Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need a script that will start with the PWD and list sub-directories and the total amount of disk space consumed by all files in all directories under each sub directory.
To check size of all directories, including files, residing in pwd:
Code:
~$ find . -exec du -sk {} \;
These do not work the same. The first command shows the size of files as well as directories. The second command shows all that, plus the size of each subdirectory, and each file present in subdirectories.
However I thank you for reminding me of -exec. I guess I am still a newbie.
Code:
find . -maxdepth 1 -mindepth 1 -type d -exec du -sh {} \;
and upon further consideration, I see that this shows only directories:
Code:
du -sh */
Last edited by Beryllos; 05-17-2013 at 11:28 PM.
Reason: explained how the command outputs differ
These do not work the same. The first command shows the size of files as well as directories. The second command shows all that, plus the size of each subdirectory, and each file present in subdirectories.
Please re-read my post. First command will show sizes of all subdirectories only whereas second one will give sizes of all subdirectories as well as files.
Please re-read my post. First command will show sizes of all subdirectories only whereas second one will give sizes of all subdirectories as well as files.
Sorry, but that is not true. If there are files present in the current directory these will be shown. It also only shows one level deep.
Code:
$ ls -l
drwxr-x--- 6 druuna druuna 4096 jan 13 12:30 Fife
drwxr-x--- 8 druuna druuna 4096 mei 7 15:43 LFS
drwxr-x--- 2 druuna druuna 4096 jan 13 16:11 Log
drwxr-x--- 2 druuna druuna 69632 mei 11 10:03 Tmp
-rw-r----- 1 druuna druuna 102 mei 18 08:23 awk_script
-rw-r----- 1 druuna druuna 45 mei 18 08:20 file1
-rw-r----- 1 druuna druuna 45 mei 18 08:20 file2
-rw-r----- 1 druuna druuna 42 mei 18 08:20 file3
$ du -sk ./*
24 ./Fife
313992 ./LFS
8 ./Log
68 ./Tmp
4 ./awk_script
4 ./file1
4 ./file2
4 ./file3
To show all the subdirectories and not just one level the s switch needs to be removed, that combined with Beryllos' answer you get this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.