using_unix
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| using_unix [2017/05/12 12:07] – cgeb2001 | using_unix [2021/10/27 14:04] (current) – 24.222.40.124 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== Basic UNIX commands ====== |
| - | Some general comments | + | Some general comments |
| These commands are issued on the command line and should work on a MAC or in a UNIX environment like perun. | These commands are issued on the command line and should work on a MAC or in a UNIX environment like perun. | ||
| Do not have spaces in the names of files or directories. If you want to separate portions of the name to make it more obvious use _ or . or – like so lord_of_the_rings.txt | Do not have spaces in the names of files or directories. If you want to separate portions of the name to make it more obvious use _ or . or – like so lord_of_the_rings.txt | ||
| Line 13: | Line 13: | ||
| - | •ls --- lists your files
ls -l --- lists your files in 'long format', | + | •**ls** --- lists your files
ls -l --- lists your files in 'long format', |
| - | •cd dirname --- change directory. You basically ' | + | •**cd dirname** --- change directory. You basically ' |
| - | •more filename --- shows the first part of a file - as much as will fit on one screen. Just hit the space bar to see more or q to quit | + | •**more filename** --- shows the first part of a file - as much as will fit on one screen. Just hit the space bar to see more or q to quit |
| - | •less filename -- similar to more but has more sophisticated search and navigation abilities. Once you are within the less window you can navigate or search with certain keys, Eg. b for previous page, g for first line, G for last line, /searchtext to find a string, etc (see man page man less). | + | •**less filename** -- similar to more but has more sophisticated search and navigation abilities. Once you are within the less window you can navigate or search with certain keys, Eg. b for previous page, g for first line, G for last line, /searchtext to find a string, etc (see man page man less). |
| - | •cat filename ---displays the entire content of a file to the screen | + | •**cat filename** ---displays the entire content of a file to the screen |
| - | •mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a different directory (see below) | + | •**mv filename1 filename2** --- moves a file (i.e. gives it a different name, or moves it into a different directory (see below) |
| - | •cp filename1 filename2 --- copies a file | + | •**cp filename1 filename2** --- copies a file |
| - | •rm filename --- removes a file. It is wise to use the option rm -i, which will ask you for confirmation before actually deleting anything. You can make this your default by making an alias in your .cshrc file. | + | •**rm filename** --- removes a file. It is wise to use the option rm -i, which will ask you for confirmation before actually deleting anything. You can make this your default by making an alias in your .cshrc file. |
| - | •diff filename1 filename2 --- compares files, and shows where they differ | + | •**diff filename1 filename2** --- compares files, and shows where they differ |
| - | •wc filename --- tells you how many lines, words, and characters there are in a file | + | •**wc filename** --- tells you how many lines, words, and characters there are in a file |
| - | •chmod options filename --- lets you change the read, write, and execute permissions on your files. The default is that only you can look at them and change them, but you may sometimes want to change these permissions. | + | •**chmod** options |
| - | •gzip filename --- compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose but gzip usually gives the highest compression rate. Gzip produces files with the ending ' | + | •**gzip filename** --- compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose but gzip usually gives the highest compression rate. Gzip produces files with the ending ' |
| - | •gunzip filename --- uncompresses files compressed by gzip. | + | •**gunzip filename** --- uncompresses files compressed by gzip. |
| - | •mkdir dirname --- make a new directory | + | •**mkdir dirname** --- make a new directory |
| - | •pwd --- tells you where you currently are. | + | •**pwd** --- tells you where you currently are. |
| - | •man command --- will show the manual entry for the unix command. For example, man ls will show all the options for the common unix command ls. | + | •**man command** --- will show the manual entry for the unix command. For example, man ls will show all the options for the common unix command ls. |
| - | •* is the UNIX symbol for global and can be with many of the other commands. Eg to list all the files in a directory that start with the character b ls b*. To list all the files that start with g and end in fasta ls g*fasta. To copy all the files that end in blastx to the directory above the current one cp *blastx .. . To change the permissions on all fasta files to rw, rw, r chmod 664 *fasta. Remove all the files that start with t and end in pid rm t*pid | + | •***** is the UNIX symbol for global and can be with many of the other commands. Eg to list all the files in a directory that start with the character b ls b*. To list all the files that start with g and end in fasta ls g*fasta. To copy all the files that end in blastx to the directory above the current one cp *blastx .. . To change the permissions on all fasta files to rw, rw, r chmod 664 *fasta. Remove all the files that start with t and end in pid rm t*pid |
| Line 47: | Line 47: | ||
| More advanced UNIX commands | More advanced UNIX commands | ||
| - | grep searchtext filename --- will search a file line by line for the presence of a searchtext. For example, grep frodo lord_of_the_rings.txt will search for the text frodo in the file lord_of_the_rings. If your search text includes spaces or special characters you need to double quote it – grep “the one ring" lord_of_the_rings. One of the options for grep is -v which means find all the lines that DO NOT contain the string and output them to the screen (or file if you redirect the output (see below)). Another useful grep option is -i which means ignore the case of the searchtext, so grep -i foo file will find lines that contain FOO, foo, FoO, fOO, FOo, fOo in the file file. | + | **grep searchtext filename** --- will search a file line by line for the presence of a searchtext. For example, grep frodo lord_of_the_rings.txt will search for the text frodo in the file lord_of_the_rings. If your search text includes spaces or special characters you need to double quote it – grep “the one ring" lord_of_the_rings. One of the options for grep is -v which means find all the lines that DO NOT contain the string and output them to the screen (or file if you redirect the output (see below)). Another useful grep option is -i which means ignore the case of the searchtext, so grep -i foo file will find lines that contain FOO, foo, FoO, fOO, FOo, fOo in the file file. |
| - | ssh -l username url_of_system. Eg. ssh -l curtisba perun.biochem.dal.ca. | + | **ssh -l username url_of_system.** Eg. ssh -l curtisba perun.biochem.dal.ca. |
| - | scp - secure copy protocol. Allows you to securely copy files from one computer system to another. To copy a file from you local computer to a remote computer | + | **scp** - secure copy protocol. Allows you to securely copy files from one computer system to another. To copy a file from you local computer to a remote computer |
| scp name_of_file username@remote_computer_system:/ | scp name_of_file username@remote_computer_system:/ | ||
| eg. scp myfile curtisba@perun.biochem.dal.ca:/ | eg. scp myfile curtisba@perun.biochem.dal.ca:/ | ||
| Line 61: | Line 61: | ||
| You will be asked for the password for the remote computer system. | You will be asked for the password for the remote computer system. | ||
| - | sort -will sort the contents of a file and print it to the screen (or file if redirected). | + | **sort** -will sort the contents of a file and print it to the screen (or file if redirected). |
| Lines are sorted based on the first character in the first column. You can sort by other columns (or fields) with columns (fields) separated by blank space. Eg to sort a file that contains by the numbers in the second column | Lines are sorted based on the first character in the first column. You can sort by other columns (or fields) with columns (fields) separated by blank space. Eg to sort a file that contains by the numbers in the second column | ||
| bob 310 | bob 310 | ||
| Line 69: | Line 69: | ||
| To sort in reverse numerically sort -nrk2 file_name | To sort in reverse numerically sort -nrk2 file_name | ||
| - | > -unix for redirect output. Normally the results of a unix command like ls will output to the screen. However, you can redirect the results to a file. Eg. ls -l > what_files_exist | + | **>** -unix for redirect output. Normally the results of a unix command like ls will output to the screen. However, you can redirect the results to a file. Eg. ls -l > what_files_exist |
| - | | -unix for piping results | + | **|** -unix for piping results |
| - | cut -cut up lines of a file by columns or a single character delimiter. Eg to cut the 3 lines in the file money by the comma and print out what type of metal cut -d"," | + | **cut** -cut up lines of a file by columns or a single character delimiter. Eg to cut the 3 lines in the file money by the comma and print out what type of metal cut -d"," |
| 30,gold | 30,gold | ||
| 50,silver | 50,silver | ||
using_unix.1494601647.txt.gz · Last modified: by cgeb2001
