Examples of useful commands which can be both easy to forget for experts and hard to guess for Linux novices. Almost all of these examples should work identically on MacOS and the Windows Subsystem for Linux (WSL).
Tools such as rg
, bat
, fzf
, ffmpeg
,
soffice
(LibreOffice), and youtube-dl
may need to be installed
explicitly.
command | result | notes | |
---|---|---|---|
acpi -b -t |
show energy-related info
|
||
awk '$0 != ""' |
ignore empty lines | ||
awk '!c[$0]++' |
avoid duplicate lines |
|
|
awk 'NR == 1 || FNR != 1' filenames… |
concatenate table files sharing the same header (column names) without repeating the header line after the 1st time | only makes sense when given multiple filenames | |
awk -F '\t' -v OFS='\t' script… filenames… |
run AWK for tab-separated values | filenames are optional | |
awk '{ gsub(/\x1b\[[0-9;]+m/, ""); print }' filenames… |
ignore ANSI-terminal escape codes, which are used for colors and styles | filenames are optional | |
bat -A infile |
browse text showing all normally-invisible characters like newline, tab, space, carriage return, etc. | very slow when dealing with 100+ MB data | |
bat -l sql infile |
browse text with line counts and SQL-syntax highlighting |
|
|
bat infile.sql |
browse file with line counts and SQL-syntax highlighting | file extensions act as automatic syntax-coloring hints | |
cal |
show a calendar for the current month | useful to see the days of the week for the whole month | |
cal year |
find which day of the week any day from the year given was | ||
curl -s uri |
quiet/silent curl | shows only received data, unless there are errors | |
curl wttr.in |
get local weather forecast |
|
|
curl wttr.in/city |
get weather forecast for the city given |
|
|
curl wttr.in/city?m |
get weather forecast for the city given using metric units when you’re in the US |
|
|
dos2unix -r filenames… |
removes
|
makes Windows-specific plain-text data compatible with modern Windows, Linux, and Mac | |
ffmpeg -i infile -acodec libmp3lame outfile.mp3 |
convert the audio file given into another MP3-encoded file | ||
ffmpeg -i infile -codec:a aac outfile.m4a |
convert the audio file given into another AAC-encoded file | ||
ffmpeg -i song.m4a -ss 00:00:06 -to 00:03:58 -c copy |
crop media file song.m4a from 6 seconds in to 3 minutes and 58 seconds in,
leaving song.m4a the same and saving result into cropped.m4a
|
to re-encode media data, don’t use option -c copy |
|
ffmpeg -f concat -safe 0 -i listfile -c copy outfile.m4a |
if the file given after option -i
|
|
|
file -i filenames… |
show autodetected mime-type for each filename given | ||
find folder -maxdepth 1 -type f |
show full filenames only for files (and not folders) inside the folder given, without digging into any of its subfolders | ||
find folder -type f -not -name '*.*' |
show full filenames only for files without extension inside the folder given |
|
|
fzf |
fuzzy-find items out of plain-text data |
|
|
go build -ldflags="-s -w" |
build smaller-sized programs using Go | ||
ip -4 addr show wifi0 | awk 'NR == 2 { print $2 }' | sed 's/\/[0-9]*//' |
show your LAN IP address | ||
less -NRS filenames… |
browse files or program results
|
|
|
openssl req -x509 -nodes rsa:4096 -keyout key.pem -out cert.pem -days 365 |
create SSL public/private-key files named key.pem and cert.pem which are valid for 365 days |
||
rg options pattern |
ripgrep (rg) is a crazy-fast regular-expression folder-digging searcher with sensible default settings | almost always preferable to grep |
|
sed 's/^ *//' |
ignore spaces at the beginning of lines | ||
sed 's/ *$//' |
ignore spaces at the end of lines | ||
sed 's/ +/ /g; s/ *\t */\t/g; s/^ *//; s/ *\$//' |
ignore spaces
| useful to clean/improve tab-separated data | |
soffice --convert-to pdf:writer_pdf_Export infile |
export a wordprocessor file as a PDF one | you need LibreOffice or OpenOffice installed | |
soffice --convert-to txt infile |
export a wordprocessor file as a plain-text one |
|
|
sort -k 3 |
sort lines using only the 3rd field in each line | ||
sort -n |
sort lines, using number-ordering (instead of ASCII-ordering) | you can also add the -k option from above |
|
sort -rn |
sort lines in reverse order, using number-ordering | you can also add the -k option from above |
|
sort -u |
sort lines, then ignore duplicate lines |
|
|
tr -d '\r' |
ignore all carriage returns | ||
xargs -d '\n' command options… |
run a command using the options given explicitly, followed by each line taken from the standard input, each of which will be added to the list of options |
by default xargs splits its standard input with spaces into multiple
arguments: this is wrong and annoying when dealing with filenames, since these
can include spaces
|
|
xclip |
copy text to clipboard | use with files or at the end of a pipeline chain | |
xclip -o |
emit text from clipboard | ||
youtube-dl -F youtube-uri |
show all formats available for the YouTube URI given, along with their numeric codes | ||
youtube-dl -f 140 youtube-uri |
download audio file in AAC format (.m4a file) for the YouTube URI given | AAC format seems to be always available | |
youtube-dl -f 251 youtube-uri |
download audio file in Opus (160k) format for the YouTube URI given | Opus format not always available |