Skip to content

Instantly share code, notes, and snippets.

@chaseconey
Created July 17, 2013 03:27
Show Gist options
  • Save chaseconey/6017456 to your computer and use it in GitHub Desktop.
Save chaseconey/6017456 to your computer and use it in GitHub Desktop.
Some lesser known commands in *nix that I should totally use more....

Lesser Known Terminal Commands

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.

pushd and popd

Command for keeping a queue of directories as you move around

	pushd ~/Downloads
	pushd ~/Documents
	popd #this will take us back to ~/Downloads

Meta Commands

  • which - figure out where the command executable lives
  • basename - 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
  • file - gives you details information on files and directories

Compression and Zipping

gzip

Compresses a single file

	#Transforms rawr.txt => rawr.txt.gz
	gzip rawr.txt

To decompress

	gzip -d rawr.txt.gz

zip

Compressing multiple files

	zip someZip.zip list.txt of.txt files.txt

Unzipping

	unzip someZip.zip

tar

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

Sorting

	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

Working With Clipboard (OSX)

	echo "some stuff to copy" | pbcopy #copy some text to clipboard
	pbpaste #paste what is in clipboard

Math on the Terminal

expr

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

bc

Just run the bc command to open up a prompt for math.

Random Commands

  • uptime - time since last restart
  • date
  • cal - Show current calendar page for current month OR pass a Month Year to it
    • cal July 1959
  • wc - get word/line/character count
    • wc -l - get line count
  • history - get last commands used
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment