This week, I learned about two (new to me) Linux commands that I am finding very helpful, in my system admin role.
“stdbuf” is a command that you can use to immediately adjust the default input/output buffer size in a pipeline of commands. For example, if you want to run “tail -F file” and pipe that to grep string, and pipe THAT to cut -c1-100, you’ll be frustrated, because while the tail command defaults to an output buffer of one line, because grep is outputting to another pipe, it defaults to a standard 4K buffer, and your screen output will pause until tail | grep passes 4K of data, then cut will read that and pass it through in one big unreadable chunk.
However, if you use stdbuf -oL grep string, you are running grep with line buffered output, and will get to see each line as soon as it is passed out of tail. Compare the behavior of these two slightly different commands:
tail -F /path/file | grep interestingstring | cut -c1-100 tail -F /path/file | stdbuf -oL grep interestingstring | cut -c1-100
Okay, the other one I just learned this morning is a simple way to list all block devices, and how they are used. Try this:
It will display something like:
$ lsblk -f NAME FSTYPE LABEL UUID MOUNTPOINT loop5 squash /snap/cano loop6 squash /snap/core sda ├─sda1 xfs 8fdebc8f-e44a-4771-8ade-702506563824 /boot ├─sda2 └─sda5 swap f9727aaf-47c2-437a-9ce0-34c4b34a4b0b [SWAP] sdb ├─sdb1 xfs f0c79706-7a42-4f4d-90be-a63f054e9f8f / ├─sdb2 LVM2_member Q039DZ-RfAF-ryYE-IKXD-7Ii3-LOd5-5Xzblt
Which shows my server has two disks, sda and sdb, and a couple of snap loopback filesystems mounted. The last entry is a Logical Volume Manager physical volume.
I think it’s cool, that after 30+ years of dealing with UNIX and almost that much dealing with Linux, there are still useful tricks to learn. Cheers!