This post is a continuation to my post from two weeks ago where I talked about Linux commands for file management.
2>
Redirects standard error instead of standard output. Useful when a command is throwing warnings or errors you want to save separately from its normal output.
Usage: command 2> errors.log
2>&1
Redirects standard error into the same stream as standard output, so both end up in the same place. Commonly paired with > to capture everything a command prints.
Usage: command > output.log 2>&1
!!
Re-runs the last command you typed. Useful for when sudo was forgotten
Usage: sudo !!
TEXT PROCESSING
sort
Sorts the lines of a file or input alphabetically by default. The -n flag sorts numerically instead of as text, -r reverses the order, and -k lets you sort by a specific column.
Usage: sort -n scores.txt
uniq
Filters out repeated adjacent lines, either removing duplicates or, with -c, counting how many times each line occurs.
Usage: sort names.txt | uniq -c
wc
Word Count. Prints the number of lines, words, and bytes in a file. Use -l for just lines, -w for just words, or -c for just bytes.
Usage: wc -l access.log
cut
Pulls out a specific section from each line of input, usually a column in delimited text like a CSV. The -d flag sets the delimiter and -f picks which fields to keep.
Usage: cut -d ',' -f 2 contacts.csv
tr
Translates or deletes characters from input, one for one. Good for quick jobs like changing case or stripping out unwanted characters. It only reads from standard input, so it's always used with a pipe or redirect.
Usage: cat notes.txt | tr 'a-z' 'A-Z'
sed
Stream editor. Reads input line by line and applies an edit to each one, most commonly a find-and-replace using the s/pattern/replacement/ syntax. Add a g at the end to replace every match on a line, not just the first.
Usage: sed 's/http/https/g' urls.txt
awk
A small programming language built for working with columnar text. It automatically splits each line into fields you can reference as $1, $2, and so on, with $0 meaning the whole line. It's overkill for simple jobs but worth understanding once you need conditions or math on your columns.
Usage: awk '{print $1, $3}' access.log
xargs
Takes lines from standard input and turns them into arguments for another command. Many commands, like rm or grep, don't read from a pipe directly, so xargs is what lets you feed piped output into them.
Usage: find . -name "*.tmp" | xargs rm
NETWORKING
ping
Sends small packets to a host and reports how long they take to come back, confirming whether a machine is reachable at all. Runs continuously until you stop it with ctrl+c, unless you cap it with -c.
Usage: ping -c 4 google.com
curl
Transfers data to or from a server over HTTP, FTP, and other protocols. By default it just prints the response body, but flags like -I (headers only), -o (save to file), and -X (set the request method) make it more flexible.
Usage: curl -I https://example.com
wget
Downloads files from the web straight to disk. Where curl is built for talking to APIs and inspecting responses, wget is built for grabbing a file and saving it, including recursively pulling down a whole page with its assets.
Usage: wget https://example.com/file.zip
ip
Shows and configures network interfaces, addresses, and routing on the machine. The older ifconfig command does something similar but is considered deprecated on most modern distros in favor of ip.
Usage: ip a
ss
Lists the network sockets currently open on the machine, such as which ports are listening for connections. The -t flag limits it to TCP, -u to UDP, -l to listening sockets, and -n skips resolving names so it runs faster.
Usage: ss -tuln
dig
Queries DNS servers directly and shows the full result, which makes it the go-to tool for debugging why a domain isn't resolving the way you expect.
Usage: dig example.com
ssh
Secure Shell. Opens an encrypted terminal session on a remote machine, as if you were sitting in front of it. Requires an account on the remote machine, identified as user@host.
Usage: ssh user@192.168.1.10
scp
Secure Copy. Copies files between machines over the same encrypted connection SSH uses. The syntax mirrors cp, just with a user@host: prefix on whichever side is remote.
Usage: scp report.pdf user@192.168.1.10:/home/user/
Hopefully this gave some more insight as to how the Linux terminal can be a powerful place to do online work.
Happy coding!
Top comments (0)