TL;DR
- Basic Linux commands that we use literally all the time.
alias
alias grep=“grep –color” alias
ps
- print pid: ps -C {program-name} -o pid=
- Show full command: ps -f | less
- ps detects the size of your terminal window and clips to that.
xargs
- use \0 as the delimiter and -0 to use it
- printf ‘%s\0’ Hello Hola Bonjour | xargs -0 -I _ echo _ Landon
Search
Sort files by date then grep
- ls -rt *.log | xargs grep -l
List open files
- ls -l /proc/${pid}/fd
- Use this when lsof is not installed
- lsof -p ${pid}
watch
- watch -n 5 curl -s localhost:8983/show/health
- -d: highlights the changes
curl
pbcopy (take standard input to clipboard) + pbpaste (take data from clipboard to standard output)
diff
sed
- sed -n ‘16224,16482p’ filename > newfile
System
Check the age of the system
- rpm -qi basesystem | grep “Install Date”
Misc
- cd $(dirname ${file_full_path})
- tar xfz somefilename.tar.gz
- dirname, basename, realpath
- Copy one file to multiple file names
- cat 1.ods | tee {jan,feb,mar}-{Rep,graph}.ods >/dev/null
- tail -f **/*.log
Get current working directory of a process
- pwdx
- lsof -p
| grep cwd - readlink -e /proc/
/cwd ##### [View a range of bash history] - fl -l ${start} ${end}
- history | sed ‘start,{end}p’
- lsof -p
Brace expansion
- mkdir -p {f1, f2}
- for i in {1..3}; do echo $i; done
- {START..END..INCREMENT}
Command History
!!:n | where n is the 0-based position of the argument you want |
!$ | last argument from previous command |
!^ | first argument (after the program/built-in/script) from previous command |
!! | previous command (often pronounced “bang bang”) |
!n | command number n from history |
!pattern | most recent command matching pattern |
!!:s/find/replace | last command, substitute find with replace |
:p | print the command - !!:p, !!n:p |