Unix+Commands

Below you can find some useful UNIX commands for exploring your next-gen data. You can find a more in depth UNIX tutorial **here**.

Clicking on the command will take you to its man page.

flat

=Getting Started= **clear** or Ctrl-l: clear screen

up and down to navigate through previously used commands

Ctrl-r let's you search the command history of your shell code format="bash" (reverse-i-search)`': code use Tab to complete names of files and directories
 * 1) Ctrl-r opens this query tool
 * 2) start typing part of the command you issued a while back and it will show
 * 3) up in the query tool -- I think the history gets deleted after logging out

**exit** or Ctrl-d: log out of shell

**poweroff** : one of several ways to shut down a computer from the shell prompt

=Man Pages= **[|man]** : displays the manual for the command you are interested in To search a man page type / search term. To scroll through your search hits use n. To exit type q. code format="bash" man man man ssh code
 * 1) displays the man-page of man ;-)
 * 1) displays man-page of the ssh client

=Navigating the File System=

Here is a nice introduction to the Unix file system. Reading **this** should clarify greatly how the file system on a typical Unix system looks like (Mac users may have to make some adjustments).

**cd** : move between directories cd .. will take you back one directory in your path. You can use multiple .. arguments. For instance, if you are in /home/cartwrightlab/desktop and would like to get back to /home use cd ../.. code format="bash" pwd /home/cartwrightlab/desktop cd ../.. pwd /home code **cp** : copy files code format="bash" cp dir1/foo.txt dir2/ cp -r dir1/ dir2/ code **ls** : list the contents in a directory code format="bash" ls -l ls -a ls -lh ls -lha code **mkdir** : make a new directory code format="bash" mkdir foo code **mv** : move file or rename file code format="bash" mv foo.txt newdirectory/foo.txt mv foo.txt cat.txt
 * 1) copies foo.txt from dir1 to dir2
 * 1) copies dir1 and its contents to dir2
 * 1) list files with detailed info
 * 1) show all files including hidden files
 * 1) show a list of files including their sizes in human readable form
 * 1) well...
 * 1) makes directory foo
 * 1) moves foo.txt into newdirectory
 * 1) renames foo.txt to cat.txt

code **rename** : rename multiple files according to a **[|regular expression]** indicating a rule for renaming code format="bash" rename 's/\.txt$/\.fasta/' * code **rm** : remove files or directories code format="bash" rm foo.txt rm -r foo code **find** : search for files -- here's a great tutorial for harnessing the full power of find code format="bash" find /home/user -name pattern code **df** : report file system disk space usage code format="bash" df -h code **du** : estimate file space usage / directory size code format="bash" du -h /home/user code **pwd** : print the path of the directory you are in
 * 1) changes the file extension for all files (*) in a directory from .txt to .fasta
 * 1) delete foo.txt
 * 1) delete the directory foo and its contents
 * 1) searches for files in /home/user that match the pattern
 * 1) reports the size, used space, and available
 * 2) space of every device available on the system
 * 3) useful if you want to know how much space you
 * 4) have left to work with -- Can I really extract this tarball?!
 * 1) have left to work with -- Can I really extract this tarball?!
 * 1) estimates the size of the user's home directory
 * 2) and the contained directories
 * 3) can be used to estimate the size of any directory
 * 1) can be used to estimate the size of any directory

Note: All commands can be issued on the files you would like to work with from the directory they are in. They can also be issued from another directory. In this case use the path for your files relative to your working directory. Ex: Your file (file_1.txt) is in the directory home/cartwrightlab/Documents/TruSeq/ you are working in home/cartwrightlab/Documents and want to rename file_1 without leaving your current directory. The command would look like this: code format="bash" mv TruSeq/file_1.txt TruSeq/newfile_1.txt code Notice that the entire path is not necessary since TruSeq is a subdirectory of Documents.

=Mounting= **mount** : mount a device

A device can be a hard-drive. These are generally found in the directory /dev. The exact name differs from system to system. Let's say /dev/sdb1 is the USB drive you just plugged into your computer. You would mount it to the directory /mnt by doing the following: code format="bash" mount /dev/sdb1 /mnt code **umount** : unmount file system

To unmount the drive from above example do this. The process may take a while to finish, as there may be data that has to be written to the device first! code format="bash" umount /mnt code

=Working With Text Files= For additional information on working with text files see Editing text files.

**less** : print file contents to standard out; you can search patterns in less in the same way as the man pages code format="bash" less foo.txt code **head** : print the first 10 lines of file to standard out code format="bash" head foo.txt code to print the first 5 lines: code format="bash" head -n 5 foo.txt code **tail** : print the last 10 lines of file to standard out code format="bash" tail foo.txt code to print the last 5 lines: code format="bash" tail -n 5 foo.txt code **nano** : text editor that is very easy to use If all you would like to do is look at a file use less instead of nano. Nano is not ideal for editing very large files, see the editing text files post. code format="bash" nano foo.txt code **cat**: concatenate files and print to standard out code format="bash" cat foo.txt cat foo1.txt foo2.txt foo3.txt cat *.txt code **grep** : pattern search within file -- returns the lines in a file that contain the search pattern code format="bash" grep pattern foo.txt cat foo.txt | grep pattern cat *.txt | grep pattern code **uniq** : report or omit repeated lines code format="bash" cat foo.txt | uniq > foo-filtered.txt code
 * 1) dump foo.txt to standard out (the screen)
 * 1) dump foo1.txt through foo3.txt to standard out
 * 1) dump all text files in current directory to standard out
 * 1) Simple pattern matching and full-fledged support for regular expressions.
 * 2) There are tons of how-to's on the web.
 * 1) basic usage to look for pattern in file foo.txt
 * 1) same as above using cat and a pipe (see I/O Redirection)
 * 1) search for a pattern in all text files in the present directory
 * 1) only retain uniq lines in foo.txt and save these in
 * 2) foo-filtered.txt
 * 3) think about filtering out duplicate sequences etc.
 * 1) think about filtering out duplicate sequences etc.
 * vi **: powerful text editor with steep learning curve. Why would you learn the basics of vi? Because it's installed on pretty much any Unix(-like) computer you will encounter. Cheat sheet for reference.

code format="bash" wc -l foo.txt cat foo.txt | wc -l code
 * wc **: newline, word, and byte counts for each file
 * 1) counts the number of lines in foo.txt
 * 1) same as above using a pipe (see I/O Redirection)