So it fits precisely du with the –files0-from=- option. find‘s -print0 action prints each filename followed by a null character. So if we want du to process the filenames found by the find command, we can use the -print0 action. We’ve seen that the find command prints each file’s name with a newline character. This is pretty useful if we pipe a bunch of filenames to the du command. Further, the filenames should be terminated by a null character. It’s worth mentioning that when F is –, du reads filenames from stdin. What exactly do you mean by the 'size' of a directory The number of files under it (recursively or not) The sum of the sizes of the files under it (recursively or not) The disk size of the directory itself (A directory is implemented as a special file containing file names and other information. Example usage for your specific case: find rapidlyshrinkingdrive/ -name 'offender1' -mtime -1 -print0 du -files0-from-hc tail -n1 (Previously I wrote du -hs, but on my machine that appears to disregard find s input and instead summarises the size of the cwd. Instead of passing filenames directly to the du command, we can use the –files0-from=F option to tell du to read filenames from the F file. The command du tells you about disk usage. We know that the du command with the -b option reports the given files or directories size in bytes, for example: $ du -b myDir/picture01.jpgĪdditionally, we can add the -c option to make du sum up the file sizes for all files we pass to it: $ du -bc myDir/*.jpg However, we need to type the awk command whenever we want to sum up the filesizes in the ls output. A compact awk one-liner solves our problem. Here is a way on how to find top 10 largest files in Linux largest files in directory recursively on a Ubuntu Linux System. To achieve that, we can pipe the ls -l output to the awk command: $ ls -l *.* | awk ''Īs we can see, the total size (in bytes) of the listed files is calculated and printed. Which is the command to find largest files in Linux Ubuntu. Now that we understand the ls -l output, if we want to sum the file sizes in the ls -l list, we need to sum the fifth column (file size in bytes) in each file record. | | | | | | +- The last modification time Let’s take the 001.txt file as an example to understand the ls -l output: -rw-r-r- 1 kent kent 2 Dec 9 13:20 001.txt
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |