02 Dec 2015
This is the cheatsheet accompanying a workshop I gave recently for the BDSS IGERT trainees.
/in the beginning of a file means the root directory
./is the current directory
../is the parent directory
~/is the home directory
.are hidden files
$ pwd # Where am I? $ cd [dir] # Change directory $ pushd [dir] # Save current location and change to [dir] $ popd # Change back to directory stored with pushd
$ cp [origin] [target] # Copy $ mv [origin] [target] # Move $ mkdir [dir] # Make directory $ rm (-r) [file] # Remove [file] (-r for recursive for dirs) $ touch [file] # Create empty file
$ ls # List stuff in current directory $ cat [file] # Print [file] contents stdout $ head (-n) [file] # Show first (-n) lines of [file] $ tail (-n) [file] # Show the last (-n) lines of [file] $ less # Scroll thought the file
$ find [file/dir] # Find file or directory $ grep 'something' [file] # Find string in file
$ [command] | [programm] # Input the output of [command] to a [program] $ [command] > [file] # Create / overwrite [file] containing output of [command] $ [command] >> [file] # Append output of [command] to [file] $ [program] < [file] # Input content of [file] to [program]
If you want to make permanent changes to your command line you can do so in your
~/.bash_profile (mac) files.
Example: Shortcuts (aliases) for commands you often use. To create the shortcut
ls -alH put the following into your
alias ll='ls -alH'
nano [file] # Opens [file] in a simple text editor
cntrl-X in case you are confused.
vim [file] # Opens [file] in a more advanced editor sed # Stream editor sed '' [file] # print the contents of the file sed 's/[pattern]/[replacement]/' [file] # replace the first match of [pattern] with [replacement] sed 's/[pattern]/[replacement]/3' [file] # replace the third match sed 's/[pattern]/[replacement]/g' [file] # replace all matches