I had already a situation where an application was (wrongly) creating thousands of small files, and it was hard to find out the disk space's offender. Luizfnpinho said:I was wondering what would be the best way to list the most dense folder, in terms of disk occupation. Once complete it will return the top ten largest files / directories, their sizes and locations. It will take a little time to run as it needs to check every directory of the filesystem. sudo du -aBm / 2>/dev/null | sort -nr | head -n 10ģ. | head -n 10 will list the top ten files/directories returned from the search. | 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. is the root directory, the starting point for the search.Ģ>/dev/null will send any errors to /dev/null ensuring that no errors are printed to the screen. Use the du command to search all files and then use two pipes to format the returned data.ĭu -aBM will search all files and directories, returning their sizes in megabytes. 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.Ģ. sudo find / -type f -size +100M Finding the 10 Largest Linux Files on Your Drive 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. For this example connect a USB drive with a collection of files on it including some that are over 100MB in size. Search all filesystems for files larger than 100MB. Note that we are using / to set the command to search the entire filesystem from the root of the filesystem. As we are invoking root privileges using sudo we will need to input our password. Search the current filesystem for files larger than 100MB. 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.Ģ. To search the entire filesystem, we will need to use the command with sudo. We may have some files hidden away in our home directory that need removing. It’s sometimes useful to search the whole Linux filesystem for large files. test -type f -size +100M Searching the Whole Linux Filesystem For Large Files This means we can search the test directory from the home directory. We can run the same command as in the previous section but replace the “.” with a specified path. Use the same command, but this time specify a path to search. We only have one file in our test folder Baby_Yoda.obj that is larger than 100MB. Finally the +100M argument specifies that the command will only return files larger than 100MB in size. The -type f argument specifies returning files as results. We are working inside our test directory and the “.” indicates to search the current directory. Use find to search for any file larger than 100MB in the current directory. We can also use the find command in combination with the -size argument specifying a size threshold where any file larger than specified will be returned.\ġ. Binary entities, like zip files and executable programs, are indicated swith an asterisk ( *).In another article, we explained how to find files in Linux using the find command to search based on a filename or part of a filename. If you're color blind or on a display that doesn't provide colors, you can alternately use the -classify option: $ pwdĪs you can see, folders are given a trailing slash ( /) to denote that they are steps within your file system. If you don't see those colors, you can try ls -color. Some Linux distributions have some nice colors set up so that all folders are blue and the files are white and binary files are pink or green, and so on. You may notice that it's hard to tell a file from a folder. Files and folders and how to tell the difference Once you start moving around within your computer, you can use that information to create shortcuts for yourself or to increase the specificity of your paths. That is, you are in a folder in another folder. The two dots indicate that you can move back from this location. The single dot is actually a meta location meaning the folder you are currently in. Free online course: RHEL Technical OverviewĪs you can see, the first items listed are dots.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |