How to add a column heading with awk on Linux.

This very nice one-liner will print some information about your mounted drives on Linux and also print a column header to dress up the output. ┌──[[email protected]]─[~/Downloads] └──╼ ╼ $ df -Hla | grep "[0-9]% /" | awk -F, ‘NR==1 {print "Device","Capacity","Free","Usage","Percentage","Mount"} {gsub(/"/,""); print $1,$2,$4}’ | column -t Device Capacity Free…

Read More

Good ways to find files in your home directory.

Finding files in your home directory is very easy. The command below will search inside all files in your home directory and find all files that contain the text “linux”. find . -type f -exec grep -niH linux ‘{}’ ‘;’find . -type f -exec grep -niH linux ‘{}’ ‘;’ This…

Read More

How to recursively search with grep on Linux.

The grep utility is very useful for searching for text in files on a Linux system. It is possible to search for text or files recursively. This is very easy to do. This example is how to search for a text string recursively with grep. I have double quotes in…

Read More

Fun with sed on Linux.

The sed command can be used to reverse text. This is a very interesting feature. Provide a text string, and it will be reversed. jason@jason-Virtual-Machine:~$ sed ‘/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/./Hello. /’ <<< ‘This is a long sentence in reverse. This is a lot of fun.’ Hello. .nuf fo tol a si sihT .esrever…

Read More

Search and replace text in a file with ed.

I have a text file containing this string. deusexmachina:Documents jason$ cat out Darwin deusexmachina.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64deusexmachina:Documents jason$ cat out Darwin deusexmachina.local 18.2.0 Darwin Kernel Version 18.2.0: Mon Nov 12 20:24:46 PST 2018; root:xnu-4903.231.4~2/RELEASE_X86_64 x86_64 And I want to replace…

Read More