1 / 73

Introduction to Linux

Introduction to Linux. Instructor: Bennett M. Tanyag UNIT - 2. UNIT 2: Using the Linux System. Learning Objective To learn how to log in and out To understand the command format To learn about input and output redirection To learn to use some basic commands

easter
Télécharger la présentation

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 Instructor: Bennett M. Tanyag UNIT - 2

  2. UNIT 2: Using the Linux System • Learning Objective • To learn how to log in and out • To understand the command format • To learn about input and output redirection • To learn to use some basic commands • To understand the usage of pipes and filters

  3. Logging in and out • Users identify themselves to the system through the login procedure. • Every Linux system has a system administrator who administers, monitors and manages the system. • The system administrator creates accounts and provide login names for the accounts. • The administrator also provides the initial password for every account • Each user of the system is identified with a unique account. • The users are identified by their login name, and protection is provided through user passwords.

  4. Logging in and out • A typical login prompt looks like this: mycomputer login: • mycomputer is the name of the computer • Every computer is uniquely identified ba a name given to it. • The user enters the login name Linus and immediately the password prompt is shown as mycomputer login: Linus password: • The password entered is not echoed to the screen • If the password is incorrectly entered, a message appears login incorrect

  5. Logging in and out • UNIX systems are case sensitive systems • User is logged in to the system, when both the login name and password match • The space where the user is logged into is called as the home directory • When a user logs in, the command prompt appears as follows /home/linus • The above is the home directory of the user. • The shell is now in command, waiting to take input from the user • The default shell is the bash (Bourne Again Shell) • Other shells are csh (C shell), ksh (Korn shell), sh (shell) and tcsh (enchanced C shell).

  6. Logging in and out • Before leaving the system, it is important that we log out of the system. • This can be accomplished by typing either • Logout • Exit • Ctrl-d • Anyone of the above can be used to log out of the system. • Remember to log out always to prevent other users from messing around with your files.

  7. Command Format • A command is a program that does a specific job • There are hundreds of commands and most of them have options available, yielding thousands of possibilities. • The command man, meaning manual pages, is used to find the details about each command • To run even the man command we need to know the structure of a Linux command line command –opn1, opn2 …,arg1, arg2… argn • Where • Command is the command name • Opn1 to Opnn are the range of n options possible for that command • Arg1 to argn are the range of n arguments that may be passed to the command.

  8. passwd command • The command to change the password is passwd. /home/Linus$ passwd Changing password for Linus (current) UNIX password: Torvalds New Unix password: Helsinki Retype new Unix password: Helsinki /home/Linus$ • The password entered by the user cannot resemble the old password • Some of the error messages given by the system are: • BAD PASSWORD: is too similar to the old one. • BAD PASSWORD: it is too short • BAD PASSWORD: is too simple

  9. BASIC UNIX COMMANDS • To execute a UNIX command, simply type the name of the command at the UNIX prompt (much like in DOS) followed by the Enter or Return key (). Some basic UNIX commands: 1. date The date command gives the user the current date and time. Only the system administrator (or the superuser) can change the system date and time. Example : $ date  Mon Oct 25 19:24:50 PST 1993

  10. BASIC UNIX COMMANDS • clear The clear command will simply clear the screen and move the $ prompt to the upper left-hand corner of the screen. This is similar to the cls command in DOS.

  11. BASIC UNIX COMMANDS • who The who command gives a list of users currently logged in the system. The output will give the user name or account name together with the TTY or terminal number (the exact terminal being used by the user). Example : $ who  root tty0 user1 tty17 user5 tty6 mitch tty8

  12. BASIC UNIX COMMANDS • whoami The whoami command gives the account name of the user currently logged in at a particular terminal. For example, if someone happens to see a terminal left on with someone logged in, typing whoami at the prompt will give the account name of that user. Example : $ whoami  mitch

  13. BASIC UNIX COMMANDS • bc The bc command will enable user to access the on-line calculator of UNIX. Example: $ bc  13 + 18  31 2 * 8  16 <^D> $ _

  14. BASIC UNIX COMMANDS • cal or cal year or calmonthyear The cal command gives the user the calendar for the current month and year. The calyear command will give the user the whole calendar for the year specified. The calmonthyear command will give the calendar for the specified month and year.

  15. BASIC UNIX COMMANDS • Example : $ cal  July Sun Mon Tue Wed Thu Fri Sat 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

  16. BASIC UNIX COMMANDS • banner The banner command prints large letters on screen. Example: $ banner HI # # # # # # # # # # # # # # # # # # # # # # # # # #

  17. BASIC UNIX COMMANDS • ls command The ls (list) command lists the name of files in a given directory. Typing ls without any option and argument at the prompt gives the user a listing of the files in columns and in alphabetical order. Example: $ ls  arithmetic chapter1.doc eric.let figures memo.to.henry report.1 sample.c test.program.c

  18. BASIC UNIX COMMANDS • Some options and arguments of the ls command: The l option gives a long listing of the files that includes information such as the size of the file, the owner of the file, the date and time the file was last modified, etc. Example: $ ls -l  -r-xr-xr-x 1 linus staff 4222 Jan 13 11:10 arithmetic -rw-r----- 1 linus staff 512 Dec 1 8:00 chapter1.doc -rw-rw-r-- 1 linus staff 1020 Feb 9 10:15 eric.let drwx------ 2 linus staff 2023 Jun 4 9:31 figures

  19. BASIC UNIX COMMANDS • The a option gives a listing of all the files including hidden files (those which start with a ".") Example: $ ls -a  . .. .profile .sh_history arithmetic chapter1.doc eric.let figures memo.to.henry report.1 sample.c test.program.c In some UNIX versions, the ls command will list the files one line per file. Use the C option to list the files by columns.

  20. BASIC UNIX COMMANDS • The ls command can also have arguments. Example: $ ls arithmetic  arithmetic $ ls *.c  sample.c test.program.c

  21. The ls command can also have a combination of arguments and options. $ ls -l sample.c  -rw-r--r-- 2 linus staff 20432 Oct 25 10:30 sample.c

  22. Multiple Options The rule of separation can be applied in case of multiple options. A dash "-" symbol should precede an option and a space should separate each option. Example: $ ls -a -l This will give you a long listing of all the files.

  23. A user may also combine multiple options in a single dash symbol. Example: $ ls -al Take note that there should be no space between the a and the l. Also, the ordering of the options is not important. Therefore, ls -l -a and ls -la will also work.

  24. Multiple Argunments The rule of separation is also applicable in case of multiple arguments. A space separates one argument from another. Example: $ ls -l arithmetic eric.let sample.c

  25. Multiple Commands A user may enter several commands at a single UNIX prompt. In such a case, a semi-colon (;) delimits each command unit. The commands will then be executed consecutively. Example: $ ls; ls -a; ls -l

  26. UNIX FILENAMES UNIX filenames can have fourteen (14) characters consisting of letters, numbers, periods, and/or dashes. UNIX filenames do not follow the concept of file extensions as in DOS. In other words, the period is just like an ordinary character. Example: letters.to.me and c.prog.linus are valid UNIX filenames UNIX filenames are case sensitive unlike in DOS Example: payroll.1994, PAYROLL.1994, and Payroll.1994 are all different filenames in UNIX.

  27. WILD CARDS • Like in DOS, UNIX also uses wild cards in selecting certain files to be operated on. • In UNIX systems have 3 wild cards, these are: • * asterisk • ? Question mark • [ ] brackets

  28. 1. The Asterisk "*" The asterisk wild card will match any number of characters that occur at the designated position in the pattern. Examples: 1. ch* represents all filenames that start with ch followed by any number of characters. $ ls ch*  chapter1 change.doc cherry_text 2. *er represents all filenames that start with any number of characters and end with an er. $ ls *er  files.october system.ver

  29. 3. *itch* represents all filenames that start with any number of characters, followed by the string itch and then followed by any number of characters again. $ ls *itch*  ritchie.doc itchy.let mitch.let In DOS, *.* represents all files (any name and any extension). This is not applicable in UNIX since there are no such things as file extensions. Instead, *.* will be interpreted by UNIX as any file with a period in its filename. To represent all files in UNIX, just simply type *.

  30. 2. The Question Mark "?" Like in DOS, the question mark will match any single character. Examples: 1. ?ark represents all filenames that start with any single character followed by the string ark. $ ls ?ark  mark lark 5arkark

  31. 2. henry? represents all filenames that start with the string henry and ends with any single character. $ ls henry?  henry1 henry2 henryx henry 3. letter?.doc represents all filenames that start with the string letter, followed by any single character, and then followed by the string doc. $ ls letter?.doc  letter1.docletters.doc letter.doc

  32. The Square Brackets "[ ]" The square brackets are similar to the question mark in the sense that it will match any single character. However, square brackets provide the user with options in choosing the character. Examples: 1. letter[246].doc represents all filenames that start with the string letter, followed by either a 2, 4, or 6, and then followed by the string.doc. $ ls letter[246].doc  letter2.docletter4.docletter6.doc

  33. 2. memo_[a-c] represents all filenames that start with the string memo_ followed by any letter from a to c. $ ls memo_[a-c].doc  memo_a.docmemo_b.docmemo_c.doc 3. letter[3-5] represents all filenames that start with the string letter followed by any number from 3 to 5. $ ls letter[3-5]  letter3 letter4 letter5

  34. 4. message[4-6m-o] represents all filenames that start with the string message followed by any number from 4 to 6 or any letter from m to o. $ ls message[4-6m-o]  message4 message5 message6 messagem messagen messageo

  35. 5. notice[1-2][b-d] represents all filenames that start with the string notice followed by any number from 1 to 2 and then by any letter from b to d. $ ls notice[1-2][b-d]  notice1b notice1c notice1d notice2b notice2c notice2d 6. element[!5-9] represents all filenames that start with the string element and NOT followed by any number from 5 to 9.

  36. UNIX FILE SYSTEM • The UNIX File System organizes all files into a single hierarchy of directories just like in DOS. In fact, DOS copied its directory structure from UNIX. The highest directory level is called the root (/). Take note that DOS represents its own root directory by a backward slash (\).

  37. The root directory contain numerous subdirectories, many of which are standard in UNIX systems. Some of UNIX’s important subdirectories are: 1.bin contains the executable programs that make up most of the important UNIX system commands 2.etc contains important system administration programs and data files 3.lib contains some of the libraries that programming language compilers use

  38. 4. dev contains UNIX device files 5. tmp contains temporary files to hold data for a short period of time 6. usr contains files of general use to the users of a UNIX system

  39. Path • A file could be in any directory and its location is called its path. • a chain of directory names that tell UNIX how to find a particular file An Absolute Path traces the location of the file from the root directory Examples: /usr/linus/docs/mydoc /usr/linus/letters/letter1

  40. A Relative Path traces the location of the file starting at the current working directory Examples: Assuming that the current working directory is docs: ../letters/letter1 ../letters/letter2

  41. Files and Directories • What are files? • Everything in UNIX is a file • A file is sequence of bytes • Files a re placeholders for data • Data can be simple ASCII text, formatted documents, source, programs, executable files, pictures etc.

  42. What are Directories? • A directory is a placeholder for files. • Directories can hold any kind of files. • UNIX directory is a special kind of file that maintains a list of all the files in it. • The organizational scheme is powerful, as a file in a directory can be another directory. • This would be called a subdirectory of the original directory. • Directories are the branches of the tree and the files are the leaves of the tree. • As a tree has both internal and leaf nodes with a root at the top, in UNIX too we have a root that is the basis of the structure of directories and files.

  43. Typical representation of a directory / dir1 dir2 dir3 dir4 dir5 dir6 file2 file3 file1

  44. UNIX FILE OWNERSHIP AND SECURITY • In a multi-user environment like UNIX, each file has a designated owner. Example: $ ls -l  -r-xr-xr-x 1 Linus staff 4222 Jan 13 11:10 arithmetic -rw-r----- 1 Linus staff 512 Dec 1 8:00 chapter1.doc -rw-rw-r-- 1 Linus staff 1020 Feb 9 10:15 eric.let drwx------ 2 Linus staff 2023 Jun 4 9:31 figures Displayed above is a sample output of the ls -l command. There are eight (8) columns shown.

  45. Explanation of the ls-l Output -rw-rw-r-- 1 mitch staff 1020 Feb 9 10:15 eric.let Column Explanation First Security Access Modes Second Number of Links Third Owner of the File or Directory Fourth Group where the Owner belongs Fifth Size of the File Sixth Date the file was last modified Seventh Time the file was last modified Eight Name of the File or Directory

  46. What Security Access Mode means: • - r w - r w - r - - The security access mode consists of four components: First Character A “d” means this is a directory, while a "-" means this is just a regular file (text or executable file).

  47. Next Three The Security Access Mode for the owner of the file or directory. • Next Three The Security Access Mode for the group mates of the owner. • Last Three The Security Access Mode for the other users in the system who do not belong to the owner's group.

  48. The security modes • "r" stands for the read permission. This is for printing files, copying files, and displaying the contents of the file. For directories, this allows the user to list the files (by using the ls command) that are in the directory. Octal code is 4.

  49. The security modes • "w" stands for write permission. This is needed in order for the user to modify or update a file. For directories, this allows the user to create and delete files in the directory. Octal code is 2.

  50. The security modes • "x" stands for the execute permission. This is needed in order for a user to run or execute a program. It is not applicable for non-executable files such as ASCII text files. For directories, this allows the user to access the files in the directory. Without the execute permission, the write permission for a directory is useless. Octal code is 1.

More Related