Linux Running Out of Space?

In this article, I will show how to check which directories and files are the largest. We will use 3 linux commands…..du , ls and sort.

First lets do an example from your /home directory. Lets find out which directory is biggest

# du -Sm | sort -n

after executing this command you will see directory listing with sizes like:

2 ./oshrt/src/cs
3 ./oshrt/sbin
4 ./ekg/src
5 ./oshrt/src/oshrtd
10 .

In the first column you will see the directory size in megabytes, second column is directory name. The last entry only has a “.”. This represents the total size of all the files in all the directories where you executed the command. As you see the biggest dir is ./oshrt/src/oshrtd, lets find out which files in this directory are biggest.

# ls -lR ./oshrt/src/oshrtd/ | sort +4n

Output shouldl look something like this:

-rw-r–r– 1 user user 78068 Jul 24 15:12 server.o
-rw-r–r– 1 user user 85520 Jan 10 2002 command.c.orig
-rw-r–r– 1 user user 86122 Jan 21 2002 command.c
-rw-r–r– 1 user user 111344 Jul 24 15:12 connection.o
-rw-r–r– 1 user user 138708 Jul 24 15:12 oshrt.o
-rw-r–r– 1 user user 143531 Jan 21 2002 oshrt.c

The sort command sorts output from small to big file sizes, so the biggest file will be at the end of listing. In this case, the biggest file is oshrt.c. If you’re having space problems, you may want to try these commands on /var/log, because it is the most space eating directory :)

Have something to tell us about this article?
Let us know

or Comment Below

LOGIN to Comment
LOGIN to Comment

Gaming Trailers

More Like This
Gotham Knights | Official Red Hood Character Trailer
Latest Trailers
Rabbids: Party of Legends | Launch Trailer

Got a tip?

Let us know