interactivevova.blogg.se

Linux find file size in folder
Linux find file size in folder









  1. Linux find file size in folder how to#
  2. Linux find file size in folder free#

Finding the biggest files and folders is no big deal. The above command will display the largest file from /home/tecmint/Downloads directory. # find /home/tecmint/Downloads/ -type f -printf "%s %p\n" | sort -rn | head -n 5 If you want to display the biggest file sizes only, then run the following command: # find -type f -exec du -Sh + | sort -rh | head -n 5

  • -h : Compare human readable numbers (e.g., 2K, 1G).
  • sort command : sort lines of text files.
  • -s : Display only a total for each argument.
  • -S : Do not include the size of subdirectories.
  • -h : Print sizes in human-readable format (e.g., 10MB).
  • To display the largest folders/files including the sub-directories, run: # du -Sh | sort -rh | head -5įind out the meaning of each option using in above command:

    Linux find file size in folder free#

    If you feel that some directories are not important, you can simply delete a few sub-directories or delete the entire folder to free up some space. The above command will show the top directories, which are eating up more disk space. i.e you might want to display the largest files in KB, MB, or GB. Some of you would like to display the above result in human-readable format. (In our case, We displayed the first 5 lines). -r : Reverse the result of comparisons.-n : Compare according to string numerical value.sort command : Sort lines of text files.Let us break down the command and see what says each parameter. If you want to display the biggest directories in the current working directory, run: # du -a | sort -n -r | head -n 5 The above command displays the biggest 5 directories of my /home partition. Run the following command to find out top biggest directories under /home partition.

    Linux find file size in folder how to#

    How to Find Biggest Files and Directories in Linux Master the ‘Find’ Command with these 35 Practical Examples.Learn 10 Useful ‘du’ (Disk Usage) Commands in Linux.If you want to learn more about these two commands, then head over to the following articles. This brief tutorial describes how to find the largest files and folders in the Linux file system using du (disk usage) and find command. It is very necessary to find unnecessary junk and free up from your hard disk. Just switch 1G to 2G or 500M and so on.As a Linux administrator, you must periodically check which files and folders are consuming more disk space. Those are some of the ways you find directories larger than 1GB, or any other size you desire for that matter. You can also sort the first command like this too, in which case you’re combining the three commands into one: # du -h -max-depth=1 / | grep 'G\>' | sort -hr If you want it to display all directories, not just first level, just leave out the -d 1 option.įinally, as a bonus, you can sort the results from largest to smallest by piping in the sort command: # du -h -d 1 -t 1G / | sort -hr It will display first level directories larger than 1GB within the root / path, just like the first command. You can use the built in -t or –threshold option of the du command like this: # du -h -d 1 -t 1G / This single command is all you need for this task, but there’s an even shorter one that works well too. Here’s another example of this command, but with –max-depth=1 being shortened to -d 1, which works the same, and checking the /var directory instead of the root / directory. So the grep ‘G>’ searches through the du output and displays only the files that are larger than 1GB. The | sign is the pipe sign that allows combining the first command with the next command, in this case grep, which is used for searching through text output for the specified strings, which can be specified through regular expressions. If we were to specify 2 it would go a level further and also look into directories like /home/user, /usr/bin, /var/log, etc. The –max-depth=1 option makes it display the sizes of only the directories immediately within the specified path, in this case the root path /, which in Linux includes directories like /home, /usr, /bin, /var, and so on. The -h option displays the sizes in a more human readable format, in gigabytes rather than kilobytes. So to find directories that are larger than 1GB you can run this command: du -h -max-depth=1 / | grep 'G\>' The du command can be used with options that allow you to customize the results you get.Ĭommands can also be combined with each other so the second command filters the results output by the first command. Finding out sizes of files and directories in Linux is done using the du command, which estimates their disk space usage.











    Linux find file size in folder