Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Linux/UNIX Commands The symbol of Linux. Unix doesn’t really care where you log in from, though some system administrators might. Logging in Log.

Similar presentations


Presentation on theme: "Basic Linux/UNIX Commands The symbol of Linux. Unix doesn’t really care where you log in from, though some system administrators might. Logging in Log."— Presentation transcript:

1 Basic Linux/UNIX Commands The symbol of Linux

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

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

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

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

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

7 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 data could be an image, a document, a set of instructions (a program) or any fixed information. This is also known as a folder on some systems. A directory can contain other directories (which are then known as sub-directories.) Files can have more than one name, and be in different directories at the same time There are many other types of file. You don't need to worry about these. You probably won't come across one in normal use of the system.

8 Organization of the file system / The top of the file system is the directory '/', commonly known as the root directory bin usr etc home Several subdirectories under the root directory username Another subdirectory. project seq2seq1seq3seq4 letterprot An example users home directory with a subdirectory and several files Any file in the file system can be uniquely identified by describing the path to it from the root directory. /home/username/prot/ home /home/username/prot username /home/username/prot prot

9 Organization of the file system / binusretchome username project seq2seq1seq3 seq4 letterprot Any process is located somewhere in the filesystem The command ' pwd ' will tell you where. username@linus ~>pwd /home/username '~' is a unix shortcut meaning 'your home directory'

10 Looking at the file system / binusretchome username project seq2seq1seq3 seq4 letterprot ' ls ' lists the files in a directory or directories username@linus ~>ls protletterproject username@linus ~> project: seq1seq2seq3seq4 ls project Without an argument, ls lists all the files that don't start with. in the current directory There are many options to ls that allow you to select and control the information it presents.

11 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

12 Moving around the file system / binusretchome username project seq2seq1seq3 seq4 letterprot ' directory ' is the directory to which you want to move. The name can be written as the full path (from root) or as the relative path (from your current directory) You can move to a different directory with the command ' cd directory ' username@linus ~>cd /home/username/project username@linus ~/project>pwd /home/username/project username@linus ~>cd project username@linus ~/project>pwd /home/username/project username@linus ~/project>cd.. '..' means the parent directory. '.' means the current directory... username@linus ~>pwd /home/username username@linus ~> repeat using the relative path

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

14 Changing the file system / binusretchome username project seq2seq1seq3 seq4 letterprot You can create a new subdirectory in the current directory with the command ' mkdir directory ' username@linus ~>mkdir model username@linus ~> model

15 Changing the file system / binusretchome username project seq2seq1seq3 seq4 letterprot You can delete an empty subdirectory with the command ' rmdir directory ' username@linus ~>rmdir model model username@linus ~> model You can delete a file with the command ' rm file ' rm prot username@linus ~> You can delete a subdirectory and its contents with the command ' rm -rf directory '

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

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

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

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

20 username@linus ~> To copy file: letter ' from linus to dir1 subdirectory of your course account More about files: copy files Scp – Secure Copy (remote file copy program) letterproject username@linus ~> ls scp letter course:dir1 username@linus ~> scp course:myfile. username@course ~> scp -r mydir course: To copy file: myfile from your course account to your home directory on linus username@linus’s password: letter 100% |*************************| 9 To recursively copy : mydir from your course homedirectory to your account on linus

21 Grep – power search utility - Basics The grep program searches a file or files for lines that have a certain pattern. The syntax is: > grep pattern file(s) The simplest use of grep is to look for a pattern consisting of a single word. It can be used in a pipe so that only those lines of the input files containing a given string are sent to the standard output. If you don't give grep a filename to read, it reads its standard input; that's the way all filter programs work: runs ls -l to list your directory. The standard output of ls -l is piped to grep, which only outputs lines that contain the string "Aug" (that is, files that were last modified in August). Because the standard output of grep isn't redirected, those lines go to the terminal screen. username@linus ~> ls -l | grep "Aug" -rw-rw-rw- 1 john doc 11008 Aug 6 14:10 ch02 -rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07 -rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro -rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros %

22 The sort command arranges lines of text alphabetically or numerically sort doesn't modify the file itself; it reads the file and writes the sorted text to the standard output. sort arranges lines of text alphabetically by default.

23 username@linus ~> More about files: sort Afghani Cuisine Tio Pepe's Peppers Bangkok Wok Sushi and Sashimi Mandalay Big Apple Deli Isle of Java Sweet Tooth username@linus ~> more food sort food Afghani Cuisine Bangkok Wok Big Apple Deli Isle of Java Mandalay Sushi and Sashimi Sweet Tooth Tio Pepe's Peppers username@linus ~>

24 Usage: sort – [general options] –o [outfile] –[key interpretation options] –t[char] –k[keydef]…[filenames] Option: -n Sort numerically (example: 10 will sort after 2), ignore blanks and tabs. -r Reverse the order of sort. -f Sort upper- and lowercase together. +x Ignore first x fields when sorting. -m Merges several input files

25 username@linus ~> ls -l | grep "Aug" | sort +4n Sort, grep, ls username@linus ~> ls -l | grep "Aug" | sort +4n -rw-rw-r-- 1 carol doc 1605 Aug 23 07:35 macros -rw-rw-r-- 1 john doc 2488 Aug 15 10:51 intro -rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07 -rw-rw-rw- 1 john doc 11008 Aug 6 14:10 ch02 username@linus ~> This pipe sorts all files in your directory modified in August by order of size, and prints them to the terminal screen. The sort option +4n skips four fields (fields are separated by blanks) then sorts the lines in numeric order. So, the output of ls (actually, the output of grep) is sorted by the file size (the fifth column, starting with 1605). Both grep and sort are used here as filters to modify the output of the ls -l command. If you wanted to email this listing to someone, you could add a final pipe to the mail command. Or you could print the listing by piping the sort output to your printer command (like lp or lpr). What does this do?

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

27 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 The file type: - - ordinary file d - directory l - link (shortcut) Permissions for the owner -rwxr--r-- Permissions for the owners group -rwxr--r-- Permissions for everyone else -rwxr--r--username The user who owns the file users The files group 6048 The files size Aug 17 16:07 The date the file was last modified letter The files name More about files: permissions

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

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

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

31 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

32 Process Management username@linus ~> ps PID TTY TIME CMD 22244 pts/27 0:00 tcsh username@linus ~> top username@linus ~> Ctrl-C to break out kill -9 16417 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: 4096M real, 3310M swap in use, 7852M swap free PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND 16417 lakshmin 1 53 0 28M 20M cpu0 3:07 1.09% netscape 13020 root 1 59 0 57M 42M cpu3 114:24 0.91% Xsun 29164 root 1 32 0 2960K 1536K cpu1 612:54 0.77% top Kill [-s signal] | -p] [–a] PID

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

34 FTP – File Transfer Protocol username@linus ~> Connected to ftp.ncbi.nih.gov. 220 FTP Server ready. Name (ftp.ncbi.nih.gov:huynh): ftp ftp.ncbi.nih.gov anonymous 230 Anonymous access granted, restrictions apply. 331 Anonymous login ok, send your complete email address as your password. Password: ftp> bin 200 Type set to I ftp> ls -l ftp> cd blast ftp> ls -l 200 PORT command successful. 150 Opening ASCII mode data connection for file list. dr-xr-xr-x 12 ftp anonymous 4096 May 20 17:04 blast dr-xr-xr-x 3 ftp anonymous 4096 Mar 2 20:50 cgap dr-xr-xr-x 4 ftp anonymous 4096 Jun 12 18:33 cn3d dr-xr-xr-x 11 ftp anonymous 4096 Dec 20 2001 entrez dr-xr-xr-x 5 ftp anonymous 4096 Jan 15 21:35 fa2htgs dr-xr-xr-x 11 ftp anonymous 12288 Jun 26 07:01 genbank dr-xr-xr-x 15 ftp anonymous 4096 Jun 19 14:22 genomes dr-xr-xr-x 7 ftp anonymous 4096 Feb 14 23:06 mmdb dr-xr-xr-x 4 ftp anonymous 12288 Jun 26 07:36 ncbi-asn1 dr-xr-xr-x 73 ftp anonymous 4096 May 17 20:34 pub dr-xr-xr-x 2 ftp anonymous 4096 Dec 14 2001 pubmed dr-xr-xr-x 11 ftp anonymous 4096 Mar 7 17:07 refseq dr-xr-xr-x 59 ftp anonymous 4096 May 15 21:45 repository dr-xr-xr-x 6 ftp anonymous 4096 Apr 26 19:27 sequin dr-xr-xr-x 16 ftp anonymous 4096 Jun 14 22:32 snp dr-xr-xr-x 2 ftp anonymous 4096 Jan 26 1996 tech-reports dr-xr-xr-x 12 ftp anonymous 4096 Dec 20 2001 toolbox 226 Transfer complete. remote: -l 1092 bytes received in 0.023 seconds (46.86 Kbytes/s) ftp> ls -l ftp> cd executables ftp> ls -l ftp> mget blast.linux.tar.Z mget blast.linux.tar.Z? y 200 PORT command successful. 150 Opening BINARY mode data connection for blast.linux.tar.Z (20222367 bytes). 226 Transfer complete. local: blast.linux.tar.Z remote: blast.linux.tar.Z 20222367 bytes received in 4.3 seconds (4579.68 Kbytes/s) ftp> ftp> ls -l 200 PORT command successful. 150 Opening ASCII mode data connection for file list. dr-xr-xr-x 2 ftp anonymous 4096 Jun 25 1997 blasturl dr-xr-xr-x 3 ftp anonymous 4096 Jul 1 09:46 db dr-xr-xr-x 2 ftp anonymous 4096 Feb 26 22:59 demo dr-xr-xr-x 3 ftp anonymous 4096 Apr 17 2001 documents dr-xr-xr-x 5 ftp anonymous 4096 Jun 21 19:19 executables dr-xr-xr-x 3 ftp anonymous 4096 Dec 29 1998 fmerge dr-xr-xr-x 2 ftp anonymous 4096 Aug 26 1997 matrices dr-xr-xr-x 3 ftp anonymous 4096 Jun 7 1999 network dr-xr-xr-x 12 ftp anonymous 4096 Jun 18 22:49 server dr-xr-xr-x 2 ftp anonymous 4096 Jul 1 15:59 temp 226 Transfer complete. remote: -l 645 bytes received in 0.052 seconds (12.05 Kbytes/s) ftp> ls 200 PORT command successful. 150 Opening ASCII mode data connection for file list. old special README.bls README.imp blast.hpux11.tar.Z blast.hpux11.tar.gz blast.AIX-powerpc.tar.Z blast.hqx blastz.exe blast.solaris.tar.Z blast.solarisintel.tar.Z blast.linux.tar.Z blast.sgi.tar.Z blast.sgi32.tar.Z blast.macosx.tar.gz blast-FreeBSD-4.5-i386.tar.gz blast.alphaOSF1.tar.Z delme 226 Transfer complete. 311 bytes received in 0.038 seconds (8.05 Kbytes/s) ftp>

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

36 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/

37 Extra Slides


Download ppt "Basic Linux/UNIX Commands The symbol of Linux. Unix doesn’t really care where you log in from, though some system administrators might. Logging in Log."

Similar presentations


Ads by Google