![]() ![]() -r, -reverse – Reverse the result of comparisons.-h, -human-numeric-sort – Compare human readable numbers (eg, 2K, 1G).To sort in reverse (descending) order, you can use the -r option with sort -h, i.e., sort -hr. To sort the output above by the sizes that you see in ascending order, we can pipe the output to the sort command: $ du -ah -d 1 2>/dev/null | sort -h This makes it default to the current working directory which in this case is HOME.Īs you can see, the output above is listed in random order (not sorted on size or file/folder names). Note: In the command above, we don’t pass any file or directory as an argument to the command. ![]() ![]() 2>/dev/null – Any directory/file that can’t be processed (due to permission error for instance) will throw an error.Press Esc or Q to quit the interactive mode. You can see the current sort field in the top right corner. When you are at the desired parameter, press S to sort on it. Step 3: Use the arrow key to choose a different parameter like MEM, TIME, VIRT etc. -d, -max-depth=N – Process stats for N levels in the directory (argument) hierarchy. Step 2: Press Shift+F to enter the interactive mode.-h, -human-readable – Prints sizes in human-readable format (e.g., 1K, 234M, 2G).-a, -all – Displays usage stats for files too, not just directories. The sort command is an essential utility in Linux that arranges the contents of a file or standard input in ascending or descending order.With a couple of options, we can get a decent output: # Get file and folder sizes present in the current directory The du command displays the disk usage statistics (estimated file space usage) of the files or directories (recursively) passed to it as arguments. $ du | sort -hr # Descending order of sizes This command is an excellent tool for organizing text alphabetically and numerically. Arranging Data Easily With Linux Sort And Grep Commands. This should work in most Unix-based or Unix-like operating systems (Linux, BSD, macOS): $ du | sort -h # Ascending order of sizes The Linux sort command is a useful tool for quickly and easily organizing data, and it can be used to arrange large data sets in a logical and easy-to-understand way. To sort in descending order, pipe it to sort -hr. TL DR: To sort du command’s output in ascending order of the file and/or directory sizes, we can pipe its output to sort -h. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |