Strip directory and suffix from filenames

Syntax :

basename NAME [SUFFIX]

basename OPTION

Key : 

    Display help

    Output version information and exit

basename will print NAME with any leading directory components removed. If specified, it will also remove a trailing SUFFIX (typically a file extention).


Get the name of the home folder:

$ basename ~

Extract the file name from the variable pathnamevar and store in the variable result using parameter expansion $( )

$ result=$(basename "$pathnamevar")

A script to rename file extensions:

for file in *.$1; do
mv $file `basename $file $1`.$2
$ BatchRenameExt htm html

Loading ...

Related Results :

  1. Installing PHP in Linux
  2. Linux Basics
  3. SCP and SSH Remote Linux
  4. Create your own commands in linux
  5. basename
  6. bind bash
Note :
  • Related Posts are generally User Blog posts.
  • or Other tutorials from other networks of
  • Any registered user can create related posts based on search term tags.

About the Author