| Command | Description |
|---|---|
| pwd | prints working directory (prints to screen, ie displays the full path, or your location on the filesystem) |
| ls | lists contents of current directory |
| ls -l | lists contents of current directory with extra details |
| ls /home/user/*.txt | lists all files in /home/user ending in .txt |
| cd | change directory to your home directory |
| cd ~ | change directory to your home directory |
| cd - | change directory to the last directory you were in before changing to wherever you are now |
| mkdir mydir | makes a directory called mydir |
| mkdir -p mydir/mydir2/mydir3 | makes the directory mydir3 and all parent directories if they don't exist |
| rmdir mydir | removes directory called mydir. mydir must be empty |
| touch myfile | creates a file called myfile. updates the timestamp on the file if it already exists, without modifying its contents |
| cp myfile myfile2 | copies myfile to myfile2. if myfile2 exists, this will overwrite it!*** |
| rm myfile | removes file called myfile*** |
| rm -f myfile | removes myfile without asking you for confirmation. useful if using wildcards to remove files *** |
| cp -r dir newdir | copies the whole directory dir to newdir. -r must be specified to copy directory contents recursively |
| rm -rf mydir | this will delete directory mydir along with all its content without asking you for confirmation! *** |
| vi | opens a text editor. `i` to enter insert mode (Note bottom shows `--INSERT--`). `esc` to exit insert mode. `:` to enter command mode and `q!` to quit, `wq` to write and quit. |
| vi new.txt | opens vi editing a file called new.txt |
| cat new.txt | displays the contents of new.txt |
| less new.txt | displays the contents of new.txt screen by screen. spacebar to pagedown, q to quit |
| head new.txt | displays first 10 lines of new.txt |
| tail new.txt | displays last 10 lines of new.txt |
| tail -f new.txt | displays the contents of a file as it grows, starting with the last 10 lines. `CTRL-c` to quit. |
| mv myfile newlocdir | moves myfile into the destination directory newlocdir |
| mv myfile newname | renames file to newname. if a file called newname exists, this will overwrite it! |
| mv dir subdir | moves the directory called dir to the directory called subdir |
| mv dir newdirname | renames directory dir to newdirname |
| file new.txt | determine file type of the file names new.txt |
| top | displays all the processes running on the machine, and shows available resources |
| ps | list processes you have running |
| ps -U username | list processes a specific user is running |
| kill 5106 | kill process indentified as 5106 from the `ps` commands above *** |
| du -h --max-depth=1 | run this in your home directory to see how much space you are using. |
| df -h | display all mounted volumes with mount points, total used, and size in human readable format |
| ssh servername | goes to a different server |
| grep pattern files | searches for the pattern in files, and displays lines in those files matching the pattern |
| anycommand > myfile | redirects the output of anycommand writing it to a file called myfile *** |
| anycommand >> myfile | appends the output of anycommand to a file called myfile |
| command1 | command2 | pipes the output of command1 to command2. the pipe is usually shift-backslash key |
| date | displays the date and time |
| tar -xzvf archive.tgz | this will extract the contents of the archive called archive.tgz. kind of like unzipping a zipfile. *** |
| tar -czvf dir.tgz dir | this creates a compressed archive called dir.tgz that contains all the files and directory structure of dir |
| find ~/sandbox -name bad* | find a file where the name starts with bad and is in the sandbox folder in your home directory |
| screen -S myScreenName | start a screen session named myScreenName. Use `CTRL-a CTRL-d` to detach. Use `CTRL-a Esc` to enable mouse wheel scrolling and `Esc` again to exit mouse wheel mode |
| screen -ls | list all open screen sessions |
| screen -r myScreenName | recover a screen session named myScreenName |
| tmux new -s myScreenName | start a tmux session named myScreenName. Use `CTRL-b d` to detach |
| tmux ls | list all open tmux sessions |
| tmux a -t myScreenName | recover a tmux session named myScreenName |
| man anycommand | gives you help on anycommand |
| CTRL-c | kills whatever process you're currently doing |
| CTRL-insert | copies selected text to the windows clipboard (n.b. see above, `CTRL-c` will kill whatever you're doing) |
| SHIFT-insert | pastes clipboard contents to terminal |
| <highlighting text with mouse> | copies highlighted text to your clipboard |
| CTRL-v | While connected to OOD terminal, this will paste clipboard to terminal |
| _Note:__ | |
| ** = use with extreme caution! | ou can easily delete or overwrite important files with these. |
35 Linux/Unix Command Line Cheat Sheet
Adapted from GettingGeneticsDone.blogspot.com
35.0.0.1 Absolute vs relative paths.
Let’s say you are here: /home/turnersd/scripts/. If you wanted to go to /home/turnersd/, you could type: cd /home/turnersd/. Or you could use a relative path. cd ..(two periods) will take you one directory “up” to the parent directory of the current directory.
. (a single period) means the current directory
.. (two periods) means the parent directory
~ means your home directory
| mv myfile .. | moves myfile to the parent directory |
| cp myfile ../newname | copies myfile to the parent directory and names the copy newname |
| cp /home/turnersd/scripts/bstrap.pl . | copies bstrap.pl to "." i.e. to dot, or the current directory you're in |
| cp myfile ~/subdir/newname | copies myfile to subdir in your home, naming the copy newname |
| less ../../../myfile | displays screen by screen the content of myfile, which exists 3 directories "up" |
| \* | matches any character. example: ls *.pl lists any file ending with .pl ; rm dataset* will remove all files beginning with "dataset" |
| [xyz] | matches any character in the brackets (x, y, or z). example: cat do[or]m.txt will display the contents of either doom.txt or dorm.txt |