Aritalab:Lecture/NGS/Unix commands

From Metabolomics.JP
< Aritalab:Lecture | NGS(Difference between revisions)
Jump to: navigation, search
(Created page with "==Useful Unix Commands== When you open a terminal, the background "shell" program is already running. It prints out a prompt ">" and parses and executes your input. Famous on...")
 
m (Path and the Current Directory)
Line 42: Line 42:
  
 
; cd ''directory''
 
; cd ''directory''
: When you input commands, the shell executes them from the position you are in. This position is called the current directory, denoted by ' . ' in your commands. You can specify the directory location by .. (one-step down), / (directory), or . (current position). Your home directory is specified as "~/".
+
: When you input commands, the shell executes them from the position you are in. This position is called the current directory, denoted by ' . '. You can check the value of '.' by typing 'pwd' (print working directory).
 +
 
 +
The directory location can be also changed by .. (one-step down), / (root directory), or . (current position). Your home directory is specified as "~/".
 +
 
 +
; mkdir ''filename''
 +
: Creating a new directory. Removing a directory uses the 'rmdir' command.
  
 
At the unix root, you will find the following directories.
 
At the unix root, you will find the following directories.

Revision as of 14:52, 9 November 2015

Contents

Useful Unix Commands

When you open a terminal, the background "shell" program is already running. It prints out a prompt ">" and parses and executes your input. Famous ones are "bash" (Bourne-again shell) and "tcsh". The shell program offers over 200 commands.

All data in UNIX are organized in a file/directory tree. The entire tree is called the UNIX filesystem.

File operations

ls -l
Listing all filenames in the current directory. Each line consists of (1) file type and its access permission, (2) number of memory blocks, (3) file owner and group, (4) file size (in bytes), (5) last update time, and (6) file name. To list selected files only, you can use an astarisk * as a don't-care symbol.
cat filename
Listing file contents. Option -b attaches line numbers. To see long files, use 'cat filename | ls'.
cp -i from to 
Duplicating a file
mv -i from to 
Renaming a file
rm -i filename 
Deleting a file
We often mistake the order of from and to files in these commands. Therefore, make sure to use the -i option. These commands are destructive and there is no way to undo the operation.
wc filename
Counting the line number, word number and file bytes.

Exercise

File Ownership

When you check files by 'ls -l', you see file permissions. The permission consists of one character showing either it is a file (-) or directory (d), and the three groups of three characters 'rwx'.

Each letter of the three 'rwx' represents read (r), write (w), and execute (x) permission. The first block indicates the permission for the file owner, second block indicates, for group members to which the file belongs, and the last block, for everybody else.

To change permissions, you use the command 'chmod' and a binary notation for the three letter block 'rwx'. For example, the number 6 indicates 'rw-' (read or write permission), the number 4 indicates 'r--' (read only), 7 indicates 'rwx' (all ok). Permissions for the three user types are specified by three consecutive numbers of 0-7.

chmod 644 'filename'
Changing the file permission to read only to others. 'chmod 600 filename' makes your file personal.

Path and the Current Directory

cd directory
When you input commands, the shell executes them from the position you are in. This position is called the current directory, denoted by ' . '. You can check the value of '.' by typing 'pwd' (print working directory).

The directory location can be also changed by .. (one-step down), / (root directory), or . (current position). Your home directory is specified as "~/".

mkdir filename
Creating a new directory. Removing a directory uses the 'rmdir' command.

At the unix root, you will find the following directories.

/bin /sbin /usr /etc

Bin and sbin are used to store executable files and user files are located in usr. When you type any command, the shell looks for a binary executable file in bin or sbin locations. The places to search is defined as the PATH variable.

Please type 'echo $PATH' to show the PATH value. (The dollar symbol indicates the value of a defined variable and the echo command outputs the input value directly.) You can add a new location to this variable by 'PATH=/usr/bin:$PATH'. In typing this command, do not insert a space such as "PATH = /usr/bin : $PATH'. Space character does matter. OTher important variables include: HOME (home directory), LANG (language switch), and DISPLAY (display identifier).

Text Operation

grep pattern file(s)
Searching a regular expression in files. Inputs can be given by other commands through a pipe '|'. Please see its usage by typing 'grep --help'. To fully exploit its power, you need to learn the regular expression.
sort filename
Sorting lines of text alphabetically. For a numeric sort, use the '-n' option. To sort by the 2nd or 3rd column, ignore the first N fields by specifying '+N'.
more filename
 
less filename
Showing text information page by page. 'More' command can move forward only but 'less' can move backward too. Check their functions by 'more --help', for example.
Personal tools
Namespaces

Variants
Actions
Navigation
metabolites
Toolbox