Not everyone thinks in binary or wants to mentally insert commas into large numbers to come to grips with the sizes of their files. So, it's not surprising that Linux commands have evolved over several decades to incorporate more human-friendly ways of displaying information to its users. In today\u2019s post, we look at some of the options provided by various commands that make digesting data just a little easier.\nWhy not default to friendly?\nIf you\u2019re wondering why human-friendliness isn\u2019t the default \u2013- we humans are, after all, the default users of computers \u2014 you might be asking yourself, \u201cWhy do we have to go out of our way to get command responses that will make sense to everyone?\u201d The answer is primarily that changing the default output of commands would likely interfere with numerous other processes that were built to expect the default responses. Other tools, as well as scripts, that have been developed over the decades might break in some very ugly ways if they were suddenly fed output in a very different format than what they were built to expect.\n\nIt\u2019s probably also true that some of us might prefer to see all of the digits in our file sizes \u2014 1338277310 instead of 1.3G. In any case, switching defaults could be very disruptive, while promoting some easy options for more human-friendly responses only involves us learning some command options.\nCommands for displaying human-friendly data\nWhat are some of the easy options for making the output of Unix commands a little easier to parse? Let's check some command by command.\ntop\nYou may not have noticed this, but you can change the display of overall memory usage in top by typing "E" (i.e., capital E) once top is running. Successive presses will change the numeric display from KiB to MiB to GiB to TiB to PiB to EiB and back to KiB.\nOK with those units? These and a couple more are defined here:\n2**10 = 1,024 = 1 KiB (kibibyte)\n2**20 = 1,048,576 = 1 MiB (mebibyte)\n2**30 = 1,073,741,824 = 1 GiB (gibibyte)\n2**40 = 1,099,511,627,776 = 1 TiB (tebibyte)\n2**50 = 1,125,899,906,842,624 = PiB (pebibyte)\n2**60 = 1,152,921,504,606,846,976 = EiB (exbibyte)\n2**70 = 1,180,591,620,717,411,303,424 = 1 ZiB (zebibyte)\n2**80 = 1,208,925,819,614,629,174,706,176 = 1 YiB (yobibyte)\n\nThese units are closely related to kilobytes, megabytes, and gigabytes, etc. But, while close, there's still a significant difference between them. One set is based on powers of 10 and the other powers of 2. Comparing kilobytes and kibibytes, for example, we can see how they diverge:\nKB = 1000 = 10**3\nKiB = 1024 = 2**10\n\nHere's an example of top output using the default display in KiB:\ntop - 10:49:06 up 5 days, 35 min, 1 user, load average: 0.05, 0.04, 0.01\nTasks: 158 total, 1 running, 118 sleeping, 0 stopped, 0 zombie\n%Cpu(s): 0.0 us, 0.2 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\nKiB Mem : 6102680 total, 4634980 free, 392244 used, 1075456 buff\/cache\nKiB Swap: 2097148 total, 2097148 free, 0 used. 5407432 avail Mem\n\nAfter one press of an E, it changes to MiB:\ntop - 10:49:31 up 5 days, 36 min, 1 user, load average: 0.03, 0.04, 0.01\nTasks: 158 total, 2 running, 118 sleeping, 0 stopped, 0 zombie\n%Cpu(s): 0.0 us, 0.6 sy, 0.0 ni, 99.4 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\nMiB Mem : 5959.648 total, 4526.348 free, 383.055 used, 1050.246 buff\/cache\nMiB Swap: 2047.996 total, 2047.996 free, 0.000 used. 5280.684 avail Mem\n\nAfter a second E, we get GiB:\ntop - 10:49:49 up 5 days, 36 min, 1 user, load average: 0.02, 0.03, 0.01\nTasks: 158 total, 1 running, 118 sleeping, 0 stopped, 0 zombie\n%Cpu(s): 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\nGiB Mem : 5.820 total, 4.420 free, 0.374 used, 1.026 buff\/cache\nGiB Swap: 2.000 total, 2.000 free, 0.000 used. 5.157 avail Mem\n\nYou can also change the numbers displaying per-process memory usage by pressing the letter \u201ce\u201d. It will change from the default of KiB to MiB to GiB to TiB to PiB (expect to see LOTS of zeroes!) and back. Here's some top output after one press of an "e":\ntop - 08:45:28 up 4 days, 22:32, 1 user, load average: 0.02, 0.03, 0.00\nTasks: 167 total, 1 running, 118 sleeping, 0 stopped, 0 zombie\n%Cpu(s): 0.2 us, 0.0 sy, 0.0 ni, 99.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\nKiB Mem : 6102680 total, 4641836 free, 393348 used, 1067496 buff\/cache\nKiB Swap: 2097148 total, 2097148 free, 0 used. 5406396 avail Mem\n\n PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND\n 784 root 20 0 543.2m 26.8m 16.1m S 0.9 0.5 0:22.20 snapd\n 733 root 20 0 107.8m 2.0m 1.8m S 0.4 0.0 0:18.49 irqbalance\n22574 shs 20 0 107.5m 5.5m 4.6m S 0.4 0.1 0:00.09 sshd\n 1 root 20 0 156.4m 9.3m 6.7m S 0.0 0.2 0:05.59 systemd\n\ndu\nThe du command, which shows how much disk space files or directories use, adjusts the sizes to the most appropriate measurement if the -h option is used. By default, it reports in kilobytes.\n$ du camper*\n360 camper_10.jpg\n5684 camper.jpg\n240 camper_small.jpg\n$ du -h camper*\n360K camper_10.jpg\n5.6M camper.jpg\n240K camper_small.jpg\n\ndf\nThe df command also offers a -h option. Note in the example below how sizes are reported in both gigabytes and megabytes.\n$ df -h | grep -v loop\nFilesystem Size Used Avail Use% Mounted on\nudev 2.9G 0 2.9G 0% \/dev\ntmpfs 596M 1.7M 595M 1% \/run\n\/dev\/sda1 110G 9.0G 95G 9% \/\ntmpfs 3.0G 0 3.0G 0% \/dev\/shm\ntmpfs 5.0M 4.0K 5.0M 1% \/run\/lock\ntmpfs 3.0G 0 3.0G 0% \/sys\/fs\/cgroup\ntmpfs 596M 16K 596M 1% \/run\/user\/121\n\/dev\/sdb2 457G 73M 434G 1% \/apps\ntmpfs 596M 0 596M 0% \/run\/user\/1000\n\nThe command below uses the -h option, but also includes -T to display the type of file system we are looking at.\n$ df -hT \/mnt2\nFilesystem Type Size Used Avail Use% Mounted on\n\/dev\/sdb2 ext4 457G 73M 434G 1% \/apps\n\nls\nEven ls gives us the option of adjusting size displays to the measurements that are the most reasonable.\n$ ls -l camper*\n-rw-rw-r-- 1 shs shs 365091 Jul 14 19:42 camper_10.jpg\n-rw-rw-r-- 1 shs shs 5818597 Jul 14 19:41 camper.jpg\n-rw-rw-r-- 1 shs shs 241844 Jul 14 19:45 camper_small.jpg\n$ ls -lh camper*\n-rw-rw-r-- 1 shs shs 357K Jul 14 19:42 camper_10.jpg\n-rw-rw-r-- 1 shs shs 5.6M Jul 14 19:41 camper.jpg\n-rw-rw-r-- 1 shs shs 237K Jul 14 19:45 camper_small.jpg\n\nfree\nThe free command allows you to report memory usage in bytes, kilobytes, megabytes, and gigabytes.\n$ free -b\n total used free shared buff\/cache available\nMem: 6249144320 393076736 4851625984 1654784 1004441600 5561253888\nSwap: 2147479552 0 2147479552\n$ free -k\n total used free shared buff\/cache available\nMem: 6102680 383836 4737924 1616 980920 5430932\nSwap: 2097148 0 2097148\n$ free -m\n total used free shared buff\/cache available\nMem: 5959 374 4627 1 957 5303\nSwap: 2047 0 2047\n$ free -g\n total used free shared buff\/cache available\nMem: 5 0 4 0 0 5\nSwap: 1 0 1\n\ntree\nWhile not related to file or memory measurements, the tree command also provides very human-friendly view of files by displaying them in a hierarchical display to illustrate how the files are organized. This kind of display can be very useful when trying to get an idea for how the contents of a directory are arranged.\n$ tree\n.g to \n\u251c\u2500\u2500 123\n\u251c\u2500\u2500 appended.png \n\u251c\u2500\u2500 appts\n\u251c\u2500\u2500 arrow.jpg\n\u251c\u2500\u2500 arrow.png\n\u251c\u2500\u2500 bin\n\u2502 \u251c\u2500\u2500 append\n\u2502 \u251c\u2500\u2500 cpuhog1\n\u2502 \u251c\u2500\u2500 cpuhog2\n\u2502 \u251c\u2500\u2500 loop\n\u2502 \u251c\u2500\u2500 mkhome\n\u2502 \u251c\u2500\u2500 runme\n\nstat\nThe stat command is another that displays information in a very human-friendly format. It provides a lot more metadata on files, including the file sizes in bytes and blocks, the file types, device and inode, owner and group (names and numeric IDs), file permissions in both numeric and rwx format and the dates the file was last accessed and modified. In some circumstances, it might also display when the file was initially created.\n$ stat camper*\n File: camper_10.jpg\n Size: 365091 Blocks: 720 IO Block: 4096 regular file\nDevice: 801h\/2049d Inode: 796059 Links: 1\nAccess: (0664\/-rw-rw-r--) Uid: ( 1000\/ shs) Gid: ( 1000\/ shs)\nAccess: 2018-07-19 18:56:31.841013385 -0400\nModify: 2018-07-14 19:42:25.230519509 -0400\nChange: 2018-07-14 19:42:25.230519509 -0400\n Birth: -\n File: camper.jpg\n Size: 5818597 Blocks: 11368 IO Block: 4096 regular file\nDevice: 801h\/2049d Inode: 796058 Links: 1\nAccess: (0664\/-rw-rw-r--) Uid: ( 1000\/ shs) Gid: ( 1000\/ shs)\nAccess: 2018-07-19 18:56:31.845013872 -0400\nModify: 2018-07-14 19:41:46.882024039 -0400\nChange: 2018-07-14 19:41:46.882024039 -0400\n Birth: -\n\nWrap-up\nLinux provides many command options that can make their output easier for users to understand or compare. For many commands, the -h option brings up the friendlier output format. For others, you might have to specify how you'd prefer to see your output by using some specific option or pressing a key as with top. I hope that some of these choices will make your Linux systems seem just a little friendlier.