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.\ġ. In our case, we only need to match files.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. The -type test is used to filter the type of the match. mozilla/firefox/esr/extension-preferences.json mozilla/firefox/esr/shield-preference-experiments.json However, we can if we want to search for files by extension, we can simply use -name or -iname: $ find -type f -iname "*.json" * at the beginning of the regex is used to print the path of the file. Alternatively, we can use the -iregex test to disable case sensitivity. The – regex test specifies a pattern that is used to match all files that contain zsh in its filename. For that reason, we can use the -iregex or – regex test: $ find -regex ".*\(zsh\|bash\)rc" Sometimes, we might want to search for files based on a pattern. The -iname test turns off case sensitivity, as opposed to the -name test, which retains case sensitivity. We’ll specify it using the -iname test: $ find -iname ".zshrc" When we run the find command without any options, it will list all the files and directories in the current directory. The basic syntax for find is straightforward: $ find īy default, the path is the current directory.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |