andieje
asked on
how do i list all of the gz files in a directory and their sizes
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
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
Are you looking in a specific subdirectory? If so, include the directory name, like this:
ls -l -h sub_dir_name/*.gz
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"
Note that you need to use 2 because the current directory is considered the first, and its subdirs are 2, etc.
if you want to list all files in a particular directory, try
ls -ltr *.gz
but that won't include gz files from subdirectories
ls -ltr *.gz
but that won't include gz files from subdirectories
To find recursively and list the size as well:
find . -name "*.gz" -ls
ASKER
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
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
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;
}'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
brilliant :)
Did you try ls -l -h *.gz