Extracting File Name

How can you extract just the Filename from the Fully Qualified Path and Filename.Basename?

Questions by sgodkhindi

Showing Answers 1 - 5 of 5 Answers

AnsarP

  • Apr 1st, 2008
 

basename $filename will extract filename from a path. if you wish to extract the complete path use the commane dirname $filename.

  Was this answer useful?  Yes

Prasad2008

  • Jun 2nd, 2008
 

dirname will not give the full path of the file. It will do the opposite (but in case of directories) . If a full path is given , then it will extract the directory name from it.

  Was this answer useful?  Yes

jincee

  • Aug 10th, 2009
 

file1=`basename $0`
echo "$file1"

(or)

file1=`basename /home/user1/Jincy/base.ksh`
echo $file1
 
The above commands will give the outpuy as base.ksh

 if you just need the base of the file alone then try the below.
file1=`basename /home/user1/Jincy/base.ksh | cut -d "." -f1`

this will give you the output : base

Thanks,
Jincy


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions