Matthew Hodge
Full Stack Developer

Over the course of a good couple of years I have built up quite a library of Gists, which is something I highly recomend every developer does, I thought it would be nice to share a couple of bash/terminal comamnds that have been pretty usefull

Zipping and Unzipping files and or folders

Calculate size of directories

Copying or syncing one location to another

Memory

Zipping and Unzipping files and or folders

using tar
man tar
tar --help # Shows all available params
zip file/folders
# c = create
# z = filter the archive through gzip
# v = verbosely list files processed
# f = use the archive file or device archive

# tar -czvf <name_of_tar_gz_file> <directory_or_file_to_compress>

tar -czvf plugins.tar.gz plugins
unzip file/folders
tar --help # Shows all available params

# x = extract from the arhive
# z = filter the archive through gzip
# v = verbosely list files processed
# f = use the archive file or device archive

# tar -czvf <name_of_tar_gz_file> <directory_or_file_to_compress>
tar -czvf plugins.tar.gz plugins

Calculate size of directories

using du
man du
du --help # Shows all available params
dir size
# you may or maynot need to sudo pending the file and folder 
# permissions of the directory you are wanting to calculate

# s = summarize
# h = human readable (my favourite)

# du -sh <path>/*
du -sh ./* # will display summary of the current working directory

Copying or syncing one location to another

rsync
man rsync
rsync --help
how to use
# a = archive mode; equals -rlptgoD (no -H,-A,-X)
# v = increase verbosity
# z = compress file data during the transfer
# h = output numbers in a human-readable format
# --dry-run = simulates what would happen but does not actualy copy or sync

# local example
# rsync -avzh <source> <dest> --dry-run

# copy a file/folder from local to server over ssh
# rsync -avzh <source>/* <user>@<host>:<dest>/ --dry-run

# copy a file/folder from local to a server over ssh with a non standard port
# rsync -avzh --rsh='ssh -p2345' <source>/* user@host:<dest>/ --dry-run

rsync -avzh ./ /tmp/backups # copy files/folders from current working directory to backup directory

Memory

using free
man free
free --help
system memory
# m = show output in mebibytes
# h = show human-readable output

free -mh # available memory
ps
man ps
ps --help simple
what is using the memory
ps aux  | awk '{print $6/1024 " MB\t\t" $11}'  | sort -n # memory used by what