We’ve all got to that point on a given system where we start to run out of storage space. Do we buy more storage, perhaps one of the best SSDs, or do we search and find the largest files quickly? In this how to we will look at a few simple approaches to help us maintain and manage our filesystems.
All the commands in this article will work on most Linux machines. We’ve used a Ubuntu 20.04 install but you could run this how-to on a Raspberry Pi. All of the how-to is performed via the Terminal. If you’re not already at the command line, you can open a terminal window on most Linux machines by pressing ctrl, alt and t.
Listing Files In Size Order Using the ls Command in Linux
The ls command is used to list the contents of a directory in Linux. By adding the -lS argument we can order the returned results according to the file size. We have copied a collection of files into a test directory to show this command but it can be run in any directory you choose.
Identifying Files Larger Than a Specified Size in Linux
We can use the find command in combination with the -size argument specifying a size threshold where any file larger than specified will be returned.
1. Use find to search for any file larger than 100MB in the current directory. We are working inside our test directory and the “.” indicates to search the current directory. The -type f argument specifies returning files as results. Finally the +100M argument specifies that the command will only return files larger than 100MB in size. We only have one file in our test folder Baby_Yoda.obj that is larger than 100MB.
find . -type f -size +100M
2. Use the same command, but this time specify a path to search. We can run the same command as in the previous section but replace the “.” with a specified path. This means we can search the test directory from the home directory.
cd
find ./test -type f -size +100M
Searching the Whole Linux Filesystem For Large Files
It’s sometimes useful to search the whole Linux filesystem for large files. We may have some files hidden away in our home directory that need removing. To search the entire filesystem, we will need to use the command with sudo. We might also want to either limit the search to the current filesystem which can be achieved via the -xdev argument, for example when we suspect the files we seek are in our current main filesystem or we can choose not to add the -xdev argument which will then include results from other mounted filesystems, for example an attached USB drive.
1. Open a terminal.
2. Search the current filesystem for files larger than 100MB. As we are invoking root privileges using sudo we will need to input our password. Note that we are using / to set the command to search the entire filesystem from the root of the filesystem.
sudo find / -xdev -type f -size +100M
3. Search all filesystems for files larger than 100MB. For this example connect a USB drive with a collection of files on it including some that are over 100MB in size. You should be able to scroll through the returned results and see that the larger files on the pen drive have been included in the results.
sudo find / -type f -size +100M
Finding the 10 Largest Linux Files on Your Drive
What are the top ten files or directories on our machine? How large are they and where are they located? Using a little Linux command line magic we can target these files with only one line of commands.
1. Open a terminal.
2. Use the du command to search all files and then use two pipes to format the returned data.
du -aBM will search all files and directories, returning their sizes in megabytes.
/ is the root directory, the starting point for the search.
2>/dev/null will send any errors to /dev/null ensuring that no errors are printed to the screen.
| sort -nr is a pipe that sends the output of du command to be the input of sort which is then listed in reverse order.
| head -n 10 will list the top ten files/directories returned from the search.
sudo du -aBm / 2>/dev/null | sort -nr | head -n 10
3. Press Enter to run the command. It will take a little time to run as it needs to check every directory of the filesystem. Once complete it will return the top ten largest files / directories, their sizes and locations.
With this collection of commands, you have several ways to identify and locate large files in Linux. It’s extremely useful to be able to do this when you need to quickly select big files for deletion to free up your precious system resources. As always, take care when poking around your filesystem to ensure you aren’t deleting something critical!
levaquin 500mg tablet levaquin 500mg uk
purchase ampicillin online cheap buy ampicillin generic oral erythromycin 500mg
sildenafil 50mg for sale nolvadex 10mg for sale buy methocarbamol pill
sildenafil over the counter sildalis tablet brand estrace 1mg
lamictal drug prazosin for sale cheap tretinoin cream
cost tadalafil 20mg voltaren 100mg for sale voltaren 50mg generic
order generic isotretinoin 20mg order amoxil generic zithromax 500mg canada
indomethacin 75mg brand buy generic suprax purchase amoxicillin for sale
tadalafil liquid Viagra 100 mg female viagra pill
order generic arimidex 1mg Approved viagra sildenafil pill
deltasone medication order deltasone 10mg pills buy sildenafil for sale
tadalafil 10mg kaufen ohne rezept original cialis 20mg rezeptfrei sicher kaufen sildenafil 100mg kaufen ohne rezept
accutane 10mg price order isotretinoin 20mg pills stromectol medication
provigil 200mg tablet Cialis cost generic diamox
doxycycline sale levitra 10mg uk oral lasix 40mg
order ramipril sale ramipril oral order astelin 10 ml sprayers
order clonidine 0.1mg generic buy meclizine 25 mg online buy spiriva online cheap
order hytrin 1mg arava 10mg sale cheap azulfidine 500 mg
buy tacrolimus 5mg sale buy prograf 1mg without prescription ursodiol 300mg generic
order generic imdur order azathioprine generic telmisartan 80mg cost
zyban 150 mg without prescription buy zyrtec buy quetiapine online cheap
molnunat pills generic lansoprazole 15mg order lansoprazole 30mg pill
tadalafil 10mg sale order prozac 40mg sildenafil mail order usa
cialis from india purchase tadalafil sale buy amantadine online
naltrexone online generic abilify 30mg abilify 20mg cost
buy dapsone 100 mg pill buy adalat 10mg pill buy perindopril without prescription
cheap provera 10mg cyproheptadine for sale buy periactin 4mg without prescription
order generic provigil 100mg order provigil sale stromectol buy
order accutane 20mg order prednisone sale order prednisone 20mg pill
nootropil 800mg cheap sildenafil 100mg pills for sale viagra order online
order azithromycin pills buy neurontin 800mg cost gabapentin 800mg
buy tadalafil 10mg generic sildenafil canada buy viagra 50mg generic
Best site cialis
comprar cialis
comprar cialis
cialis
Drug absorption from four intestinal segments was investigated discount cialis He has to sleep with me, under the covers
hauseri are cefotaxime and ceftizoxime, and the alternative antibiotics are cefoxitin and trimethoprim TMP sulfamethoxazole SMX how many inches does viagra give you