Basic LinuxUNIX Commands The symbol of Linux Logging

Basic Linux/UNIX Commands The symbol of Linux

Logging in Unix doesn’t really care where you log in from, though some system administrators might. You must have a username id) topermission useyou a Havein graphical output(login sent anywhere Log from anywhere you have unix system have permission Every. This useridentifies is a member or moreso groups youof to one the system it can of users. manage your work properly. This helps the system manage different types of user properly.

Logging in Connect to the unix machine using a suitable program on your local machine. Connecting to embnet. org Telnet Connected. Xterm Secure Shell You may get some messages here Login: username Kermit Password: from the system administrator. Other terminal emulators Welcome to the Bioinformatics Course. unix is case sensitive. username not doesn’t show on the is screen The system will be unavailable on anything friday the same as your Username or USERNAME as you type password. afternoon for maintenance. You have new mail. username@linus ~>

The shell or command line Several different shells but they behave more or less 1. The Prompt. the same username@linus ~> your username machine your present The prompt can the be customised to location look how you wish are logged in to

The shell or command line 2. Commands username@linus ~> ls -ald *. txt The shell breaks the command up into individual words The first word is a command The subsequent words form a listwords of arguments By default the boundary between is a space. to get the command To shell to treat a phrase that includes spaces as a arguments with -like are this: options single word, beginning put it in quotes 'my or "my word". * is aword' special character. It means ‘any group of Options control how the program runs. characters’ (including none). The shell finds all the '-a -l that -d'match is equivalent to '-ald' and adds filenames anything. txt them to the list of arguments

More Special Characters * ? " ' & | > `` $ Any group of characters Anydelineation single character. word including none. < ; Pipe. theathe Cause Redirect process commands to run input. in the output, eg. background a file to ainstead file Passfrom theeg. output of the keyboard. command on the Backslash. Semicolon Backticks (not '). left as the String or Dollar input to command the Change Seperate Take commands output meaning of the typed ofon in Treat thethe next word as athe right. next together. command character. as write an argument variable and out its value Some special characters can lose their special meaning if they are inside quotes.

Organization "Everything is a file" • An ordinary file contains data. • A directory contains other files. • A link is a file that is a shortcut to another file. The dataare could be an image, a document, • There many other types of file. a set of instructions (a program) or anyonfixed This is also known as a folder someinformation. systems. A directory contain directories (which are Files cancan have moreother than one name, and be in then as about sub-directories. ) different at the same time You don't needknown todirectories worry these. You probably won't come across one in normal use of the system.

Organization of the file system / bin usr home etc The top of the file system is the directory '/', commonly known as the rootthe directory Several subdirectories under root directory username An Anyexample file in the users file home system can directory be uniquely with identified a subdirectory by and describing severalthe files path to it from the root directory. /home/username/prot Another subdirectory. prot letter project seq 4 seq 3 seq 2 seq 1

Organization of the file system / bin usr Any process is located somewhere in the filesystem The command 'pwd' will tell you where. username@linus ~> pwd /home/username home etc username prot letter project seq 4 seq 3 seq 2 seq 1 '~' is a unix shortcut meaning 'your home directory'

Looking at the file system / bin 'ls' lists the files in a directory or directories usr home etc username prot letter project There areanmany optionslstolists ls that allow Without argument, all the filesyou thatto select start and control it presents. don't with. inthe theinformation current directory seq 4 seq 3 seq 2 seq 1 username@linus ~> ls ls project: letter project seq 1 seq 2 seq 3 seq 4

Basic shell commands - ls • ls: list existing files in current directory – Short listing: ls – List all files: ls –a – Detailed long list: ls –l – All of the above: ls -al

Moving around the file system / bin usr You can move to a different directory with the command 'cd directory ' home etc username prot letter project . . seq 4 to seq 3 'directory' is the directory whichseq 2 you seq 1 want to move. The name can be written as the username@linus ~>(from ~/project> cd cd root) /home/username/project. . relative path full path or cd as the username@linus ~/project> ~> current pwd (frommeans your directory) '. . ' the parent directory. /home/username/project /home/username repeat using'. ' the relative pathcurrent directory. means the

Basic shell commands - cd • cd – changing directory – To a subdirectory: cd Desktop – Giving a complete path: cd /home/<username>/Desktop – To the next directory above: cd. .

Changing the file system / bin usr You can create a new subdirectory in the current directory with the command ' mkdir directory ' home etc username prot letter project model seq 4 seq 3 seq 2 seq 1 username@linus ~> mkdir model username@linus ~>

Changing the file system / bin usr You can delete an empty subdirectory with the command ' rmdir directory ' You can delete a file with the command ' rm file ' home etc username prot letter project model seq 4 seq 3 seq 2 seq 1 username@linus model You~> can rmdir delete a subdirectory and username@linus ~> rmwith prot its contents the command username@linus ' rm~>-rf directory '

More about files: filenames Filenames can contain any normal text character including spaces and special characters. Filenames can be almost any length. If a filename contains a special character or a space you may need to put quotes around the whole path. It is best to stick to a-z, A-Z, _, -, and numbers. It is best to keep them short as it saves typing. Special characters in filenames can cause problems with some programs.

More about files: reading files You can print the contents of one or more files to the screen with the command: 'cat file 1 file 2. . . ' You can view the contents of one or more files a prints file with at once, a file page at acat time on thewhole screen thesocommand: longer than just a few lines will run off ' more the file 1 file 2. . . ' top of your screen. You can print the first few lines of a file with the more will let you search through a file, go command: backwards and forwards 'head file 1 file 2. . . ' and has many other functions. The last few lines can be viewed with 'tail'

More about files: editing files You can change the content of text files and create new files with a text editor. PICO Text editors edit text. They do not try to format the text like word processors. EMACS A novice friendly basic text editor used as standard on many systems. Start with the A powerful'pico editingfilename' environment which can be VI command programmed. It has many modes for auto A powerful editor which can be somewhat layout of program code. Start with the confusing newcomers. It is designed for command for 'emacs filename' rapid editing of text files and programming. Start with the command 'vi filename'

More about files: copying files You can copy a file with the command 'cp oldfilename newfilename' If newfilename is a directory, ~> ls then the file will be copied to project ~>'newfilename/oldfilename' cp letter draft username@linus letter username@linus ~> ls draft letter Warning: username@linus ~> project If a file called newfilename already exists then it will be overwritten. The command 'mv oldfilename newfilename' can be used to rename a file

More about files: permissions • Every file is protected to a greater or lesser extent. • Permissions determine who can read, write, or execute a given file. Owner Group World The user who owns the file Other users in the same group the user owns All theas other userswho in the file. system. • Files can have read, write or execute permission for each of the three types of user.

More about files: permissions You can view the permissions for a file by listing it in long format with the command 'ls -l filename' username@linus ~> ls -l letter -rwxr--r-- 1 username users 6048 Aug 17 16: 07 letter The letter l Permissions for the everyone owners group else who the file The date file The type: files file was size last modified The files name Theowns files group Permissions for. The theuser owner - - ordinary file d - directory l - link (shortcut)

More about files: permissions You can change the permissions for a file with the command 'chmod change filename' username@linus ~>change ls -l letter is the modification you -rwxr--r-- 1 username users 6048 Aug 17 16: 07 letter want to make to the files username@linus ~> chmod o-r letter username@linus ~>permissions ls -l letter -rwxr----- 1 users 6048 Aug 17 16: 07 letter Permissions How you are being changing permissions: Forusername whom you are changed: changing permissions: username@linus ~> permission r read remove these permissions o -- other + w writethese add permissions g -- group x = execute set permissions (run) permission to this u -- user a - all

Getting help You can get help on a command by using the command ' man command' If you do not know a command called, page Thiswhat will bring up the is manual use the option '-k' get it a list of commands that and to show to you screen by screen may be relevant 'man -k word' This will find '-help', all manualor pages Try using the options '-h', containing word in the short '--help' if you can't find the man page. description of the command.

Finding commands quickly username@linus ~> history 123 17: 55 more food 124 17: 58 sort food username@linus ~> less. bash_history | grep man username@linus ~> 102 125 15: 04 18: 05 man scp history | grep man In Linux List of all commands previously typed with the word “man”

Finding commands quickly > history > less. bash_history > history | grep man – You see a list of all the commands you type with the word man in them

Process Management username@linus ~> ps PID TTY TIME CMD 22244 pts/27 0: 00 tcsh username@linus ~> top last pid: 22413; load averages: 1. 14, 1. 20, 1. 45 16: 19: 31 1089 processes: 1064 sleeping, 2 running, 17 zombie, 2 stopped, 4 on cpu CPU states: % idle, % user, % kernel, % iowait, % swap Memory: 4096 M real, 3310 M swap in use, 7852 M swap free PID 16417 13020 29164 USERNAME THR PRI NICE SIZE RES lakshmin 1 53 0 28 M 20 M root 1 59 0 57 M 42 M root 1 32 0 2960 K 1536 K username@linus ~> kill -9 16417 STATE TIME cpu 0 3: 07 cpu 3 114: 24 cpu 1 612: 54 CPU 1. 09% 0. 91% 0. 77% COMMAND netscape Xsun top Ctrl-C to break out Kill [-s signal] | -p] [–a] PID

Determining File Sizes and Space Usage username@linus ~> df Filesystem 1 k-blocks Used Available Use% Mounted on /dev/md/dsk/d 0 4131866 2249730 1840818 55% / swap 7993840 16 7993824 0% /var/run /dev/md/dsk/d 7 5017602 957225 4010201 19% /export/home linux: /export/home 209198492 148520117 39758526 79% /net/linux/ export/home username@linus ~> df -h

FTP – File Transfer Protocol ftp> ls -l command successful. username@linus ~> 200 ftp PORT ftp. ncbi. nih. gov 150 Opening ASCII mode data connection for file list. Connected to ftp. ncbi. nih. gov. dr-xr-xr-x 2 ftp 4096 Jun 25 1997 blasturl ftp> ls anonymous 220 FTP Server ready. dr-xr-xr-x 3 ftp 4096 Jul 1 09: 46 db 200 PORT anonymous command successful. anonymous Name (ftp. ncbi. nih. gov: huynh): dr-xr-xr-x 2 ftp anonymous 26 22: 59 for demo ftp> ls -l 150 Opening ASCII mode 4096 data Feb connection file 331 Anonymous login your complete email address as your password. dr-xr-xr-x 3 ftp anonymous 4096 Apr 17 2001 documents 200 ok, PORTsend command successful. list. dr-xr-xr-x 5 ftp anonymous Jun 21 19: 19 executables 150 Opening ASCII connection 4096 for file list. Password: oldmode data dr-xr-xr-x 3 ftp anonymous 4096 Dec 29 1998 blast fmerge 12 May 20 17: 04 special 230 Anonymous access granted, restrictions apply. dr-xr-xr-x 2 anonymous 4096 Aug 1997 matrices 3 ftp Mar 26 2 20: 50 cgap README. bls ftp> bin dr-xr-xr-x 3 anonymous 4096 Jun 12 7 18: 33 1999 network 4 ftp cn 3 d README. imp 200 Type set to I dr-xr-xr-x 12 anonymous 4096 Jun 18 22: 49 server 11 ftp Dec 20 2001 entrez blast. hpux 11. tar. Z dr-xr-xr-x 2 anonymous 4096 Jul 1 15: 59 5 ftp Jan 15 21: 35 temp fa 2 htgs ftp> ls -l blast. hpux 11. tar. gz dr-xr-xr-x ftp anonymous 12288 Jun 26 07: 01 genbank 226 Transfer 11 complete. blast. AIX-powerpc. tar. Z ftp> cd blast dr-xr-xr-x 4096 Jun 19 14: 22 genomes remote: -l 15 ftp blast. hqxanonymous dr-xr-xr-x 7 ftp anonymous 4096 Kbytes/s) Feb 14 23: 06 mmdb 645 bytes received in 0. 052 seconds (12. 05 ftp> ls -l blastz. exe dr-xr-xr-x 4 ftp anonymous 12288 Jun 26 07: 36 ncbi-asn 1 blast. solaris. tar. Z ftp> cd executables dr-xr-xr-x 73 ftp anonymous 4096 May 17 20: 34 pub blast. solarisintel. tar. Z ftp> ls -l dr-xr-xr-x 2 ftp anonymous 4096 Dec 14 2001 pubmed blast. linux. tar. Z ftp> mget blast. linux. tar. Z dr-xr-xr-x 11 ftp anonymous 4096 Mar 7 17: 07 refseq blast. sgi. tar. Z dr-xr-xr-x 59 ftp anonymous 4096 May 15 21: 45 repository mget blast. linux. tar. Z? y blast. sgi 32. tar. Z dr-xr-xr-x 6 ftp anonymous 4096 Apr 26 19: 27 sequin 200 PORT command successful. blast. macosx. tar. gz ftp anonymous 4096 Jun 14 22: 32 snp blast-Free. BSD-4. 5 -i 386. tar. gz 150 Opening BINARYdr-xr-xr-x mode data 16 connection for blast. linux. tar. Z (20222367 bytes). dr-xr-xr-x 2 ftp anonymous 4096 Jan 26 1996 tech-reports blast. alpha. OSF 1. tar. Z 226 Transfer complete. dr-xr-xr-x 12 ftp anonymous 4096 Dec 20 2001 toolbox delme local: blast. linux. tar. Z remote: blast. linux. tar. Z 226 Transfer complete. 20222367 bytes received Kbytes/s) remote: in -l 4. 3 seconds 311 bytes(4579. 68 received in 0. 038 seconds (8. 05 Kbytes/s) 1092 bytes received in 0. 023 seconds (46. 86 Kbytes/s) ftp>

Useful literature • Learning the UNIX operating system O'Reilly Press • UNIX Quickguide - EMBnet • Running Linux, 3 rd Edition – O’Reilly Press

Useful Online Resource • • • http: //www. freshmeat. net/ http: //www. linuxiso. org/ http: //www. redhat. com/ http: //www. tldp. org/ http: //www. linux. org/ http: //www. cygwin. com/
- Slides: 30