1 / 58

Introduction to LINUX

Introduction to LINUX. CHAPTER 3. Command Line Utilities CHAPTER 4 . The Linux Filesystem. What did we learn last time?. How can I connect to Linux-system from my networked PC? What is my login name? What is my password? How can I change my password? ( passwd )

colman
Download Presentation

Introduction to LINUX

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. Introduction to LINUX CHAPTER3. Command Line Utilities CHAPTER 4. The Linux Filesystem __________________________________________________________________________________1__

  2. What did we learn last time? • How can I connect to Linux-system from my networked PC? • What is my login name? • What is my password? • How can I change my password? (passwd) • How to pick a good password? • Logging off (exit, Ctrl+D) __________________________________________________________________________________2__

  3. Command Components • Commands consist of: • Command name • Options, or flags • Arguments • Arguments are the “things” that the command will operate on • Options modify the behavior of the command __________________________________________________________________________________3__

  4. Entering commands Command options and arguments $ date $ ls –a $ ls –al $ cal The who command The w command The finger command $ finger $ finger user_name The write command The talk command The mesg command $ mesg y $ mesg n $ mesg Command name Option(s) Argument Allows receiving the messages Denies receiving the messages __________________________________________________________________________________4__

  5. Who Lists Users on the System • Who is on the system and info about their login • User_name, terminal_name, login_time • Syntax: who [am i] • Example: clyde% who Root console Jul 22 09:36 krf ttyp0 Aug 7 10:32 (dal-tx2-33.ix.ne) • am i option lists requestor info only • Related command: whoami • Lists requestor’s user_name only __________________________________________________________________________________5__

  6. finger • Displays information about users • Syntax: finger [options] user_name • By default, finger displays user_name’s: • login name • full name • terminal name • idle time • login time • location • first line of .plan file __________________________________________________________________________________6__

  7. talk • Talk to another user • Syntax: talk username [ttyname] username - login name if on the same machine, username@machinename if on a different machine ttyname - login session to use if username is logged in more than once __________________________________________________________________________________7__

  8. talk Example clyde% talk krf Message from Talk_Daemon@clyde at 17:39 ... talk: connection requested by krf@clyde.dcccd.edu. talk: respond with: talk krf@clyde.dcccd.edu • Respond as shown and a split screen will be displayed with your input in one half and your talk-mate’s output in the other • To end the session, type Control-c __________________________________________________________________________________8__

  9. MESsaGe - mesg • Permit or deny messages on your terminal • Syntax: mesg [n] [y] • default reports current state without changing it • n - forbids messages to be sent to you from talk or write • y - reinstates permission __________________________________________________________________________________9__

  10. write • Write a message to another user • Syntax: write username [ttyname] username - login name of the message recipient ttyname - terminal name if user is logged in more than once Whatever you type is then copied, line by line, to the recipient’s terminal until you enter on EOF (control-d) __________________________________________________________________________________10__

  11. write Example: clyde% write krf Hi there! Heard any good Linux jokes lately? control-d • On krf’s terminal, the following appears: clyde% Message from krf@clyde on ttyp1 at 17:50 ... Hi there! Heard any good Linux jokes lately? clyde% __________________________________________________________________________________11__

  12. Specifying a Terminal Terminal characteristics $ echo $TERM $ stty $ TERM=vt100 $ export TERM $ echo $TERM Environment variable Displays value(s) on the screen Definition of the variable TERM Makes the new value known to the system __________________________________________________________________________________12__

  13. Listing the content of a Directory $ ls -l total 1272 drwxr-xr-x 2 volin users 4096 Jan 21 11:23 COS120 drwx------ 5 volin users 4096 Sep 3 10:31 Desktop -rwxr-xr-x 1 volin users 1504 Oct 10 13:48 a -rw-r--r-- 1 volin users 108 Dec 16 22:41 awk1 -rw-r--r-- 1 volin users 68 Dec 16 22:59 awk2 -rw-r--r-- 1 volin users 57 Dec 14 22:50 awktest -rwxr-xr-x 1 volin users 1472 Oct 10 13:48 b -rw-r--r-- 1 volin users 1561 Nov 27 17:08 bank.pl $ ls $ ls –a $ ls -al $ ls -al|more total 1396 drwxr-xr-x 21 volin users 4096 Jan 21 11:17 . drwxr-xr-x 117 root root 4096 Jan 21 10:59 .. -rw------- 1 volin users 0 Dec 3 18:11 .ICEauthority -rw------- 1 volin users 107 Dec 3 18:11 .Xauthority -rw-r--r-- 1 volin users 0 Sep 4 21:54 .addressbook drwxr-xr-x 2 volin users 4096 Jan 21 11:23 COS120 drwx------ 5 volin users 4096 Sep 3 10:31 Desktop -rwxr-xr-x 1 volin users 1504 Oct 10 13:48 a -rw-r--r-- 1 volin users 108 Dec 16 22:41 awk1 __________________________________________________________________________________13__

  14. Displaying the contents of a Text File $ cat f1 f2 $ more ffff File name(s) Displays the content page by page __________________________________________________________________________________14__

  15. More commands $date Mon Jan 28 11:43:14 EET 2002 $ date $ cal Options? How to learn about the commands? $cal January 2002 Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 __________________________________________________________________________________15__

  16. CALendar - cal • Prints a calendar for the specified year • Default is current year • Syntax: cal [ [ month ] year ] • month - number from 1 to 12 • year - number from 1 to 9999 • Note: September 1752 is odd, 11 days were skipped to make up for lack of prior leap year adjustments • Examples: clyde% cal clyde% cal 9 1752 __________________________________________________________________________________16__

  17. date • Display or set the date • Syntax:date [-u] [-a [-] sss.fff] [yymmddhhmm [.ss]] • u - display date in GMT, default is local time • a - slowly adjust system clock • yymmddhhmm [.ss] - set system date and time • Only superuser can set the date and time • If the argument begins with a +, the output of date is under user control • Examples: clyde% date clyde% date -u clyde% date +%T __________________________________________________________________________________17__

  18. Searching the man-pages with Keywords • If you do not know the name of the command to carry out a particular task, you can search the man-pages with keyword. $ man –k sort or $ apropos sort • The output from these commands might be more than one screen. How can you manage to get page-by-page output? • Texinfo database in Linux contains full description of the commands. $ info <name_of_the_command> “Play” for a couple of minute with these commands __________________________________________________________________________________18__

  19. MANual pages - man • Read online documentation or find reference pages by keyword • Syntax: man [[section] title] or: man [[-k keyword] | [-f filename]] • Examples: clyde% man ps clyde% man -k compile clyde% man -f /var/spool/mail clyde% man link clyde% man 2 link clyde% man 8 link __________________________________________________________________________________19__

  20. apropos • Locate commands by keyword lookup • Syntax: apropos keyword • Example: clyde% apropos compiler • Note: apropos is no different than man -k __________________________________________________________________________________20__

  21. More commands There are three vital things to know when you're working on a Linux system: • Who am I? • Where am I? • What am I? $ whoami $who am i $ pwd (print working directory) $hostname (Displays the System Name ) $uname –a Try this commands now! __________________________________________________________________________________21__

  22. whatis • Displays a one line summary about a command • Syntax: whatis command • Example: clyde% whatis vi __________________________________________________________________________________22__

  23. show ProcesSes - ps • Displays the status of current processes • Syntax: ps [ [-] acCegjklnrSuUvwx] [-tx] | [num] [kernel-name] [c-dump-file] [swap-file] • Default is to display only processes with your effective user ID • We will only use the following options: • a - include processes that are not owned by you • x - show processes that don’t have a controlling terminal • r - show only running processes • Example: clyde% ps -a __________________________________________________________________________________23__

  24. Print Working Directory - pwd • Displays the pathname of the current working directory • Syntax: pwd • Example: clyde% pwd /home/clyde/krf clyde% __________________________________________________________________________________24__

  25. Accessing Files and Directories • The File System • Directory Paths • Navigating the File System • Listing Directory Contents __________________________________________________________________________________25__

  26. The LINUX File Hierarchy __________________________________________________________________________________26__

  27. Function of Directories • There are four ways in which directories are created in Linux: • By the OS during installation. • By and application during its installation. • By the system administrator. • By users. __________________________________________________________________________________27__

  28. Directory Structure • A pathname specifies the location of a file on disk. • Every file and directory on a system has a pathname. • The ‘/’ separates file and directory names in a pathname. • What is the pathname of the file pointed to by the red arrows? __________________________________________________________________________________28__

  29. Types of Pathnames • Absolute Pathname • Specifies the location of a file in relation to the entire file system. • Starts with the root (‘/’) directory. • Relative Pathname • Specifies the location of a file in relation to the current directory. • Can get to a file or directory in the current directory by simply using its name. • Does not start with ‘/’. __________________________________________________________________________________29__

  30. Absolute path of directory john /users/john/work __________________________________________________________________________________30__

  31. Relative pathname from work to play ../play __________________________________________________________________________________31__

  32. Linux Command-Line Syntax Rules __________________________________________________________________________________32__

  33. Displaying the Current Directory • Use the pwd (“Print Working Directory”) command to get the absolute pathname to the current directory. __________________________________________________________________________________33__

  34. Changing Directories Using the cd Command • Use the cd (“Change Directory”) command to move to a different directory in the file system. • Accepts absolute or relative pathnames. • Navigation shortcuts and timesavers. • cd or cd ~ • Change to the user’s home directory. __________________________________________________________________________________34__

  35. Changing Directories Using the cd Command • Navigation shortcuts and timesavers continued. • . (dot) • The current directory. • .. (dot dot) • The parent directory. • ~username • Shortcut to another user’s home directory. __________________________________________________________________________________35__

  36. The ls Command • Gives a listing of the contents (files and directories) of a directory. • Syntax: ls [-option(s)] [pathname(s)] • With no options you get a “wide” listing. • Sorted alphabetically by default. • This is the way to find out what is in your file system. __________________________________________________________________________________36__

  37. Displaying Hidden Files • Any file whose name begins with a ‘.’ is a hidden file in Linux. • Not shown with ls by default. • The links to ‘.’ and ‘..’ are hidden files. • To see hidden files in Linux, use ls –a to show “all” files. • Use ls –Ato show all files except ‘.’ and ‘..’. __________________________________________________________________________________37__

  38. Displaying File Types • Use ls –F to get a “wide” listing with indicators as to the type of each file. __________________________________________________________________________________38__

  39. Displaying a Long Listing • ls –l • This gives a “long” listing of directory contents. • Sorted alphabetically by default. Can use ls –lt to sort by time. __________________________________________________________________________________39__

  40. File Types with ls -l • The “long” listing shows the file type at the far left of the listing. • Most common are ‘-’ for a regular file and ‘d’ for a directory. __________________________________________________________________________________40__

  41. Listing Individual Directories and Subdirectories • Use ls –ld to find out information about a directory itself, not the contents of it. • You can use the “recursive” option with ls, ls –R to list a directory and all of its subdirectories. • Can produce a lot of output. • -r and –R are used with many Linux commands. __________________________________________________________________________________41__

  42. Getting Around • You can move around from directory to directory using the cdcommand. Give the name of the directory you want to move to, or give no name to move back to your home directory. Use the pwd command to see where you are (or rely on the prompt, if configured): $ cd $ pwd $ cd / $ pwd $ cd /home $ ls –F $ cd ~ $ pwd $ cd .. $ pwd Try this commands and tell what “/”, “~” and “..” symbols mean? • Each directory contains two special hidden • directories named "." and "..". • "." refers always to the directory in which • it is located. • ".." refers always to the parent of the • directory. __________________________________________________________________________________42__

  43. Exercise: Exploring the filesystem Take a tour of the directory system, hopping one or many steps at a time, with a mixture of cd and pwd commands. Go to your home directory. Enter cd Find your working directory. Enter pwd Change to new working directory. Enter cd /etc List files in new working directory. Enter ls Change directory to root and list files. Enter cd /; ls Change to a new directory. Enter cd usr Give a wrong pathname. Enter cd xqk Change to a new directory with its absolute pathname. Enter cd /etc List files in another directory. Enter ls /bin Find your working directory (notice that ls didn't change it) Enter pwd Return to your home directory. Enter cd __________________________________________________________________________________43__

  44. Using echo to display text on the terminal • The echo utility copies to the terminal anything you put on the command line after echo. $ echo Hi Hi $ echo Hello World! Hello World! $ echo date date $ echo ”date” date $ echo ’date’ date $ echo `date` __________________________________________________________________________________44__

  45. Using echo to display text on the terminal $ ls memo memo.0714 practice $ echo Hi Hi $ echo This is a sentence. This is a sentence. $ echo star: * star: memo memo.0714 practice $ ` __________________________________________________________________________________45__

  46. Copy file cp cp source-file destination-file $ cd $ cat > file1 This is a source file named file1 Ctrl+D $ ls $ cp file1 file2 $ ls $ cp file2 file2.0130.week2 $cd $cp ~volin/cos231/memo01. File manipulation commands (copy) __________________________________________________________________________________46__

  47. File manipulation commands (rename) Changing the name of the file mv mv existing-file new_file $ mv file1 file1.week1 $ ls __________________________________________________________________________________47__

  48. The lpr Command • Prints a File • The lpr (line printer) utility places one or more files in a print queue for printing. • you can use the –P option to instruct lpr to place the file in the queue for a specific printer • $ lpr report You can see what jobs are in the print queue by using the lpq utility: lprm utility to remove the job from the print queue and stop it from printing $ lprm 86 __________________________________________________________________________________48__

  49. The wc Command • Displays line, word, byte, or character counts for a text file. • wc [option(s)] [filename(s)] • Displays line, word and byte count with no options given. __________________________________________________________________________________49__

  50. grep to Find a String $ cat memo01 $ grep homework memo01 $ grep –v homework memo01 The –w option causes grep to match only whole words Examples of wc(word count) command – print the numbers of bytes, words and lines in file $ wc memo01 $ wc –w memo01 $ wc –c memo01 $ wc –l memo01 More commands … __________________________________________________________________________________50__

More Related