[Linux Command Line](https://docs.google.com/file/d/1s4_1qturE3YqK1pzltsqvn_pXWVkAUtH2rjP8XlVkmIJ_8piYWxMEhHlAwfXEjYnj97E7iDWq_ivyCWt/edit?usp=sharing) ======================== Intro to essential Linux commands, e.g.: - `date` shows current date and time - `time` useful for benchmarking (there's also GNU time, more sophisticated, can show max memory consumption: `/usr/bin/time`) - `rsync` is generally a better alternative to scp - `ln -s` for creating symbolic links (having a file in two places at once via a pointer) - `cut` commonly used for selecting fields (default is to delimit by tab) - `sort` for sorting, has many options - `uniq` for unique data - `wc` for many types of counts, e.g. words, chars, lines, longest line (for pre-allocating a buffer) - `split` splits files, handy for parallel processing jobs - `head` shows the beginning of a file (defaults to first 10 lines) - `tail` shows the ending of a file (defaults to last 10 lines) can also be used for starting at a certain line, e.g. to start at 4th line: `tail -n+4` - `paste` combines columns (commonly used with `cut`) - `wget` & `curl` for grabbing online resources; `curl` is handy for APIs - `nl` prepend line numbers - `xargs` execute commands from STDIN, useful when dealing with a huge number of files (use `-P` to enable multiple processors) - `find` non-indexed search, e.g. `find /etc | nl` - `locate` indexed search works out of the box on Ubuntu, but on MacOS you need to do ``` sudo apt-get install -y locate; sudo updatedb; locate fstab ``` - `grep` print lines matching a pattern - `sed` stream editor for filtering and transforming text, useful for search and replace - [one liners](http://www.catonmat.net/blog/wp-content/uploads/2008/09/sed1line.txt) - `awk` pattern scanning and text processing language, useful for tab-delimited data - [one liners](http://www.pement.org/awk/awk1line.txt) [Taco Bell programming (i.e. combining CLI tools via pipes) is one of the steps on the path to Unix Zen](http://t.co/icmrEuNkNq). #### [Bash keyboard shortcuts](http://www.howtogeek.com/howto/ubuntu/keyboard-shortcuts-for-bash-command-shell-for-ubuntu-debian-suse-redhat-linux-etc/) Should also work in fish shell. - CTRL + l: clear screen - CTRL + u: clear text before cursor - CTRL + c: kill current process - CTRL + d: exit current shell - CTRL + z: puts the current process in the background, restore with `fg` You can also use &. E.g. `sleep 10 &` - CTRL + w: clear word before cursor - TAB: auto-complete