Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-27
8
Medium Priority
?
126 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
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 …
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…

704 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