1 / 30

Basic Linux/UNIX Commands

Basic Linux/UNIX Commands. The symbol of Linux. Have graphical output sent anywhere you have permission. Log in from anywhere you have permission. This identifies you to the system so it can manage your work properly. This helps the system manage different types of user properly.

pooky
Download Presentation

Basic Linux/UNIX Commands

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic Linux/UNIX Commands The symbol of Linux

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

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

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

  5. username@linus ~> ls -ald *.txt ls -ald *.txt ls -ald *.txt ls -ald *.txt The first word is a command The subsequent words form a list of arguments to the command arguments beginning with - are options * 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 Options control how the program runs. '-a -l -d' is equivalent to '-ald' The shell or command line 2. Commands ls -ald *.txt The shell breaks the command up into individual words 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".

  6. Any single character. word delineation Any group of characters including none. 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. Cause the process to run in the background Backslash. Change the meaning of the next character. Semicolon Seperate commands typed in together. Backticks (not '). Take the output of the command as an argument String or Dollar Treat the next word as a variable and write out its value More Special Characters * ? " ' & | > < `` $ \ ; Some special characters can lose their special meaning if they are inside quotes.

  7. 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 You don't need to worry about these. You probably won't come across one in normal use of the system. 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. • There are many other types of file .

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

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

  10. / bin usr home etc username 'ls' lists the files in a directory or directories prot letter project There are many options to ls that allow you to select and control the information it presents. Without an argument, ls lists all the files that don't start with . in the current directory seq3 seq2 seq1 seq4 username@linus ~> username@linus ~> Looking at the file system ls ls project prot letter project project: seq1 seq2 seq3 seq4

  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. / bin usr home etc username You can move to a different directory with the command 'cd directory ' prot letter project .. '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) seq3 seq2 seq1 seq4 username@linus ~> username@linus ~/project> username@linus ~> username@linus ~> '..' means the parent directory. '.' means the current directory. /home/username/project /home/username /home/username/project repeat using the relative path Moving around the file system cd /home/username/project cd project cd .. username@linus ~/project> username@linus ~> username@linus ~/project> pwd pwd pwd

  13. 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 ..

  14. / bin usr home etc username You can create a new subdirectory in the current directory with the command ' mkdir directory ' prot letter project model seq3 seq2 seq1 seq4 username@linus ~> username@linus ~> Changing the file system mkdir model

  15. / bin usr home etc You can delete an empty subdirectory with the command ' rmdir directory ' username prot letter project model model You can delete a file with the command ' rm file ' seq3 seq2 seq1 seq4 username@linus ~> You can delete a subdirectory and its contents with the command ' rm -rfdirectory' username@linus ~> username@linus ~> Changing the file system rmdir model rm prot

  16. More about files: filenames Filenames can contain any normal text character including spaces and special characters. It is best to stick to a-z, A-Z, _, -, and numbers. It is best to keep them short as it saves typing. 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. Special characters in filenames can cause problems with some programs.

  17. 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' More about files: reading files You can print the contents of one or more files to the screen with the command: 'cat file1 file2 ...' 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 ...'

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

  19. If newfilename is a directory, then the file will be copied to 'newfilename/oldfilename' 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 More about files: copying files You can copy a file with the command 'cp oldfilename newfilename' ls letter project username@linus ~> cp letter draft username@linus ~> ls draft letter project username@linus ~>

  20. Owner Group The user who owns the file World Other users in the same group as the user who owns the file. All the other users in the system. 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. • Files can have read, write or execute permission for each of the three types of user.

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

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

  23. This will bring up the manual page and show it to you screen by screen This will find all manual pages containing word in the short description of the command. Getting help You can get help on a command by using the command ' man command' 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.

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

  25. 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

  26. username@linus ~> ps Ctrl-C to break out Kill [-s signal] | -p] [–a] PID Process Management 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: 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 username@linus ~> kill -9 16417

  27. username@linus ~> df Determining File Sizes and Space Usage 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

  28. username@linus ~> 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> 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 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 – File Transfer Protocol ftp ftp.ncbi.nih.gov Connected to ftp.ncbi.nih.gov. 220 FTP Server ready. Name (ftp.ncbi.nih.gov:huynh): anonymous 331 Anonymous login ok, send your complete email address as your password. Password: 230 Anonymous access granted, restrictions apply. ftp> bin 200 Type set to I ftp> ls -l ftp> cd blast 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>

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

  30. 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/

More Related