![]() The command below will list all files containing a line with the text “ check_root”, by recursively and aggressively searching the ~/bin directory. Read Also: 11 Advanced Linux ‘Grep’ Commands on Character Classes and Bracket Expressions This article will guide you on how to do that, you will learn how to recursively dig through directories to find and list all files that contain a given string of text.Ī simple way to work this out is by using grep pattern searching tool, is a powerful, efficient, reliable and most popular command-line utility for finding patterns and words from files or directories on Unix-like systems. Just switch 1G to 2G or 500M and so on.Do you want to find all files that contain a particular word or string of text on your entire Linux system or a given directory. Those are some of the ways you find directories larger than 1GB, or any other size you desire for that matter. You can also sort the first command like this too, in which case you’re combining the three commands into one: # du -h -max-depth=1 / | grep 'G\>' | sort -hr If you want it to display all directories, not just first level, just leave out the -d 1 option.įinally, as a bonus, you can sort the results from largest to smallest by piping in the sort command: # du -h -d 1 -t 1G / | sort -hr ![]() It will display first level directories larger than 1GB within the root / path, just like the first command. You can use the built in -t or –threshold option of the du command like this: # du -h -d 1 -t 1G / ![]() This single command is all you need for this task, but there’s an even shorter one that works well too. Here’s another example of this command, but with –max-depth=1 being shortened to -d 1, which works the same, and checking the /var directory instead of the root / directory. So the grep ‘G>’ searches through the du output and displays only the files that are larger than 1GB. The | sign is the pipe sign that allows combining the first command with the next command, in this case grep, which is used for searching through text output for the specified strings, which can be specified through regular expressions. If we were to specify 2 it would go a level further and also look into directories like /home/user, /usr/bin, /var/log, etc. The –max-depth=1 option makes it display the sizes of only the directories immediately within the specified path, in this case the root path /, which in Linux includes directories like /home, /usr, /bin, /var, and so on. The -h option displays the sizes in a more human readable format, in gigabytes rather than kilobytes. ![]() So to find directories that are larger than 1GB you can run this command: du -h -max-depth=1 / | grep 'G\>' The du command can be used with options that allow you to customize the results you get.Ĭommands can also be combined with each other so the second command filters the results output by the first command. Finding out sizes of files and directories in Linux is done using the du command, which estimates their disk space usage. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |