Commands Summary

CommandPurpose
headDisplay the first few lines of a file or input
tailDisplay the last few lines of a file or input
cutExtract specific portion from each row of a file or input
grepFilters rows having a specified pattern in a file or input
sedStream editor used to find, replace and delete patterns in a file
awkPattern search and processing language
lessA pager that displays text files with scroll
catDisplays a file
xargsConverts input from stdin into arguments for a command
sortSorts a file or input
pwdPrint current working directory
lslist files and folders in a directory
echoPrint a message to stdout
manShow a commands manual
historyShow command history
clearClear command console
netstatShow system’s network info (routing & sockets)
ifconfigShow system’s network interface config
wgetDownload files from a URL
pingSend a connection request to a server, used to check network connectivity
shutdownShutdown system
psList running processes
pkillKill a running process
systemctlManage system services
timeCalculate command execution time
unamePrint info of the system kernel
chmodChange permissions of a file
chownChange ownership of a file
cdChange working directory
mvMove files
cpCopy files
rmDelete files
mkdirMakes a new directory
rmdirDeletes an empty directory
touchCreates a new file
sudoRuns a command as a superuser
xdg-openOpen file or URL using the default application
countReturns row count
whoamiPrint current user

Cut

ls -l | cut -d ' ' -f1-3  # prints fields 1,2 & 3 based on the space delimiter 
 
ls -l | cut -b1-2  # prints first 2 bytes of every line

Sed

# Replace all first occurences of 'unix' with 'linux' 
# in all lines
sed 's/unix/linux/' sample.txt
 
# s - indicates substitution
# / - delimiter
 
# To replace all occurences
sed 's/unix/linux/g' sample.txt

Awk

# Signature: awk '<Pattern> {<command>}' <file>
# start and end regex with '/'
 
# Print lines having the pattern 
awk '/option/ {print}' sample.txt 
 
# From the input stream
cat sample.txt | awk '/option/ {print}'
 
# Print 1st & 3rd column of lines with the pattern 
# with row number
awk '/option/ {print NR " - " $1 $3}' sample.txt 
 
# Print number of lines
awk 'END {print NR}' sample.txt 
 
# Number of .md files in my vault
find -name '*.md' -type f | awk 'END {print NR}'
 
# Get URLs of all image previews in a mardown file
cat file.md | awk 'match($0, /!\[\]\(([^)]+)\)/, arr) { gsub(/[()]/, "", arr[1]); print arr[1]}'

Xargs

# Total number of lines in .md files in my vault
find -name '*.md' -type f -print0 | xargs -0 cat | awk 'END {print NR}'
 
# Get line count of each file
find -name '*.md' -type f -print0 | xargs -0 wc -l