
The script will sort all the files and folders from largest to smallest to check the disk space use in Linux. Then, we pipe the result to the sort command together with the -rn option.
Sorting Files By Sizeįirst, we gather files and folders on the Desktop in a readable format using the du command. After that, you can proceed with these combinations. Just remember to start with df command to see which file system needs a cleanup the most.
#Linux find file size in folder free
By doing this, you will get a better idea of which files you can delete to free up disk space. You can get more information done by combining df and du command with other arguments.
df –help - it displays a list of available options and what they can be used for.Ĭombining Commands and Cleaning Disk Space. du -h - time /home/user/Desktop - this informs the last modification date of the displayed folders and files. du -m /home/user/Desktop - the -m option provides us with folder and file sizes in Megabytes (we can use -k to see the information in Kilobytes). du -sh /home/user/Desktop - the -s option will give us the total size of a specified folder (Desktop in this case). du -h /home/user/Desktop - just like with df, the option -h displays information in a human-readable format. du /home/user/Desktop - this command line allows users to see into the disk usage of their Desktop folders and files (subdirectories are included as well). Let’s take a look at real-world use of the du command with the Desktop directory: With the du command, you need to specify which folder or file you want to check. It will show you details about the disk usage of files and directories on a Linux computer or server. df - help - it lists down other useful options that you can use, complete with their descriptions.Ĭheck Disk Usage in Linux Using the du CommandĪnother important command is du, short for Disk Usage. df /home - it allows you to view information about a specific file system in a readable format (in this case /home file system). df -T - this option will show the file system type (a new column will appear). df -k - to display file system usage in KB. df -m - this command line is used to display information of file system usage in MB. df -h - it will display the result in a human-readable format. Mounted On - tells us the mount point of a particular file system.īy adding a certain option to the df command, you can check the disk space in Linux more precisely. Use% - displays the percentage of disk space that is used. Available - shows how much space is left in the file system. Used - shows how much disk space is used in the particular file system. Size - gives us the total size of the specific file system. FileSystem - provides the name of the file system. You can also change the argument -max-depth=1 to show the size of subfolders as well. This tells me that I have 118 MB in folder1, 292 KB in folder2, 26 MB in folder named stuff, and 155 MB in total in the current folder. It shows total folder size of all folders in the current directory. This begged the question - what took up the most space? To find out, I went to the root directory (/), and ran this command: du -h -max-depth=1 For example, one of my production servers recently started glitching. What if, instead, you need to see the total size of folders?. rwxr-xr-x 1 root root 874 Dec 18 04:55 totallynotavirus.py Folders only rwxr-xr-x 1 root root 222 Dec 18 04:59 program2.py rwxr-xr-x 1 root root 496 Dec 21 07:13 program.py rwxr-xr-x 1 root root 15K Dec 18 04:55 howtodeleteavirus.txt 1 root root 1.4K Oct 12 06:28 configfile.cfg ls -lh -group-directories-first Example output:ĭrwxr-xr-x 5 root root 4.0K Nov 30 02:29 folder1ĭrwxr-xr-x 18 1000 1000 4.0K Dec 18 03:46 folder2 However, you can add -group-directories-first to show folders listed first (like the default on Windows). Unfortunately, it also lists folders in alphabetical order along with the rest of the files, so you might not be able to tell straight away if something is a file or a folder. If you want to list all files in a directory, along with their sizes, you can use this command: ls -lh There are several ways to get the required information. List only folders and show their total size in current directory: du -h -max-depth=1 Solution List all files (with size), and folders in current directory: ls -lh Find out disk size of files and folders in Linux.