- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ls (is the result in bytes)
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2009 10:00 AM
02-26-2009 10:00 AM
i would like to know what is the size of the result after i run the command "ls -l"
Example:
$ ls -lrt prueba
-rw-rw-r-- 1 ftphr sapsys2 21 Feb 26 12:58 prueba
is "21" in bytes? if so, how can i run ls to get the value in Mb?
please let me know.
Thanks.
Dma.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2009 10:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2009 10:14 AM
02-26-2009 10:14 AM
Re: ls (is the result in bytes)
Of course.
If you want it in Mb, you will have to write a script:
ll -rt prueba | awk '
NF >= 9 {
print $1, $2, $3, $4, $5/(1024*1024), $6, $7, $8, $9, $10, $11
next
}
{
print $0
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2009 10:55 AM
02-26-2009 10:55 AM
Re: ls (is the result in bytes)
only 1 time: 1024?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2009 10:59 AM
02-26-2009 10:59 AM
Re: ls (is the result in bytes)
> and , what about Kb? how can i do that?
Yes:
# ls -l | awk '{$5=sprintf("%6.2f",$5/1024);print}'
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 01:34 PM
03-05-2009 01:34 PM
Re: ls (is the result in bytes)
when i run:
ls -l | awk '{$5=sprintf("%6.2f",$5);print}'
the result is:
how can i gent 27.00 ?
total 32 0.00
-rw-rw-r-- 1 ftphr sapsys2 20.00 Mar 5 16:33 file1
-rw-rw-r-- 1 ftphr sapsys2 7.00 Mar 5 16:33 file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 01:40 PM
03-05-2009 01:40 PM
Re: ls (is the result in bytes)
Yes, we should skip the "total" line at the head of the list:
# ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
...converts to KB...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 01:43 PM
03-05-2009 01:43 PM
Re: ls (is the result in bytes)
I have a question, if i run:
$ ls -lR | awk '{ sum += $5 } END { print sum }'
I got:
1.26335e+08
if i run:
$ ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
I got: total 155152 (KB)
is the same both cases? i mean, the result (numbers) are different .... how can i explain that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 01:52 PM
03-05-2009 01:52 PM
Re: ls (is the result in bytes)
ls -lR | awk '{ sum += $5 } END { print sum }'
example two had:
ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
the "-R" in example one caused it to list the sizes of all the files in all the subdirectories, while the second didn't have that option.
also notice that the second example got rid of the "total" line, although this should not change the results.
Basically, you appear to have run the test with different sets of data!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:00 PM
03-05-2009 02:00 PM
Re: ls (is the result in bytes)
example one totals the sizes of all the files in the list, as in:
ls -lR | awk '{ sum += $5 } END { print sum }'
5912633
example two converts / displays each file to KB and displays that in the list:
ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
total 668
-rwxr----- 1 root root 0.00 Feb 23 12:26 abc
-rw-r--r-- 1 root root 1.73 Dec 26 16:05 add.hosts
-rw-r--r-- 1 root root 1.72 Dec 26 19:50 anaconda-ks.cfg
drwxr-xr-x 2 root root 4.00 Feb 25 10:26 c2
drwx------ 3 root root 4.00 Dec 26 19:57 Desktop
-rw-r--r-- 1 root root 120.00 Dec 30 14:07 examples.tar
-rwxr-xr-x 1 root root 0.04 Feb 27 15:18 fsm
-rw-r--r-- 1 root root 0.10 Mar 2 15:54 fsm1
-rwxr-xr-x 1 root root 0.13 Mar 2 16:11 fsm1.sh
-rw-r--r-- 1 root root 0.10 Mar 2 14:45 fsm2
-rw-r--r-- 1 root root 0.03 Feb 5 15:27 fsma1
-rw-r--r-- 1 root root 0.52 Feb 5 15:25 fsmawk
-rwxr-xr-x 1 root root 0.16 Feb 19 16:27 fsm.sh
-rw-r--r-- 1 root root 46.62 Dec 26 19:50 install.log
-rw-r--r-- 1 root root 5.10 Dec 26 19:50 install.log.syslog
drwxr-xr-x 3 root root 4.00 Jan 9 10:34 sudo
-rw-r--r-- 1 root root 423.72 Dec 26 15:28 tzdata-2008i-1.el2_1.noarch.rpm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:01 PM
03-05-2009 02:01 PM
Re: ls (is the result in bytes)
So, why it is different:
$ ls -l | awk '{ sum += $5 } END { print sum }'
RESULT: 7.94204e+07
$ ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
RESULT: total 155152
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:10 PM
03-05-2009 02:10 PM
Re: ls (is the result in bytes)
You asked:
So, why it is different:
$ ls -l | awk '{ sum += $5 } END { print sum }'
RESULT: 7.94204e+07
$ ls -l | awk '/^total/ {print;next};{$5=sprintf("%6.2f",$5/1024);print}'
RESULT: total 155152
...
In the first case we summed *characters*.
In the second case we simply passed through without converion the "total" line in the list head. The UNITS of this value are 512-character BLOCKS. Hence, 155152*512 = 79437824 =~ 7.94204e+07
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:15 PM
03-05-2009 02:15 PM
Re: ls (is the result in bytes)
RESULT: total 155152
I take it in the above you calculated a total by hand ('cause it sure didn't print it).
if so, lots of small files could be an issue i suppose, but w/o seeing the directory listing *before* it gets run thru the various awks, its hard to tell
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:15 PM
03-05-2009 02:15 PM
Re: ls (is the result in bytes)
i mean, i have to get a size report of different paths , my boss needs to know how much we are using in KB.
please let me know what option is the best to get above information.
thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:25 PM
03-05-2009 02:25 PM
Re: ls (is the result in bytes)
> I mean, i have to get a size report of different paths , my boss needs to know how much we are using in KB.
The 'du' command is designed for this. You could summarize a path like this:
# du -ks /path
...and then to find the one-level deeper directory usage:
# ls -l /path | awk '/^d/ {print $NF}'|xargs du -ks
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:29 PM
03-05-2009 02:29 PM
Re: ls (is the result in bytes)
You can use "du -kx".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 02:34 PM
03-05-2009 02:34 PM
Re: ls (is the result in bytes)
now, how can i get the result in:
bytes
kbytes
mbytes ?
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 03:15 PM
03-05-2009 03:15 PM
Re: ls (is the result in bytes)
> now, how can i get the result in: bytes kbytes mbytes ?
Using 'du -k' means Kilobytes, so you need to appropriately convert by factors of 1024. You have quite enough examples to deduce how to do that :-)
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 03:21 PM
03-05-2009 03:21 PM
Re: ls (is the result in bytes)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 03:21 PM
03-05-2009 03:21 PM
Re: ls (is the result in bytes)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 03:25 PM
03-05-2009 03:25 PM
Re: ls (is the result in bytes)
$ du -m
du: illegal option -- m
usage: du [-a|-s] [-kbrx] [-t type] [name ...]
here i found:
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.cmds/doc/aixcmds2/du.htm
To summarize the disk usage of a directory tree and each of its subtrees in MB blocks, enter:
du -m /home/fran
but it did not work for me !!!
how can i get it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 03:42 PM
03-05-2009 03:42 PM
Re: ls (is the result in bytes)
Why would you look at AIX manpages for HP-UX options? To convert KB to MB, divide by 1024.
Using my suggestion of:
# ls -l /path|awk '/^d/ {print $NF}'|xargs du -ks
...which reports KB sizes, to show in MB, you could do:
# ls -l /path|awk '/^d/ {print $NF}'|xargs du -ks|awk '{printf "%6.2f %s\n",$1/1024,$2}'
For a simple 'du' [ which includes both files and directory sizes ]:
# du -k /path|awk '{printf "%6.2f %s\n",$1/1024,$2}'
...should you want the output sorted in desceding size order pipe to a sort like:
# du -k /path|awk '{printf "%6.2f %s\n",$1/1024,$2}'|sort -knr1,1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 04:58 PM
03-05-2009 04:58 PM
Re: ls (is the result in bytes)
Really, it was very easy but i am a little tired, i have 2 nights without sleeping ... thanks a lot for your great support ... (i am not very familiar with this comands and concepts related to the size that ls command shows, i know it is a basic command but i need to be sure what exactly means ..) THANKS A LOT, have a nice evening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2009 05:15 PM
03-05-2009 05:15 PM
Re: ls (is the result in bytes)
[...]
-l
(ell) List in long format, giving mode,
number of links, owner, group, size in
bytes, and [...]
> [...] i need to be sure [...]
Read the documentation? Is that so
difficult?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2009 08:48 AM
03-06-2009 08:48 AM
Re: ls (is the result in bytes)
one question:
i have these files:
REPORT IN KS:
$ ls -l |awk '/^d/ {print $NF}'|xargs du -ks
101637 .
REPORT IN MB:
$ ls -l |awk '/^d/ {print $NF}'|xargs du -ks|awk '{printf "%6.2f %s\n",$1/1024,$2}'
99.25 .
if i see the first one, i could think:
"101637 kb = 101.637 MB"
but if see the other instrucction i see: 99.25
so 101.637 is not equal to 99.25
what is the correct value to know in MB?
Thanks in advance.