GeekInterview.com
Home
Tech Articles
Code Samples
Learn
Freelance Projects
Online Testing
Geek Talk
Job Postings
Knowledge Base
Geek Blogs
Question Bank
Interview Questions
Certification
Placement Papers
Tech FAQ
Career Advice
Engineering
Ask Question
I am new,
Sign me up!
User Name
Remember Me?
Password
Interview Questions
Certification
Placement Papers
Tech FAQ
Career Advice
Engineering
Ask Question
GeekInterview.com
>
Interview Questions
>
Operating System
>
Unix Commands
Go To First
|
Previous Question
|
Next Question
Unix Commands
| Question 67 of 73
Print
Extracting File Name
How can you extract just the Filename from the Fully Qualified Path and Filename.Basename?
Total Answers and Comments:
5
Last Update: August 10, 2009 Asked by:
sgodkhindi
Sponsored Links
Best Rated Answer
—
No best answer available. Please pick the good answer available or
submit
your answer.
April 01, 2008 21:04:57
#1
AnsarP
Member Since: April 2008 Contribution: 1
RE: Extracting File Name
basename $filename will extract filename from a path. if you wish to extract the complete path use the commane dirname $filename.
Is this answer useful?
Yes
|
No
June 02, 2008 04:22:47
#2
Prasad2008
Member Since: June 2008 Contribution: 8
RE: Extracting File Name
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.
Is this answer useful?
Yes
|
No
January 15, 2009 03:02:05
#3
arunkumj
Member Since: January 2009 Contribution: 2
RE: Extracting File Name
You can use basename
basename /ms/user/a/arunkumj/Arun/file.txt
file.txt as output
Is this answer useful?
Yes
|
No
January 15, 2009 03:04:49
#4
arunkumj
Member Since: January 2009 Contribution: 2
RE: Extracting File Name
cat will give the full content of a file in one go.
more will give the content of the file in page by page
Is this answer useful?
Yes
|
No
August 10, 2009 03:16:56
#5
jincee
Member Since: May 2009 Contribution: 1
RE: Extracting File Name
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
Is this answer useful?
Yes
|
No
Go To Top
Sponsored Links
Related Categories
—
Shell Scripting Interview Questions
Solaris Admin Interview Questions
UNIX Interview Questions
Unix Interview Questions
Unix Programming Interview Questions
Operating System Interview Questions
Sponsored Links
Featured Free Offers
Request Your Copy
Request Your Copy
Request Your Copy
About Us
-
Privacy Policy
-
Terms and Conditions
-
Contact
-
Ask Question
-
Propose Category
-
Site Updates
Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved