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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AIX 5.3 - How to get the size of a soft-linked file 2

Status
Not open for further replies.

DubiousAlliance

Technical User
Oct 15, 2009
8
0
0
US
Hello all!

Trying to use "ls" or "find" to get the size of the source file in a soft link.

ie.

root@MYSRV# pwd
/BACKUP
root@MYSRV# ls -al FILE*
-rw-r--r-- 1 root system 24277 Nov 02 15:26 FILE2
root@MYSRV#

root@MYSRV# pwd
/backup/prev1
root@MYSRV# ln -s /BACKUP/FILE2 ./FILE1
root@MYSRV# ls -al
total 0
drwxrwx--- 2 root system 256 Nov 02 15:31 .
drwxrwx--- 4 root system 256 Oct 21 20:36 ..
lrwxrwxrwx 1 root system 24 Nov 02 15:31 FILE1 -> /BACKUP/FILE2

How do I get the actual size of FILE2 (24277) as opposed to the link size of (24)?

I've tried something like:

find . -follow -exec ls -al {} \;

but that doesn't seem to actually follow the link, ie:

root@MYSRV# find . -follow -exec ls -al {} \;
total 0

lrwxrwxrwx 1 root system 24 Nov 02 15:31 FILE1 -> /BACKUP/FILE2
lrwxrwxrwx 1 root system 24 Nov 02 15:31 ./FILE1 -> /BACKUP/FILE2

Thanks in advance!




 
I 'd write a (recursive) function that does an ls -ld on its argument, if output line start with lrwxrwxrwx, call the function again with the last word of the output line, if not, print out the 5th field

Recursive, because a symlink may point to another symlink...

in ksh: (untested, written here on the spot, no error checking whatsoever...)
Code:
filesize()
{
 lsout=$(ls -ld $1)
 case "${lsout}" in
  lrwxrwxrwx*)
   filesize ${lsout##* }
   ;;
  *)
   echo ${lsout}|awk '{print $5}'
   ;;
 esac
}


HTH,

p5wizard
 
Hi
the command ls with the argument L (upper L) folow the link and the size of the original file is written

Best regards
 
That I didn't know... have a star!


HTH,

p5wizard
 
Biblio93,

Thanks for your response!

Not sure if this is a shell difference or not. I'm using stock AIX 5.3 ksh.

When I try "ls -L" I only get back the name of the file (without the link)

ie.

root@MYSRV# ls -al /BACKUP/FILE2
-rw-r--r-- 1 root system 40111 Nov 04 11:42 /BACKUP/FILE2


root@MYSRV# ls -al /backup/FILE1
lrwxrwxrwx 1 root system 24 Nov 04 11:43 /backup/FILE1 -> /BACKUP/FILE2

If I do the "ls -L" command, I get:
root@MYSRV# ls -L FILE1
FILE1

Am I doing something wrong, or are we running different shells?

Thanks & regards




 
[tt]ls -l -L FILE1[/tt]

-L (uppercase L) changes the output of -l (lowercase l)
-L on its own doesn't do much...


HTH,

p5wizard
 
p5wizard,

Thanks for the clarification. The man page for "ls" and googling around a bit didn't look promising either for "ls -L" ;^)

This worked, thank you!

Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top