Basic Linux/UNIX Commands

download Basic  Linux/UNIX Commands

If you can't read please download the document

description

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. - PowerPoint PPT Presentation

Transcript of Basic Linux/UNIX Commands

  • Basic Linux/UNIXCommandsThe symbol of Linux

  • Logging inUnix doesnt really care where you log in from, though some system administrators might.You must have a username (login id) to use a unix systemEvery user is a member of one or more groups of users.

  • Logging inConnect 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 ~>

  • The shell or command lineSeveral different shells but they behave more or less the same1. The Prompt.

  • The shell or command line2. CommandsThe shell breaks the command up into individual wordsls -ald *.txtBy 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".

  • More Special Characters*?" '&|>
  • 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 .

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

  • Organization of the file systempwd

  • Looking at the file systemlsprotletterprojectproject:seq1seq2seq3seq4ls project

  • Basic shell commands - lsls: list existing files in current directoryShort listing: lsList all files: ls aDetailed long list: ls lAll of the above: ls -al

  • Moving around the file systemcd /home/username/projectusername@linus ~/project>pwdcd projectusername@linus ~/project>pwdcd ..username@linus ~>pwd

  • Basic shell commands - cdcd changing directoryTo a subdirectory: cd DesktopGiving a complete path: cd /home//DesktopTo the next directory above: cd ..

  • Changing the file systemmkdir model

  • Changing the file systemrmdir modelrm prot

  • More about files: filenamesFilenames 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.

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

  • More about files: editing filesYou can change the content of text files and create new files with a text editor.PICOEMACSVI

  • More about files: copying filesYou can copy a file with the command 'cp oldfilename newfilename'letterprojectusername@linus ~>lscp letter draftusername@linus ~>lsdraftletterprojectusername@linus ~>

  • More about files: copy filesScp Secure Copy (remote file copy program)letterprojectusername@linus ~>lsscp letter course:dir1username@linus ~>scp course:myfile .username@course ~> scp -r mydir course:username@linuss password:letter 100% |*************************| 9

  • Grep power search utility - BasicsThe 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.

  • The sort command arranges lines of text alphabetically or numericallysort 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.

  • More about files: sortAfghani CuisineTio Pepe's PeppersBangkok WokSushi and SashimiMandalayBig Apple DeliIsle of JavaSweet Toothusername@linus ~>more foodsort foodAfghani CuisineBangkok WokBig Apple DeliIsle of JavaMandalaySushi and SashimiSweet ToothTio Pepe's Peppersusername@linus ~>

  • 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

  • Sort, grep, lsusername@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 ch02username@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).

  • More about files: permissionsPermissions determine who can read, write, or execute a given file.Every file is protected to a greater or lesser extent.Files can have read, write or execute permission for each of the three types of user.

  • More about files: permissionsYou 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

  • More about files: permissionsYou can change the permissions for a file with the command 'chmod change filename'-rwxr--r-- 1 username users 6048 Aug 17 16:07 letterusername@linus ~>ls -l letterchmod o-r letterusername@linus ~>-rwxr----- 1 username users 6048 Aug 17 16:07 letterusername@linus ~>ls -l letter

  • Getting helpYou 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.

  • Finding commands quickly 123 17:55 more food 124 17:58 sort foodusername@linus ~>less .bash_historyusername@linus ~>history | grep man 102 15:04 man scp 125 18:05 history | grep man

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

  • Process Management PID TTY TIME CMD 22244 pts/27 0:00 tcshusername@linus ~>topusername@linus ~>kill -9 16417last pid: 22413; load averages: 1.14, 1.20, 1.45 16:19:311089 processes:1064 sleeping, 2 running, 17 zombie, 2 stopped, 4 on cpuCPU states: % idle, % user, % kernel, % iowait, % swapMemory: 4096M real, 3310M swap in use, 7852M swap free

    PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND16417 lakshmin 1 53 0 28M 20M cpu0 3:07 1.09% netscape13020 root 1 59 0 57M 42M cpu3 114:24 0.91% Xsun29164 root 1 32 0 2960K 1536K cpu1 612:54 0.77% top

  • Determining File Sizes and Space UsageFilesystem 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/homelinux:/export/home 209198492 148520117 39758526 79% /net/linux/export/homeusername@linus ~> df -h

  • FTP File Transfer ProtocolConnected to ftp.ncbi.nih.gov.220 FTP Server ready.Name (ftp.ncbi.nih.gov:huynh):ftp ftp.ncbi.nih.govanonymous230 Anonymous access granted, restrictions apply.331 Anonymous login ok, send your complete email address as your password.Password: ftp> bin200 Type set to Iftp> ls -lftp> cd blastftp> ls -lftp> cd executablesftp> ls -lftp> mget blast.linux.tar.Zmget blast.linux.tar.Z? y200 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.Z20222367 bytes received in 4.3 seconds (4579.68 Kbytes/s)ftp>

  • Useful literatureLearning the UNIX operating system - O'Reilly PressUNIX Quickguide - EMBnetRunning Linux, 3rd Edition OReilly Press

  • Useful Online Resourcehttp://www.freshmeat.net/http://www.linuxiso.org/http://www.redhat.com/http://www.tldp.org/http://www.linux.org/http://www.cygwin.com/

  • Extra Slides

    Course is your remote machine.Anything start with / is local while linux: is physically part of another machine