How to display file name and its size ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to display file name and its size ?
# 1  
Old 04-08-2011
How to display file name and its size ?

Suppose there are 3 files inside a directory, then i need to use display command which will display, the file name and its size. Is it possible?

The output should llook like this only

file1 1248
file2 3024
file3 3056
# 2  
Old 04-08-2011
Quote:
ls -l | awk '{print $9, $5}'
# 3  
Old 04-08-2011
For a more readable output you can use.
Code:
du -hs * |awk '{print $2 "\t" $1}'

Code:
alioune@baccus ~/bashtuto/uip $ du -hs * |awk '{print $2 "\t" $1}'
access.log.0    450M
access.log.1    99M
access.log.4    486M
access.log.5    438M
access.log.6    442M
alioune@baccus ~/bashtuto/uip $

# 4  
Old 04-08-2011
Quote:
Originally Posted by flash80
For a more readable output you can use.
Code:
du -hs * |awk '{print $2 "\t" $1}'

Except this reports disk used, not file size.

You could just use ls -lh on systems that support it.
# 5  
Old 04-08-2011
Code:
stat -c %n" "%s  files

# 6  
Old 04-08-2011
Quote:
Originally Posted by Corona688
Except this reports disk used, not file size.

You could just use ls -lh on systems that support it.
I am getting the same output. What is the diffrence between file size and disk usage?
Code:
alioune@baccus ~/bashtuto/uip $ ls -lh | awk '{print $9, $5}'
 
access.log.0 450M
access.log.1 99M
access.log.4 486M
access.log.5 438M
access.log.6 442M
alioune@baccus ~/bashtuto/uip $

Thx
# 7  
Old 04-12-2011
Quote:
Originally Posted by flash80
I am getting the same output. What is the diffrence between file size and disk usage?
Disk used is literally disk used, by the cluster or cluster-equivalent. Files smaller than the minimum cluster size may still occupy the full cluster. Observe an empty file taking up four kilobytes of space:
Code:
$ touch wtf
$ ls -l wtf
-rw-r--r-- 1 monttyle monttyle 0 Apr 12 08:28 wtf
$ du -h wtf
4.0K	wtf
$

This may vary depending on your system and filesystem, but that's the point -- it varies, it's not an exact measure of the file.

An even weirder case is sparse files, which have empty "holes" in them that take no disk space. Here's a disk image I made with ntfsclone:
Code:
$ ls -lh
total 62G #<---- Huh??
-rw------- 1 tyler cdrom 233G Jan 31 14:28 01-part.img
drwxr-sr-x 2 tyler cdrom    6 Feb  1 15:57 mnt
$ du -h 01-part.img
62G	01-part.img #<--- That's why!  Sparse file might be much smaller than it looks
$

Using du on a sparse file will give you a very wrong impression about file size!

Last edited by Corona688; 04-12-2011 at 11:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX commands to display the biggest file by size in a directory

Hello guys, Please i need to know the biggest files in my directory let's say$ >du -h | egrep 'M|G|G' 195M ./TMP 3.6M ./TP_DEC2012 146G . But here the result it's giving me the biggest directory in the path. Actually i want to know the biggest file in 146G . Can anyone... (6 Replies)
Discussion started by: gillesi
6 Replies

2. UNIX for Dummies Questions & Answers

How to display file whose size is between 100 to 200 kb ???

help me (1 Reply)
Discussion started by: sonu pandey
1 Replies

3. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

4. Shell Programming and Scripting

Display the Filename and Size of a File

Hello, all! Working in a Bourne shell. What command would list the filename and size of a file if the size of the file had to be bigger than $a and smaller than $b? Output (if $a is 10 bytes and $b is 50 bytes):test1.txt 15 test2.txt 30 test3.txt 50 Thanks, Ann :p (3 Replies)
Discussion started by: LowlyIntern
3 Replies

5. UNIX for Dummies Questions & Answers

du -k . display size wise

Hi, I want to display all the directories with ascending order in size. For example, $ du -k . 1111111 ./dir1 222222222 ./dir2 333333333 ./dir3 444444444 ./dir4 How do i get the above desired result with du -k . command? Thanks (1 Reply)
Discussion started by: welldone
1 Replies

6. UNIX for Dummies Questions & Answers

Display directory size

Hi all, Is there any built in function that can display the content of a directory showing the size of directories? I want to see the content of a directory without recursion. I don't want to see the content of all subdirectories. I want to see the contained files with their size and the... (6 Replies)
Discussion started by: chebarbudo
6 Replies

7. AIX

Increasing screen display size

Hi, How can i increase the size of my display on AIX 5.3.What i mean is e.g if i do and ps -ef i would get some like: /data/app/oracle/product/10.2 /usr/bin/ksh /usr/local/bin/s i want it to show the whole thing on the screen without cutting it,because there is still space on the screen... (0 Replies)
Discussion started by: sellafrica1
0 Replies

8. Shell Programming and Scripting

display filesystem size that cross 75% as used

Hi Genius, I would like to display filesystem size that cross 75% as used using df -k. I would thank in advance for your answer. Thanks and Regards, HAA (2 Replies)
Discussion started by: HAA
2 Replies

9. UNIX for Dummies Questions & Answers

Display size

Hi Friends, I'm a Oracle Dba first time working in Solaris, i have worked on linux (redhat). I want to see the size of the particular directory e.g oracle and also the size of the database files. Thank you (1 Reply)
Discussion started by: shaan_dmp
1 Replies

10. UNIX for Dummies Questions & Answers

Display Directory Size - DF?

How can I display the size of a directory and contents witin a directory df only gives me the mounts (3 Replies)
Discussion started by: t4st33@mac.com
3 Replies
Login or Register to Ask a Question