Commonly used commands

# change directory
# e.g. cd /home/
cd ../
 
# list
# -a:  list all files including hidden file starting with '.'
# -l:  list with long format - show permissions.
# -t:  sort by time & date.
# -lh: show you the file sizes in human readable format.
# most of the time I use: ls -al
ls -al .
 
# find
# example: find a file
# find . -name abcd
# example: find a folder
# find / -type d -name abcd
find
 
# echo
echo
 
# print working directory
pwd
 
# update the access date and/or
# modification date of a computer file or directory
# if file does not exist, create a new one.
touch
 
# set the shell configurations
# -e: instructs a shell to exit if a command yields a non-zero exit status.
# -v: prints out the lines of the shell input as they are being read.
# -x: prints command arguments during execution
set -x -e -v
 
# word count
# example:
# ls -l
# echo 'lines: ' $(ls -l | wc -l)
# echo 'words: ' $(ls -l | wc -w)
wc
 
# process status
# example:
# ps -ef | grep KEYWORD
ps
 
# list open files
 
lsof
 
# Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
# -e:
# -l:
# -n:
# -p:
# -t:
# -u:
netstat -tulpne | grep LISTEN
 
# example: any process listening to the port 8080 forcely
# kill -9 $(lsof -t -i:8080)
kill
 
# global regular expressions parser
# example:
# ls -l | grep '^d'
# grep -i "string" filename
# ps -ef | grep -c $USER
# REGEX='https:\/\/sonarqube.shoplinedev.com/api/ce/task\?id=\S*'
# PROCESS_STATUS=$(curl --silent $(cat sonarqube_result.txt | grep -Eo $REGEX) | jq -r '.task.status')
grep
 
# Aho, Weinberger, Kernighan
# Awk is a programing language which allows easy manipulation of structured data and the generation of formatted reports.
# example:
# lsof -i -P | grep '3000' | awk '{print $2}'
# $(kubectl -n <some-namespace> get pod | grep api | awk '{print $1}')
awk
 
# Stream editor
# A stream is data that travels from :
#   One process to another through a pipe
#   One file to another as a redirect
#   One device to another
# Sed performs 'text transformation' on streams
# example:
# sed '/^#/d' file
# terraform state list | grep module.workers | grep aws_ecs_task_definition.task-definition | sed "s/^/'/;s/$/'/" | tr "\n" " " | xargs terraform state rm || true
sed