ls & du -sh * | sort -hĪudiobooks Desktop Documents Downloads Music Pictures Public Templates Videos In both home or office environments managing the hard drive usage is essential. Users may need to determine which directories are utilizing the most space on their filesystem. Interesting Use-Cases Sorting by File/Folder Size There is NO WARRANTY, to the extent permitted by law. This is free software: you are free to change and redistribute it. License GPLv3+: GNU GPL version 3 or later. sort -versionĬopyright (C) 2017 Free Software Foundation, Inc. Once patched and cleanly secured, the sort -version command would display the new hardened version number, thereby confirming your safety. If there were ever to be a security flaw discovered in the sort package, it would be imperative to check your vulnerability as soon as possible. You can display the package information from your local system by adding the -version option to sort. Though seemingly counter-intuitive, one of the most important of sort might not include sorting of any kind. This example is using the 9th column’s friendly folder name as the “key”, as well as the -r option to invert the alphabetical order. Here we’re once again leveraging the useful piping capability of sort we’ve sorted the list output of the user’s home directory. ls -l /home/mtatum/ | sort -rk9ĭrwxr-xr-x 2 mtatum mtatum 4096 Dec 26 14:44 Videosĭrwxr-xr-x 2 mtatum mtatum 4096 Dec 26 14:44 Templatesĭrwxr-xr-x 2 mtatum mtatum 4096 Dec 26 14:44 Publicĭrwxr-xr-x 4 mtatum mtatum 4096 Jan 24 18:10 Picturesĭrwxr-xr-x 2 mtatum mtatum 4096 Dec 26 14:44 Musicĭrwxr-xr-x 2 mtatum mtatum 4096 Feb 9 12:58 Downloadsĭrwxr-xr-x 5 mtatum mtatum 4096 Jan 24 18:10 Documentsĭrwxr-xr-x 2 mtatum mtatum 4096 Dec 27 16:55 Desktopĭrwxrwxrwx 14 mtatum mtatum 4096 Audiobooks We can get more granular with our sorting by changing the “key” with the -k option. We may need to skip certain fields, or certain portions of lines. In other words, the key character determines the sequence order. Ordinarily, the first character of the line is the “key”. We need a field to be the deciding factor upon which we sort. Conceptually, the “key” in the sort command functions very similarly to the way that a database table’s primary key works.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |