Skip to content

Instantly share code, notes, and snippets.

@cmccormack
Last active August 30, 2018 15:00
Show Gist options
  • Save cmccormack/2fc1f23fa11ca538ca63441cde6f8588 to your computer and use it in GitHub Desktop.
Save cmccormack/2fc1f23fa11ca538ca63441cde6f8588 to your computer and use it in GitHub Desktop.
Common Linux commands with examples

tee

The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered.

Example:

echo "I am the very model of a modern Major General" | tee general.txt
I am the very model of a modern Major General # Output
cat general.txt
I am the very model of a modern Major General # Output

awk

Though AWK is fairly general purpose, it is really designed to create filters, that is, programs that accept standard input, transform data, and send it to standard output. In particular, AWK is very good at processing columnar data. This makes it a good choice for developing report generators, and tools that are used to re-format data. Since it has strong regular expression support, it's good for very small text extraction and reformatting problems, too. Like sed, many AWK programs are just one line long.

Example:

ls -l
drwxr-xr-x   5 chris  Admin     170 Aug 25  2017 Applications
ls -l | awk '{print 3}'
chris

tr

The tr utility copies the standard input to the standard output with substitution or deletion of selected characters.

Example:

echo 'apples and bananas' | tr ' ' '_' | tr a-z A-Z
APPLES_AND_BANANAS

cut

The cut utility cuts out selected portions of each line (as specified by list) from each file and writes them to the standard output. If no file arguments are specified, or a file argument is a single dash (`-'), cut reads from the standard input. The items specified by list can be in terms of column position or in terms of fields delimited by a special character. Column numbering starts from 1.

Example:

echo "windmills" | cut -c 1,6-
wills

tac

Tac is practically the reverse version of cat command (also spelled backwards) which prints each line of a file starting from the bottom line and finishing on the top line to your machine standard output.

curl

curl is a tool to transfer data from or to a server, using one of the supported protocols (DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET and TFTP). The command is designed to work without user interaction.

wget
watch
head
tail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment