This is just a reference for some commands and techniques that are not used that much and easily forgotten. These should be pretty universally available on OSX, Unix, and Linux.
Command for keeping a queue of directories as you move around
pushd ~/Downloads
pushd ~/Documents
popd #this will take us back to ~/Downloads
which
- figure out where the command executable livesbasename
- gives you the last name in a path- Ex:
basename ~/Downloads/some_other_folder/rawr.txt
gives rawr.txt - This works for both directories and files
- Ex:
file
- gives you details information on files and directories
Compresses a single file
#Transforms rawr.txt => rawr.txt.gz
gzip rawr.txt
To decompress
gzip -d rawr.txt.gz
Compressing multiple files
zip someZip.zip list.txt of.txt files.txt
Unzipping
unzip someZip.zip
How we do dat?
# create, verbose, gzip, give files now
tar -cvzf archive.tar.gz list.txt of.txt files.txt
Untarring
#extract, verbose, gzip, give files now
tar -xvzf archive.tar.gz
sort filename.txt #sorts file to stdout
sort -u filename.txt #sort and make lines unique to stdout
cat filename.txt | sort #same as first example
sort filename.txt | unique #same as second example
echo "some stuff to copy" | pbcopy #copy some text to clipboard
pbpaste #paste what is in clipboard
expr is good for simple math operations. You do need to escape the parameters that have other meanings (* for example would be *)
expr 1 + 1
expr 1 \* 9
Just run the bc
command to open up a prompt for math.
uptime
- time since last restartdate
cal
- Show current calendar page for current month OR pass a Month Year to itcal July 1959
wc
- get word/line/character countwc -l
- get line count
history
- get last commands used