Show Menu
Cheatography

Shell utilities & sytem management Cheat Sheet by

Various UNIX shell commands for programming, env and system management. Those commends are helpful, to me, but not often used. I had made this sheet to avoid periodically searching another time for the same thing.

ssh

sshfs [USER@­HOS­T]:­[re­mot­e_d­ire­ctory] mountpoint [options]
mount remote drive in mount­point
ssh -o Server­Ali­veI­nte­rval=X -o Server­Ali­veC­oun­tMax=Y [HOST]
Maintaing ssh conection for X seconds and Y tries
ssh-c­opy-id -i ~/.ssh­/id_rsa [USER@­HOST]
add autent­ication via ssh, not .pub file

operations on files & drives

cp -r $(<­fil­e_l­ist­ed.txt) outdir
copies files & direct­ories listed in file_­lis­ted.txt to outdir
xargs -a file_l­ist­ed.txt cp -r -t outdir
same as above
tar -(v)czf file.t­ar.gz /path/­to_­com­pres
create -cf archive -xf for extract
unzip file.zip -d file
unzip file.zip to file directory (must exists before)
mkdir -p dir
make parent direct­ories as needed, no error
rm -r !(*.ext)
delete everything except files with extension .ext
du -hs dir
check size of dir use -h for GB or -m for MB
basename path/b­ase­nam­e.ext .ext
get basename from path without ext
grep -i -r -E 'patte­rn1­|pa­tte­rn2­|pa­tte­rn3'
multiple patterns with grep -i case insens­itive -r recursive
find -(i)name "­pat­ter­n" -type d/f
list f files or d direct­ories with matching pattern
 

Statements

while read line; do [Command] done < input.file
Loop over file content
for file in ./*.ex­ten­tion; do [Command] done
loop over files in directory
if test -f file.txt; then [Command] fi
check if file exists -f , -d for directory
if [-f file.txt]; then [Command] fi
same different syntax
if [ -z "­$S1­" ]; then fi
checks if arg $1 is empty
function functi­on_name { <co­mma­nds> }
function declar­ation, $1 $2 - argument names
"$?­"
return exit status from last command
$(expr)
evaluate expr and store it's result

system

cat /proc/­cpuinfo #or lscpu
cpu inform­ations
uname -a
OS inform­ations
ss -tpln
show forwarded ports
lsblk -S
list block devices -S for minimal view
dd if=/pa­­th­/­t­o/­­ima­­ge.iso of=/dr­­iv­e­/­lo­­cation bs=4M && sync
create bootable drive from image.iso
sudo mount [drive] [mount­­po­int]
mounts drive at mount­­point
kill -9 $(pgrep -f [patte­rn])
terminate all processes matching pattern

git

git rm -r --cached <pa­th/­fil­e.e­xt>
remove untracked files
git clean -d -(n/f)
remove undone changes add: -n to show files to remove or -f to remove them
git fetch --all [branc­h_n­ame]
copies all changes from last pull/clone on current branch or given branch name
git log --not --remotes
all commits on all branches that aren't pushed yet
git checkout -b <ne­w_b­ran­ch>
change & create new branch
git switch -c <ne­w_b­ran­ch>
same as above
                   
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          Bash Script Colors Cheat Sheet
          Git Commands Cheat Sheet