Unix

Basename Command in Unix /Linux

Basename is a standard UNIX computer program. When basename is given a path name, it will delete any prefix up to the last slash ('/') character and return the result. Simply we can say that basename strips directory information, suffixes and prefixes from file names.

The syntax for the basename command is  
The options are
  • -a: support multiple arguments and treat each as a NAME.
  • -s: remove a trailing suffix SUFFIX, such as a file extension.
  • -z: separate output with NUL rather than a newline.
  • -help: display help information and exit.
  • -version: output version information and exit.
Examples of Basename Command 
  • basename /home/yyy/commnd
         It will remove prefix. /home/yyy/ can be removed. Prints only 'command'
  • basename  commandline line
          It will remove suffix. Remove 'line' from 'commndline'. Prints 'command'
  • basename /home/yyy/commandline line
         It will remove both suffix and prefix. Prints only 'command'

Powered by Blogger.