How To Find and List Large Files and Directories In Linux?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/find-and-list-large-files-and-directories-in-linux/
PINTEREST
PINTEREST
INSTAGRAM

One of the important job for System Administrators is finding and deleting large and unneeded files from Linux operating system. In this tutorial we will look how to find, sort and delete large and trash files from Linux distributions like Ubuntu, Debian, Mint, Fedora, CentOS and RHEL etc.

Large Files Directories

In Linux distributions there are some directories and paths where files generally holds a lot of disk space. These space are generally used by temporary, cache, log or personal files. Here list of these directories.

  • /tmp
  • /var
  • /var/log
  • /home

Find and Sort Large Files and Directories with du Command

There are alternative ways to find and list directories and files. We will look du command which is short for disk usage. We will combine commands sort to sort lines according to size and head to cut first specified number of lines. In this example we will list files and directories located at  /home/ismail . File and directory sizes are listed in the first columns and we sort with sort command. We select first 20 line with head command.

Find and Sort Large Files and Directories with du Command

Find and Sort Large Files and Directories with du Command

Print Only Directory Summaries

In previous example we will listed a lot of path. This may be consuming. We can list only given path and do not recursively its sub directories with -s option.

Print Only Directory Summaries

Print Only Directory Summaries

Skip Files and Directories in Different File Systems

Another useful option provided by du command is skipping other files systems. As we know in Linux it can be mounted different files systems in to sub directories. We can prevent checking files sizes in this file systems with -x like below.

LEARN MORE  How To Linux Bash For Loop In Files?

Find and Sort Large Files with find Command

find is very useful command used for different purposes. The extensible of find command provides us to list even delete big files. We print the file and sizes with the -printf option of the find command.

Find and Sort Large Files with find Command

Find and Sort Large Files with find Command

Create Alias and Command For Finding Large Files and Directories

As a daily job writing these commands again and agina will be very trivial task. We can create some alias or script from these commands. In this example we will create an alias named list_big_files alias and add it to the .bashrc of the current user.

and we can call list_big_files like below but in order to make it effective we should start new shell to load our new alias.

Create Alias and Command For Finding Large Files and Directories

Create Alias and Command For Finding Large Files and Directories

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/find-and-list-large-files-and-directories-in-linux/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)