Strip directory and suffix from filenames

      basename NAME [SUFFIX]

      basename OPTION

        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")

script to rename file extensions:

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

$ BatchRenameExt htm html

Related linux commands:

dir – Briefly list directory contents
dirname – Convert a full pathname to just a path
ls – List information about file(s)
Equivalent Windows command: Variable Substring

Te ayudó?