Brief%20introduction%20to%20UNIX - PowerPoint PPT Presentation

View by Category
About This Presentation



Unix commands - wildcards ... For special commands and interacting with Unix. Insert mode ... cmd run Unix command /string look for string ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 28
Provided by: AEM68


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Brief%20introduction%20to%20UNIX

Brief introduction to UNIX
  • A. Emerson
  • CINECA, High Performance Systems

  • Using Unix commands
  • command syntax
  • Getting Started
  • Getting help, identity, logging out
  • Files and directories
  • Making, renaming, deleting and copying.
  • Examining file contents.
  • Further file handling
  • File compression and making archives.
  • File permissions
  • Miscellaneous
  • Jobs and processes
  • Editing with vi.

Unix commands - usage
  • Unix commands are normally used in the form
  • ltcommandgt ltone or more optionsgt ltargumentsgt
  • Where the options are generally included with the
  • Example

ls -l a /usr/local/bin/files
Single letter options can usually be combined
ls -la /usr/local/bin/files
Unix commands - wildcards
  • If you want to do the command on multiple files
    you can use the wild card character.
  • Examples

mv .pl programs/perl/ ls data/
Be careful with rm (which does a delete) because
there is no way to undo it..
rm .
Getting Started
  • Command
  • man
  • Purpose
  • Gives you the manual page for a given command
  • Example

man pwd pwd(1)
NAME pwd -
print working directory name SYNOPSIS
pwd DESCRIPTION pwd prints the path name of
the working (current) directory. pwd is both an
explicit command (invoked as /usr/bin/pwd), as
well as a builtin
Getting Started
  • Command
  • id
  • Purpose
  • Tells you your username (!) and what group you
    belong to.
  • Example

id uid50083(aem0) gid30(cineca)
Getting Started
  • Command
  • exit (or ctrl-d)
  • Purpose
  • Logs you out from the system
  • Example

Files and directories
  • Command
  • mkdir
  • Purpose
  • Makes a directory
  • Common options
  • -p
  • creates all the sub-directories in a path if they
    dont exist
  • Examples

mkdir perl-programs mkdir p 2003/jan/data
Files and directories
  • Command
  • cd
  • Purpose
  • Changes directory. With no arguments changes to
    home directory.
  • Examples

cd my_data cd /usr/local/bin/programs cd
Files and directories
  • Command
  • mv
  • Purpose
  • Moves or renames a file or directory
  • Common options
  • -i
  • Asks confirmation before overwriting another file
    or directory
  • Examples

mv perl-programs/jan mv blast.out
blast.out.bak mv .seq sequence-dir
Files and directories
  • Command
  • rm
  • Purpose
  • Deletes or renames a file
  • Common options
  • -i
  • Asks confirmation first
  • -r
  • deletes all sub-directories of a directory (VERY
  • Examples

rm .old rm i File
Remove ? (yes/no)no
Files and directories
  • Command
  • cp
  • Purpose
  • Makes a copy of a file or directory
  • Common options
  • -i
  • Asks confirmation first if overwriting another
  • -r
  • copies all files of all sub-directories of a
  • Examples

cp program.f90 program.f90.old cp
blastdir/.out .
. means the current directory
Files and directories
  • Command
  • ls
  • Purpose
  • Lists files and directories
  • Common options
  • -t
  • sort by modification time
  • -l
  • long format, gives all details of the file (very
  • -a
  • shows file beginning with . (not visible with
    just ls)

ls lt total 136 -rw-r--r-- 1 bioinf00
cineca 15678 May 20 2002 test.out -rw-r--r--
1 bioinf00 cineca 2939 May 20 2002
test.bas -rw-r--r-- 1 bioinf00 cineca
53541 May 20 2002 prova.bas
size in bytes
Files and directories
  • Command
  • more (traditional Unix), less (Linux)
  • Purpose
  • Allows you to view the contents of a file.

Files and directories
  • Command
  • head, tail
  • Purpose
  • Allows you to view the first lines of a file
    (head) or the last lines of a file (tail)
  • Common options
  • n
  • The number of lines to show. The default is 10.

head -5 seq.fasta gtTHC479329 SWI/SNF complex
155 KDa subunitSWI/SNF complex 155 KDa subunit
Further file handling
  • Command
  • compress (standard UNIX), gzip (GNU version
  • uncompress, gunzip
  • Purpose
  • Compresses text files to save disk space
  • Common options
  • -v
  • verbose, gives compression ratio

ls -l MAG500 -rw-r--r-- 1 aem0 cineca
3249198 Jan 29 2002 MAG500 gzip v MAG500 gzip
-v MAG500 MAG500 70.1 -- replaced with
MAG500.gz ls l MAG500.gz -rw-r--r-- 1
aem0 cineca 971325 Jan 29 2002 MAG500.gz
Making archives
  • Command
  • tar
  • Purpose
  • Creates an archive of files and directories. Many
    Unix software packages consist of a tree of
    sub-directories which can be difficult to
    transfer between different machines. tar can be
    used to create a single archive file which when
    untarred re-creates the original directory
  • Common options
  • -c
  • creates an archive
  • -f
  • uses a file for the archive (you can also use
    CDs,tapes, etc)
  • -x
  • extracts file from an archive
  • -v
  • verbose tells the user what tar is doing

Creating archives - Example
  • ls -F
  • blast/
  • tar -cvf blast.tar blast
  • blast/
  • blast/results/
  • blast/input/
  • blast/input/input1.dat
  • blast/input/input2.dat
  • blast/input/input3.dat
  • blast/data/
  • blast/data/blast1.out
  • blast/data/blast2.out
  • blast/data/blast3.out
  • blast/data/blast4.out
  • blast/data/blast5.out
  • blast/data/data-old/blast-old.out
  • blast/data/blast0.out

directory to archive
name of archive file
Extracting archives - Example
  • cd new-dir
  • tar -xvf blast.tar
  • blast/
  • blast/results/
  • blast/input/
  • blast/input/input1.dat
  • blast/input/input2.dat
  • blast/input/input3.dat
  • blast/data/
  • blast/data/blast1.out
  • blast/data/blast2.out
  • blast/data/blast3.out
  • blast/data/blast4.out
  • blast/data/blast5.out
  • blast/data/data-old/
  • blast/data/blast0.out

Often gzip is combined with tar archives to give
files like blast.tar.gz or blast.tgz Sometimes
called tarballs.
File permissions
  • ls -l blast.tar
  • -rwxr--r-- 1 aem0 cineca 30720 Mar 13 1047

File permissions
r - read access w - write access (for a directory
means files can be deleted in the directory, even
if the files dont have write access) x -
executable (searchable for a directory) -
permission not set
File permissions
  • Command
  • chmod
  • Purpose
  • Changes the permissions of a file or directory.
    Only the owner of a file, or root, can change the
  • Common options
  • -R
  • changes all the permissions in a directory,
    including sub-directories

chmod ux chmod gw,o-w seq.dat
chmod r .fasta chmod 777 .prog
make file executable for owner write access for
group, no write for others add read access for
all octal notation, here rwx for all
Running programs
  • To run a program which is an executable file,
    just type the name of the file
However, like this the terminal cannot be used
until the program finishes. Add an to return
control to the user (running in the background) 1 31705
Now the user can do other things, logout and go
home, etc. Note that Unix assigns a job number
and a process number to the running program.
Running programs
  • To see what programs are running you can use the
    jobs command

jobs 1 Running
But this only applies to programs run during the
same session (the same shell). To see all
programs (processes) being run use the ps command
ps u aem0 31705 pts/3 000040 29775 pts/3 000000 tcsh 31738
pts/3 000000 ps
Editing with vi
  • vi is the standard Unix text editor and is
    present on every Unix system.

  • vi has 3 modes
  • Command mode
  • For manipulating and moving through the the text
  • Line mode
  • For special commands and interacting with Unix.
  • Insert mode
  • For entering text, i.e. writing programs,
    entering data, etc.

Editing with vi
  • Command mode the usual and initial mode (i.e.
    when starting vi)
  • Commands include
  • ???? arrow keys move the cursor
  • hjkl same as arrow keys
  • x delete a character
  • dw delete a word
  • dd delete a line
  • 3dd delete 3 lines
  • u undo previous change
  • ZZ exit vi, saving changes

Editing with vi
  • Line mode entered by typing , / , ? or ! .
  • Commands include
  • q! save file, discarding
  • q quit
  • e filename edit a new file
  • w filename write with new filename
  • wq write file and quit
  • !cmd run Unix command
  • /string look for string

RETURN executes command and returns to command
Editing with vi
  • Insert mode entered by typing any of the
    following in command mode
  • a append after cursor
  • i insert before cursor
  • o open line below
  • O open line above
  • Rtext replace with text

to exit insert mode, and return to command mode,
type ltESCgt.