linux, how to

Identifying large files on your PC can help you quickly reclaim some much needed space. For desktop Linux users, hunting down large unnecessary files might be optional. But when it comes to server space, it costs money, and you have to pay for that excess space every month. Here’s how you can locate big files in Linux to quickly get rid of them.

Content

  • Use the ls Command
  • Use the find Command
  • Use the du Command
  • Find Large Unused Files
  • GUI Apps to Find the Largest Files in Linux
  • Remove the Largest Files
  • Frequently Asked Questions

Use the ls Command

Generally, the ls command is used to list all of the directories and files in the Linux terminal. However, it can do much more – for instance, classify directory contents and display file sizes.

  1. To see more information about files and directories including their permissions, you can use the -l flag.
ls -l

linux, how to

  1. To print their size along with all of the information, use the -s flag along with the previous -l flag.
ls -ls

linux, how to

  1. By default, the ls command will only list the directories. To see the files inside the directories recursively, use the -R flag.
ls -lsR

linux, how to

  1. To sort files, you can use two methods. One takes advantage of the -S flag inside the ls command, while the other employs the power of the sort command. To sort the files according to their file size in descending order, run the following command:
ls -lsRS

linux, how to

  1. To reverse the order, you can use the -r flag.
ls -lsRSr

linux, how to

  1. Alternatively, after the ls command returns, you can pipe the result into the sort command. This will sort the list as per their numerical file sizes in ascending order. You can also reverse the order by using -r flag in conjunction with the sort command.
ls -ls | sort -nr

linux, how to

  1. So far, we have analyzed and found the largest files inside our current working directory. To identify the largest file in your whole filesystem, you can add the location after the ls command.
sudo ls / -S

linux, how to

Use the find Command

The find command can be used to search any files inside a Linux filesystem. In this case, we can employ it to list files according to their file sizes. We can also filter the results by minimum file size.

  1. To find the largest files inside your current working directory, type the following:
find . -type f

linux, how to

  1. It’s possible to also add a filter with the minimum size of 100MB.
find . -type f -size +100M

linux, how to

  1. To specify a certain directory, add the relative path after the find command.
find ./test -type f -size +100M
  1. Doing so will find all the files inside the “test” directory which has a size greater than 100MB.
  2. Sometimes you need to search the entire filesystem to find the largest file. For that, just add a / after the find command.
sudo find / -xdev -type f -size +100M

Note: the -xdev flag instructs not to descend directories on other filesystems. In simple words, it won’t scan other mounted filesystems in your Linux system.

  1. To remove this behavior and to scan all the mounted drives along with your primary filesystem, just remove the -xdev command as follows:
sudo find / -type f -size +100M

Now you should be able to view the list of the largest files in your entire device along with your mounted drives.

Use the du Command

The du command is primarily designed to estimate file sizes in Linux. Here’s how to find large files with it.

  1. You can use the -a flag to list the files along with directory sizes recursively.
du -a

linux, how to

  1. The file sizes listed here appear as very long number strings, so they are very hard to estimate. To make it readable, use the -h flag in conjunction with other flags.
du -ah

linux, how to

  1. To make the file size uniform, use the blocksize operator -B along with a unit of your choice. If you want to convert the sizes in MB, use unit M as a block size.
du -aBM

linux, how to

  1. To find the largest files among them, use the sort command to sort the files in descending order.
du -aBM | sort -nr
  1. To list only the first five results, pipe the sorted list into the head command by using -n 5.
du -aBM | sort -nr | head -n 5

linux, how to

  1. So far we’ve been displaying file sizes only in our current working directory. To list the largest files of a specific directory, append the directory name after the du command. The following command will list the five largest files in your home directory.
du /home -aBM | sort -nr | head -n 5
  1. To find the largest 10 files in your entire filesystem, just add the / after the du command.
du / -aBM | sort -nr | head -n 10

Find Large Unused Files

Getting the list of unused files is very useful, as you can readily delete them to save space on your hard disk. Do this with the help of the -mtime flag and the find command discussed earlier. The following instructions will list out the top 10 files, which have not been modified for more than 30 days and have a file size of at least 100MB.

find / -xdev -mtime +30 -type f -size +100M

GUI Apps to Find the Largest Files in Linux

If you are running Linux on your desktop, make use of these GUI apps to find the largest files in your system.

Disk Usage Analyzer

One of the best GUI apps to analyze file sizes in Linux is Disk Usage Analyzer. It comes preinstalled in your Gnome desktop environment.

  1. If this application is not installed on your machine, you can easily install the disk usage analyzer application like so:
sudo apt update sudo apt install baobab

For Fedora or other red-hat-based distributions, install Disk Usage Analyzer by using the following command:

sudo dnf install baobab
  1. Open the app and select the filesystem you want to scan. Disk Usage Analyzer will list the attached filesystem in your machine.
  2. You’ll have to wait a few seconds until the scan completes.
  3. Once the process is done, you’ll be able to see the list of files and folders sorted according to their sizes (larger ones at the top, smaller towards the bottom).

linux, how to

  1. You can navigate through the folders using double clicks.

Some additional GUI apps that you can use to find large files on your Linux system include:

  • Filelight
  • Duc
  • JDiskReport
  • QDirStat

Remove the Largest Files

After finding the largest files, you need to remove them and can easily do so with the help of therm command in Linux.

  1. Copy the absolute or relative file of the file you want to delete, then append the file path after the rm command.
rm "your file path goes here"
  1. To remove any non-empty directory, use the -rf after the rm command. -r represents recursively deleting the files inside the directory, and -f implies force to delete that directory. For example, if you want to delete your “Downloads” folder along with all the files inside it, run the following command.
rm -rf ~/Downloads

Frequently Asked Questions

Why I am getting a “permission denied” error?

If you want to run a command beyond your home directory, you should have root permission. Otherwise, you will get the permission denied error. Try using sudo before the command to elevate your permission as a root user. You can successfully run any command on your system files. Try to be careful when using sudo with commands.

How do I find files larger than 1GB?

To find files larger than 1GB, use the find command with its -size flag. The command will look like this: sudo find / -xdev -type f -size +1G.

How can I view the size of a particular folder?

To see the size of a folder, use any of the tools mentioned in this article. You can also use your File Explorer to see the size of a folder. Just right-click on the folder and select the properties option. There you can easily find the listed folder size.

Image source: Unsplash All screenshots Hrishikesh Pathak

TECH NEWS RELATED

How to find Holo-Chests in Fortnite, and what they do

Screenshot by Gamepur As if Chrome Chests weren’t plentiful enough, Fortnite Chapter 3 Season 4 introduces players to an even better kind of crate known as the Holo-Chest. This type is guaranteed to hold Epic or better loot, and you can even choose which weapon you earn. Though, there ...

View more: How to find Holo-Chests in Fortnite, and what they do

Witcher, Cyberpunk Dev's Joint-CEO And Cofounder Stepping Down After Nearly 30 Years

Marcin Iwinski is stepping down as CD Projekt announces a majorly ambitious future strategy.

View more: Witcher, Cyberpunk Dev's Joint-CEO And Cofounder Stepping Down After Nearly 30 Years

Call Of Duty: Modern Warfare 2 Campaign Early Access Details

Modern Warfare 2 will offer early access to the game's campaign, and here's what you need to know.

View more: Call Of Duty: Modern Warfare 2 Campaign Early Access Details

Fortnite Bytes Quests: How To Tune The TV, Find Chromed Vehicles, And More

Grab some new alt styles for The Nothing's Gift pickaxe.

View more: Fortnite Bytes Quests: How To Tune The TV, Find Chromed Vehicles, And More

CD Projekt RED Confirms Cyberpunk 2077 Sequel, New IP, & Extensive Plans for the Witcher IP

Today, developers CD Projekt Red took to Twitter to discuss their long-term product outlook, which is set to include plenty of content for the Witcher and Cyberpunk 2077, including a lot of information on the sequels for both series. Alongside this, it was also revealed that a brand new ...

View more: CD Projekt RED Confirms Cyberpunk 2077 Sequel, New IP, & Extensive Plans for the Witcher IP

CD Projekt Joint CEO Stepping Down; Will Remain in Non-Executive Role

Today The Witcher and Cyberpunk 2077 developer CD Projekt announced that its Joint CEO Marcin Iwiński is stepping down from his executive role. The change will become operative by the end of the year, as Iwiński will submit his candidacy as chairman of the supervisory board of the company. ...

View more: CD Projekt Joint CEO Stepping Down; Will Remain in Non-Executive Role

Cooler Master’s New Chair Will Vibrate With Your Games

Cooler Master As far as gaming chairs go, most people just want something that’s comfortable for long gaming sessions, and the most avid enthusiasts might want things like RGB lights on it. This new chair by Cooler Master, though, is something special. The Cooler Master Synk X chair looks, ...

View more: Cooler Master’s New Chair Will Vibrate With Your Games

Matter Is Finally Here to Fix Your Smart Home Woes

Google For over two years, an alliance of tech companies has been working on Matter, a unified standard for connecting smart home devices that aims to fix all the complexities of current products. Now the standard is ready for prime time. The Connectivity Standards Alliance, which includes Amazon, Apple, ...

View more: Matter Is Finally Here to Fix Your Smart Home Woes

Google Drive review

Corsair K100 Air Wireless review

How to Kill a Linux Process by Port Number

Battery and camera specs of Samsung Galaxy S23 lineup leaked

Foxhole – How to use a Bayonet

The Matter 1.0 Standard Is Here to Fix Smart Homes’ Biggest Problems

Redmi Pad Review: All Hail The New King of Affordable Tablets

Tencent Reportedly Plans To Buy More Global Studios Outright

Cyberpunk 2077 Sequel, New Witcher Games, And An Original IP In Development At CD Projekt Red

Overwatch 2 Release Time: Here's When Servers Go Live

Micron is spending up to $100 billion to build a megafab in New York

Clever side-by-side iPhone game controller has no problem with bulky cases [Review]

OTHER TECH NEWS

Top Car News Car News