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 |
see energy-related info
|
||
awk '$0 != ""' |
ignore empty lines | you can follow it with a list of filenames | |
awk '!c[$0]++' |
avoid duplicate lines |
|
|
awk 'NR == 1 || FNR != 1' |
concatenate table files sharing the same header (column names) without repeating the header line after the 1st time | useful when followed by several filenames | |
awk -F '\t' -v OFS='\t' |
run AWK for tab-separated values | follow this with an AWK command/script | |
awk '{ gsub(/\x1b\[[0-9;]+m/, ""); print }' |
ignore ANSI-terminal escape codes, which are used for colors and styles | you can follow it with a list of filenames | |
bat -A |
browse text showing all normally-invisible characters like newline, tab, space, carriage return, etc. | slow when dealing with 100+ MB data | |
bat -l sql |
browse text with line counts and SQL-syntax highlighting |
|
|
bat data.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 1995 |
find which day of the week any day from 1995 was | ||
curl -s |
quiet/silent curl | shows only received data, unless there are errors | |
curl wttr.in |
get local weather forecast |
|
|
curl wttr.in/delhi |
get weather forecast for Delhi | same as above | |
curl wttr.in/delhi?m |
get weather forecast for Delhi using metric units when you’re in the US | same as above | |
dos2unix -r |
removes
|
makes Windows-specific plain-text data compatible with modern Windows, Linux, and Mac | |
ffmpeg -i infile -acodec libmp3lame result.mp3 |
convert the audio file infile into the MP3-encoded result.mp3 |
||
ffmpeg -i infile -codec:a aac result.m4a |
convert the audio file infile into the AAC-encoded result.m4a |
||
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 filelist.txt -c copy result.m4a |
if filelist.txt
result.m4a
|
|
|
file -i |
show autodetected mime-type for each filename given | ||
find some-folder -maxdepth 1 -type f |
show full filenames only for files (and not folders) inside the folder
named some-folder , without digging into any of its subfolders
|
||
find some-folder -type f -not -name '*.*' |
show full filenames only for files without extension inside the folder named
some-folder
|
|
|
fzf |
fuzzy-find items out of piped 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 |
browse files or program results
|
an improvement over the default behavior of less when dealing with
styled and/or wide content
|
|
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 |
crazy-fast regular-expression folder-digging searcher | 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 |
export a wordprocessor file as a PDF one |
|
|
soffice --convert-to txt |
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' |
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 |
show all formats available for the YouTube URI given, along with their numeric codes | ||
youtube-dl -f 140 |
download audio file in AAC format (.m4a file) for the YouTube URI given | seems to be always available | |
youtube-dl -f 251 |
download audio file in Opus (160k) format for the YouTube URI given | not always available |