0

I don't know what's going on with my centos 7 machine but seems like du -h /path only shows folders, not files, and it's annoying. I want to find all the files and folders at a specific depth and sort it by size. For example (Note that even if I remove --max-depth=2 result is still the same)

[root@data-node12 ~]# du -h --max-depth=2 /root/quang/ | sort -rn 352M /root/quang/ 339M /root/quang/test_folder 

While I have many files inside /root/quang

[root@data-node12 ~]# ls -lh /root/quang/ total 14M -rwxrwxrwx 1 root root 508 May 22 10:23 deleteClipLogByDate.sh -rw-r--r-- 1 root root 68K Dec 22 14:01 extract.csv -rwxr-xrwx 1 root root 4.7K Dec 21 17:38 goi_cuoc.sh -rwxr-xrwx 1 root root 8.7K Dec 22 15:50 log_tuong_tac_kh.sh -rw-r--r-- 1 root root 96 May 22 09:02 output_goi_cuoc.log -rw-r--r-- 1 root root 96 May 22 09:30 output_log_tuong_tac_kh.log drwxr-xr-x 2 root root 4.0K May 22 10:53 test_folder -rwxrwxrwx 1 root root 773 Dec 21 17:41 test.sh -rw-r--r-- 1 root root 14M May 22 10:54 trino-cli-435-executable.jar 

also there is a file in /root/quang/testfolder

[root@data-node12 ~]# ls -lh /root/quang/test_folder/ total 339M -rw-r--r-- 1 root root 339M May 22 10:53 fastmoney_vft.sql 

Also please note that ls -lh command won't show the right disk space for folders, also can't sort, so that won't work.

How can I du -h and show all files and folders that I can sort (recursively if possible)? Is this some kind of bug?

4
  • 2
    du -a Commented May 22, 2024 at 4:24
  • 1
    If man du doesn't work for you, try info du. Commented May 22, 2024 at 6:03
  • There are several websites hosting manual pages, and the GNU documentation for coreutils, which du(1) is a part of. Commented May 22, 2024 at 11:01
  • @G-ManSays'ReinstateMonica' Thanks. Can't biievie I miss that simple option Commented May 23, 2024 at 5:13

1 Answer 1

0

If you use du with a directory, it will by default calculate and show the disk usage for that directory and its subdirectories. To also include files in the output, use du with its -a option (or --all if you are on a GNU system). The -a option to du is a POSIX standard option.

Example:

$ du skel 16 skel 
$ du -a skel 4 skel/.bashrc 4 skel/.zshrc 0 skel/.bash_profile 4 skel/.yashrc 16 skel 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.