I have a variable which has the directory path, along with the file name. I want to extract the filename alone from the Unix directory path and store it in a variable.
Use the basename command to extract the filename from the path:
[/tmp]$ export fspec=/exp/home1/abc.txt [/tmp]$ fname=`basename $fspec` [/tmp]$ echo $fname abc.txt