LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-09-2008, 02:11 PM   #1
rakesh.tandur
LQ Newbie
 
Registered: Aug 2007
Posts: 9

Rep: Reputation: 0
getting the path of the file


Hello,

What is the command to get the folder path of the file.

If i use the below command, it list the folder path with the filename, but we need only the folder path not the file name in it.

find . -name 'FileName'

Any suggestions are appreciated. Thanks in advance.

Regards
-Rakesh.
 
Old 05-09-2008, 02:28 PM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Try that:
Code:
dirname $(find . -name 'FileName')
 
Old 05-09-2008, 02:37 PM   #3
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
If that doesn't work try:
Code:
dirname `find . -name 'FileName'`
HTH

Forrest
 
Old 05-09-2008, 02:47 PM   #4
rakesh.tandur
LQ Newbie
 
Registered: Aug 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Forest,

They are not working.
saying extra operand `path of the file ` error
 
Old 05-09-2008, 06:01 PM   #5
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 360

Rep: Reputation: 170Reputation: 170
If you have spaces in the path try:
Code:
dirname "$(find . -name 'FileName')"
(This fails if 'find' returns more than one file.)
 
Old 05-09-2008, 06:58 PM   #6
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Or, with GNU find,
Code:
find . -name 'FileName' -printf '%h\n'
 
Old 05-10-2008, 01:37 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Or, with any find,

Code:
find . -name 'FileName' -exec dirname {} \;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 11:47 AM
getting the path of the file rakesh.tandur Programming 1 05-09-2008 02:28 PM
full path of a file ttilt Linux - General 1 11-08-2005 06:02 PM
Getting file path from FILE pointer in C barisdemiray Programming 3 10-22-2004 12:58 AM
PATH variable file pongsu Linux - General 2 09-25-2003 04:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration