johnbion.blogg.se

Bash find file pipe to directory
Bash find file pipe to directory









bash find file pipe to directory

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.

bash find file pipe to directory bash find file pipe to directory

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.











Bash find file pipe to directory