Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to list some files in a directory using the ls command, but I need to also to hide the file sizes. How can I do that with the ls command?

share|improve this question
3  
ls command in it's own does not show file size at all. Please be more specific and explain what you want to achieve. –  val0x00ff Nov 8 '13 at 19:53

1 Answer 1

You could mask it out using awk:

$ ls -l | awk '{print $1, $2, $3, $4, $6, $7, $8, $9}'

Example

$ ls -l|awk '{print $1, $2, $3, $4, $6, $7, $8, $9}' | head -5
total 172136      
drwxrwxr-x 2 saml saml Jan 16 2013 desktop-integration
-rw-r--r-- 1 saml saml Jan 16 2013 libobasis3.6-base-3.6.5.2-2.x86_64.rpm
-rw-r--r-- 1 saml saml Jan 16 2013 libobasis3.6-binfilter-3.6.5.2-2.x86_64.rpm
-rw-r--r-- 1 saml saml Jan 16 2013 libobasis3.6-calc-3.6.5.2-2.x86_64.rpm

Details

The awk command automatically will parse the data into columns, this command is telling awk to print all the columns except for the 5th, which is the column with the size information in it.

NOTE: I wouldn't recommend doing it this way however, I show you the approach only to show you the general concept of how you can parse the output from one command in Unix by piping to another tool such as awk. The next method is the preferred way of solving your particular example!

More concise awk example

Thanks to @val0x00ff in the comments there is an even more efficient method to instruct awk to print all the columns except the 5th.

Example

$ ls -l|awk '{$5=""; print}' | head -5
total 172136   
drwxrwxr-x 2 saml saml  Jan 16 2013 desktop-integration
-rw-r--r-- 1 saml saml  Jan 16 2013 libobasis3.6-base-3.6.5.2-2.x86_64.rpm
-rw-r--r-- 1 saml saml  Jan 16 2013 libobasis3.6-binfilter-3.6.5.2-2.x86_64.rpm
-rw-r--r-- 1 saml saml  Jan 16 2013 libobasis3.6-calc-3.6.5.2-2.x86_64.rpm

Details

In this method we're instructing awk to blank out the 5th column by setting it to an empty string, "". Everything else is left as is. We then tell awk to print the resulting string of what's left.

share|improve this answer
1  
I think a more efficient way would be ls -l | awk '{ $5=""; print}'. I did not post an answer since I have no clue what the OP wants. –  val0x00ff Nov 8 '13 at 20:06
1  
@val0x00ff - post that as an answer, I believe that is what he wants. I can think of no other interpretation of his question beyond that. –  slm Nov 8 '13 at 20:07
    
I'm just saying maybe it would be more efficient. You could just edit your answer. –  val0x00ff Nov 8 '13 at 20:08
1  
I don't mind at all. I appreciate your contribution and you help a lot of folks including me with your nice and well explained answers. Cheers! –  val0x00ff Nov 8 '13 at 20:10
1  
@val0x00ff - thank you for your guidance, and kind words! –  slm Nov 8 '13 at 20:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.