05.linux basic-operations-1

356 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
356
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

05.linux basic-operations-1

  1. 1. Linux: Basic Operations - 1 Minsuk Lee Hansung University, Seoul, Korea minsuk@hansung.ac.krNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  2. 2. Simple Shell usage • Invoking Terminal  • Type any command and [ENTER] • BIG TIPs !! – Use „←,↑→↓‟, [INS], [DEL],[HOME],[END] keys to edit command line – Try [tab] - It completes filename or shows all available choices – When output stops, try [SPACE], mouse scroll, „q‟ to continue or to quit – $ exit -- will end the terminalNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  3. 3. man (1) • Shows manual page of Linux commands, libraries, utilities • Usage : $ man [options] [section] item – Item can be program, function, file, anything in /usr/share/man/*/ • Options : – Sections 1. Executable programs or shell commands 2. System calls (functions provided by the kernel) 3. Library calls (functions within program libraries) 4. Special files (usually found in /dev) 5. File formats and conventions e.g. /etc/passwd 6. Games 7. Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) 8. System administration commands (usually only for root) 9. Kernel routines [Non standard] „$ man printf „ show man page of shell command printf „$ man 3 printf „ show man page of printf() library „$ man -a printf „ show man page of both of the twoNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  4. 4. man (2) • Options : -a : display all available manual pages of the item -k : list all man page items includes the given item name ($ apropos –r item) -f : shows very short descriptions -Tps : output as Postscript format (to be converted into pdf) • Example $ man man $ man -Tps 3 printf | ps2pdf - printf.pdf • Alternatives $ info item : shows detail information, if the item is available in /usr/share/info $ command –help : shows help messages (options) of the command • PLEASE READ MAN PAGES OF COMMANDS, FUNCTIONS YOU USE !!NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  5. 5. man (3) – „$ man ls‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  6. 6. man (4) – „$ man 3 printf‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  7. 7. ls • Lists directory contents • Usage : $ ls [options] file-or-directory… – If file-or-directory is missing, current directory is assumes • Options : -a : list all, including hidden files and directories (starting with .) -l : show details (permission, owner, group, size, dates) -R : list files recursively traversing child directories -1 : lists one item in one lineNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  8. 8. cd (1) • Changes the shell working (current) directory • Usage : $cd directory – Directory can be • directory-name, /adir/bdir/cdir, .. – Linux DO NOT USE „\‟(„‟), BUT USE „/‟ in directory hierarchy – „.‟ means current directory, „..‟ means parent directory – If no directory is specified, it assumes home directory – If directory name starts with „/‟, it‟s absolute directory from the root directory – If directory does not start with „/‟, it‟s relative to current directory • Examples „$ cd‟ moves current directory to my home (same as „$ cd ~‟ „$ cd ..‟ move current directory to parent directory „$ cd /usr/share/man‟ move current directory to /usr/share/man „$ cd ~user‟ moves current directory to user‟s home directoryNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  9. 9. cd (2) • Some more information on directories „$ pwd‟ shows current directory „$ mkdir directory‟ makes a new directory „$ rmdir directory‟ removes the directory „$ pushd directory‟ saves current directory, and moves to the specified directory „$ dirs‟ shows the pushed directory „$ popd‟ returns to the saved directoryNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  10. 10. cp, mv • Copies files and directories • Usage: $ cp [options] source… destination – If destination is existing directory, source is copied into the destination directory – If destination file is existing, it‟s overwritten • Options: -a : copy as is (preserving all the attributes of the source) -b : make a backup of each existing destination file -f : if destination file exists and cannot be opened, remove it and retry -i : prompt before overwrite -l : link (hard) files instead of copying -n : do not overwrite (ignoring –i) -r : copy directories recursively -s : make symbolic links instead of copying -u : copy only when source is newer than destination • Usage: $ mv [options] source… destination – Rename source to destination or move source to destination directoryNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  11. 11. rm • removes files or directories • Usage: $ rm file… – Remove files • Options -f : never prompt -i : prompt before every removal -r : remove directories and its contents recursively -v : verbose mode, (explain what is being done) • IMPORTANT NOTICE !!! – THERE IS NO “RECYCLING BIN or TRASH CAN” in Linux for UNDELETE • Desktop file browser usually support UNDELETE function, but not for „rm‟ • How to delete a file with name starts with „-‟ ? – „$ rm -- -foo‟ or „$ rm ./-foo‟NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  12. 12. Name pattern matching • Specifying multiple files(directories) – Work for ALL commands • „*‟ means any string (multiple, any characters including null) • „?‟ means any single character • [a-s] : means any single character between „a ‟ and „s ‟ – E.g., [1-7c-f], [acf2A-Z], … – „$ rm * ‟ : means everything in current directory – „$ rm directory/* „ : means everything in directory – „$ rm s*s „ : means files or directories start and end with „s ‟ – „$ rm 6[ab]x* „ : means files or directories start with „6ax ‟ or „6bx ‟ • See man page of bash ( $ man bash ) for more – Such as ?(patten-list), *(patten-list), +(pattern-list), …NEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  13. 13. more • Displays files on screen page by page • Usages : $ more [options] file… • Options: -num : specifies screen size in lines (e.g., „$ more -7 file‟) • Commands after screen stops: ‘h’ : help screen [SPACE] or ‘z’ : next num lines [ENTER] or ‘1’ : next line ‘q’ : exit ‘f ‘ : next screen ‘b’ : 또는 - ^B : 이전 페이지(back) ‘/pattern ‘ : find and go to the position of pattern ‘n’ : find next occurrence of the pattern vi (text editor) ‘=‘ : print current line number commands ‘!command ’ : run shell command ‘^L’ (Ctrl-L) : refresh screen ‘:n’ : next file ‘:p’ : previous file ‘:f’ : show current file name and line numberNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  14. 14. cat • Concatenates files and print on display • Usage : $ cat [options] file… – Concatenate files, and print on display (standard output) – Used to print, create simple file • Options : • -E : display „$‟ at the end of each line • -b : number non-empty lines • -n : number all lines • -T : show TAB as ^I • -v : show non-printing control characters except LF and TABNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  15. 15. Pipe and redirection • Standard Input and Output – In Shell, It‟s Keyboard input and Screen Output, by default – Pipe feeds standard output into other command‟s standard input – Redirection redirects the standard input/output from/to files „$ ls –l | more‟ : feed the output of „ls –l‟ to „more‟ „$ ls –1 | sort –r | more‟ : „ls -1‟ then, „sort‟ in reverse order, and „more‟ „$ ls –l > file ‟ : redirect the output of „ls –l‟ to file (overwrite or create) „$ ls –l >> file ‟ : redirect the output of „ls –l‟ to file (append) „$ cat a b > c ‟ : concatenate file „a „ and „b „ into file „c „ „$ sort < source > destination ‟ : „sort‟ source, into destination „# cat /dev/cdrom > foo.iso‟ • Standard Error „$ command 2> file‟ : redirect error message of command to fileNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA
  16. 16. Let‟s Practice • Open a terminal /etc is a directory of • Move to /etc and see what‟s in it, and see /etc/passwd System Configuration – $ cd /etc – $ ls or $ ls –l or $ ls –l | more /etc/passwd is – $ more /etc/passwd or $ cat /etc/passwd A user list of a System • Copy /etc/passwd into my home directory as sample – $ cp /etc/passwd ~/sample • Return to my home directory and Triple it into big-sample, and see – $ cd ~ or just $ cd // move back to my home – $ cat sample sample sample > big-sample // cat sample three times and redirect into big-sample – $ ls –l // see the file size – $ more big-sample // try all commands of more – $ sort big-sample > sorted-sample // see what happens in sorted-sample • Make a new directory „data‟ and copy sample and move results the files into it – $ mkdir data // – $ cp sample data – $ mv *-sample data – $ ls –l data – $ ls –l • Remove Everything – $ rm –rfi sample data // see what happening, answer with „n‟ !! – $ rm –rf sample data – $ ls -lNEAOSS MC2.0 CC-BY 2.0 KR, © Korea OSS Promotion Forum, NIPA

×