Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to check filesystem for a given file?

Status
Not open for further replies.

badrinathn

IS-IT--Management
Nov 15, 2005
16
US
Hi,

Using a shell script I need to find the 'mounted' filesystem for a given file. Example if the files are on
/u01/oradata/data01.dbf and is mounted on /u01 filesystem, I need to find the information about the /u01 filesystem using df -k.

How can I get the mouted filesystem information given the path to the file.

 
Just to clarify - the files might be on /u02/oradata/prod1/temp01.dbf or /arch/oradata/prod1/arch01.dbf

I have the path to the file, but I just want to see where they are mounted could be /u02 or /u02/oradata.

 
I found the answer myself. Nevermind.

df -k file_name gives the mount info.
 
Maybe shortlived celebration - it didn't work. Please comment.
 
Some Unixes' df work the way you described (AIX is one).

If it doesn't work on your unix: try this script instead: (strip off filename and subsequently the last dir part of the pathname until the df command stops complaining about the thus produced pathname):

Code:
d=$1
until df $d >/dev/null 2>&1
do
 d=$(dirname $d)
done
df $d|awk 'NR==2{print $NF}'

(I think this script would work on any UNIX)



HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top