Solved

how do i list all of the gz files in a directory and their sizes

Posted on 2014-01-27
8
124 Views
Last Modified: 2014-02-01
Hi

I think the question title says it all. I have tried ls -l -h  **/*.gz to just list the gz files in a directory but i get the error message 'cannot access **/*.gz no such file or directory

Thanks a lot
0
Comment
Question by:andieje
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39813233
What directory are the files in?
Did you try  ls -l -h  *.gz
0
 
LVL 14

Expert Comment

by:ThomasMcA2
ID: 39813322
Are you looking in a specific subdirectory? If so, include the directory name, like this:
ls -l -h  sub_dir_name/*.gz

Open in new window

Or do you want to find all *.gz that are 1 subdirectory below the current directory? If so, you need to use find, and tell it to only look 1 level deep, like this:
find -maxdepth 2 -name "*.gz"

Open in new window

Note that you need to use 2 because the current directory is considered the first, and its subdirs are 2, etc.
0
 
LVL 35

Expert Comment

by:YZlat
ID: 39813380
if you want to list all files in a particular directory, try

ls -ltr *.gz

but that won't include gz files from subdirectories
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:Surrano
ID: 39814350
To find recursively and list the size as well:
find . -name "*.gz" -ls

Open in new window

0
 

Author Comment

by:andieje
ID: 39814913
Hi
Thanks for the replies. I can see that as ever my question isn't worded as well as it could have been. I just want the file name and the size in human readable form (like MB or something). However in order to do this I seem to have to add the -l option which give me a load of other gunk. Or do i need to pipe it into cut to get teh columns I want. I dont use linux very mich. Sorry
0
 
LVL 8

Expert Comment

by:Surrano
ID: 39814930
Assuming there are no whitespaces in your file names the following will work.

find . -name "*.gz" -ls | awk '{size=$7; name=$11; suf=""; format="8d  ";
if (size>1024) { size /= 1024.0; suf="k"; format="10.1f" }
if (size>1024) { size /= 1024.0; suf="m" }
if (size>1024) { size /= 1024.0; suf="g" }
printf "%"format"%-2s %s\n", size, suf, name; 
}'

Open in new window

0
 
LVL 8

Accepted Solution

by:
Surrano earned 500 total points
ID: 39814942
or utilising the "-h" flag of "ls" command (which won't align the numbers decimally):

 find . -name "*.gz" | xargs ls -lh | awk '{ printf "%10s %s\n", $5,$9}'

Open in new window

0
 

Author Closing Comment

by:andieje
ID: 39826871
brilliant :)
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question