AlphaBetaGamma96
AlphaBetaGamma96

Reputation: 766

How to get size of hidden files with "du"

I've been using "du -hs ~/" to get the size of my total home directory with outputs 20GB, and I've been trying to where large files that I can delete to free up some space. However, when using "du -hs ~/*" I get numerous outputted files but they don't sum to 20GB. There are a few hidden files but they aren't shown.

How can I print out the size of hidden files, and also locate the largest files/directories via command line?

Thank you!

Upvotes: 12

Views: 24714

Answers (5)

kmario23
kmario23

Reputation: 61375

Combining some of the above answers together to get a more desirable result using:

du -sh $(ls -A) | sort -h

displays size of hidden files and directories and then sorts it in an ascending order.

Upvotes: 1

Alok
Alok

Reputation: 10574

To size all the files in home directories including hidden files

du -sh $(ls -A)
du -sh .[^.]* *

To size only normal files

du -sh *

To size only hidden files

du -sh .[^.]*

Upvotes: 20

Kubito
Kubito

Reputation: 11

find ~/ -maxdepth 1 -type d -exec du -hs {} \;

Running this command will display the disk usage summary (du -hs) for each hidden directory found.

Upvotes: 1

steeven lee
steeven lee

Reputation: 1

For me, has to filter out ".":

ls . |grep -v "\.$"

Upvotes: 0

Thomas
Thomas

Reputation: 17422

The problem lies not with du but with how the shell resolves * - it does not include files that start with a period. To remedy, just mention those files explicitly:

du -hs ~/* ~/.*

In order to find the largest of those files, simply pipe the output to a sort command, with an optional tail appended:

du -hs ~/* ~/.* | sort -h | tail

Upvotes: 13

Related Questions