Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unix Fundamentals - Part ii

Similar presentations


Presentation on theme: "Unix Fundamentals - Part ii"— Presentation transcript:

1 Unix Fundamentals - Part ii
UNIX II Unix Fundamentals - Part ii 31-Aug-98 1 1

2 Unix File System The tree representing the file structure is usually pictured upside down, with its root (/) at the top; At the end of each path is an ordinary file or a directory file; Ordinary files (called files), are at the end of each path and cannot support other paths; Directory files (called directories), are the points where other paths branch off from; Directories directly connected by a path are called parents (closer to root), and children (farther from the root). 31-Aug-98 3 3

3 Unix File System Filenames: Every file has a filename;
System V allows a maximum length of 255 alphanumeric characters; characters to choose from: uppercase letters [ A-Z ]; lowercase letters [ a-z ]; numbers [ 0-9 ]; underscore [ _ ]; period [ . ]; comma [ , ]. The only exception is the root directory, called /. 31-Aug-98 3 3

4 Unix File System Filename Extensions:
Typically file extensions help to describe the content of the file; a file extension is the part of the filename following an embedded period; Example: compute.c a C program source code; compute.o the object code for the program; compute the same program as an executable; memo memo text file, with date as file extension. Use file extensions freely to make filenames easy to understand. 31-Aug-98 3 3

5 Unix File System Invisible Filenames:
A filename beginning with a period [ . ] is called an invisible file, since ls does not normally displays it; Startup files are usually named starting with a period, so they do not clutter the display; There are two special invisible entries, called . and .., that appear in every directory; 31-Aug-98 3 3

6 Unix File System Absolute Pathnames: Every file has a pathname;
The file pathname describes the position of the file in the complete file structure; To describe a file pathname: start the description with the root; trace throughout the file structure the subset of directories that ends with the sub-directory where the file in question resides; string all the directory names in the path together, separating their names with slashes [ / ]; add the filename at the end of the string. 31-Aug-98 3 3

7 Unix File System Directories: Working directory:
Once one has logged in on a Unix OS, one will always be associated with a directory or another. The shell always points to a directory; The directory you are associated with, or are working in, or the prompt is waiting at, is called the working directory, or the current directory; To access any file in the working directory, one does not need a pathname. To access a file in any other directory, one needs the pathname to that file. The pwd (print working directory) utility display the pathname of the working directory; 31-Aug-98 3 3

8 Unix File System Directories: Working directory: 31-Aug-98 3 3

9 Unix File System Directories: Home directory:
When you first login on a Unix OS, the working directory is the account’s home directory. To display the absolute pathname, use the pwd utility just after you login; 31-Aug-98 3 3

10 Unix File System Listing Directories:
The ls (list) utility is used to list the contents (files & sub-directories) of a directory; Syntax: ls [ -aAcCdfFgilLqrRstu1 ] filename ... If ls is used with no options, the utility displays the contents of current working directory; 31-Aug-98 3 3

11 Unix File System Listing Directories:
To get other directory contents, follow ls with the appropriate name of the sub-directory to see; To see the contents of sub-directory desktop: 31-Aug-98 3 3

12 Unix File System Other Options when Listing Directories:
-s (size): Gives the size of the file in blocks; -a (all): Lists all entries; -c (change): Use time of last edit (or last mode change) for sorting or printing; -d (directory): If argument is a directory, list only its name (not its contents); often used with -l to get the status of a directory; -l (list): Lists in long format, giving mode, number of links, owner, size in bytes, and time of last modification for each file; -g (group): Shows group ownership of the file in a long output. 31-Aug-98 3 3

13 Unix File System Other Options when Listing Directories: example:
31-Aug-98 3 3

14 Unix File System Creating Directories
the mkdir utility creates a directory; Syntax: mkdir [-p] dir_name dir_name is the pathname for the new directory; -p flag allows missing parent directories to be created as needed. mkdir creates automatically two entries in the directory: . represents the directory itself, and is synonymous with the pathname of the working directory; .. represents the parent of directory, and is synonymous of the parent of the working directory. 31-Aug-98 3 3

15 Unix File System Changing to Another Working Directory:
The cd (change directory) utility makes another directory the working directory; Without an argument, cd makes the home directory (as you logged in) the working directory. 31-Aug-98 3 3

16 Unix File System Deleting A Directory:
The rmdir (remove directory) utility deletes a (sub) directory; A (sub)directory that contains sub-directories, or files cannot be deleted. If need to delete such directory, first delete all files (entries) in it, using rm utility; No need to delete entries . and .. To remove a file, you must have write per-mission in its directory; but you do not need read or write permission on the file itself. 31-Aug-98 3 3

17 Unix File System Deleting Files:
the rm (remove) utility deletes files from a directory; Syntax: rm file_name the rm command is irreversible! Be sure you know what is to be deleted... 31-Aug-98 3 3

18 Unix File System Reading Files:
The cat (concatenate) utility is used to conca-tenate & display files; example: 31-Aug-98 3 3

19 Unix File System Reading Files:
the pg (page) utility is designed to make it easier to look through long files; 31-Aug-98 3 3

20 Unix File System Reading Files:
One of the command added to Unix System V, Release 4.0, was the BSD command more, a very powerful utility to read files; Syntax: more file_name; the keys are: [Enter] advances the screen one line [d] advances the screen eleven lines [spacebar] advances one full screen [b] back one full screen [h] help screen [q] Quit 31-Aug-98 3 3

21 Unix File System Reading files: 31-Aug-98 3 3

22 Unix File System Reading Files: On-line Help for more... 31-Aug-98 3 3

23 Unix File System Moving Files:
The mv (move) utility can be used to move files from one directory to another; Syntax: mv [ - ] [ -fi ] filename1 filename2 mv [ - ] [ -fi ] directory1 directory2 mv [ - ] [ -fi ] filename ... directory One side effect of mv is to rename a file or directory; mv takes either absolute or relative pathnames; mv refuses to move a file or directory onto itself. 31-Aug-98 3 3

24 Unix File System Access Permissions:
Three type of users may access a file: the owner of the file (owner); a member of a group to which the owner belongs; everyone else (other or world). A user can attempt to access a file by trying to: read from file; write to file; execute file. When using ls -l command, the access permissions for a file are displayed. 31-Aug-98 3 3

25 Unix File System example: 31-Aug-98 3 3

26 Unix File System Let us examine the following: Lines contain:
-rw-rw-r-- 1 user Jul 22 21:21 cshrc.old drwxrwxr-x 28 user Oct desktop/ -rw-rw-r-- 1 user Jul 27 23:19 mar.1997 -rw-rw-rw- 1 user May 8 09:26 textitem.txt Lines contain: type of file - first character; file’s access permissions - next nine characters; number of links to file name of file owner - account that created the file; size of file - bytes; date & time of last modification; name of file. 31-Aug-98 3 3

27 Unix File System If the first character is a d, the file is a directory; if the character is a -, is an ordinary file - see and compare cshrc.old & desktop/; the next three characters represent the owner’s permissions - see rw- for march.1997; the next three characters represent the group’s permissions - see rw- for march.1997; the last three characters represent the world’s permissions - see r-- for march.1997; Note that desktop/ directory has “executable” permission (w) for all type of users, indicating that owner, group & world have access (listing and searching) of that directory. 31-Aug-98 3 3

28 Unix File System Changing access permissions:
The owner of a file controls which user type have permission to access the file and how they can access it; To change the access permissions for a file, the owner can use the chmod command; The chmod utility can add (+) or remove (-) read (r), write (w), or execute (x) permissions for all users (a), the group (g), and others (o); This system access permission scheme lets the file owner give other users access to the files & directories to be shared, and keep others private. 31-Aug-98 3 3

29 Unix File System 31-Aug-98 3 3

30 Unix File System Directory Access Permissions:
Access permissions have a different meaning when applied to directories; Directories can be read (r), or written to (w), but it can never be executed; Execute (x) means the user can search through & list the contents of the directory - far from the meaning executing a file... 31-Aug-98 3 3

31 Unix File System Links:
A link is a pointer to a file. Every time we create a file using an editor, or copying from another file, we are adding a pointer in a directory; The pointer associates a filename with a place on the disk; When we specify a filename in a command or utility, we are pointing to the place on the disk where the data that we want is (to be) located. 31-Aug-98 3 3

32 Unix File System Links:
Sharing files can be useful if two or more people are working on a project and need to share some common data; A file owner can make it easier to other users to access file by creating additional links (pointers) to the file(s); To share a file with another user(s), the owner must give read & write (+rw) permissions to that file, by using the chmod command; In addition, the file owner may have to change access (+rwx) to the parent directory of the file. 31-Aug-98 3 3

33 Unix File System Example: it makes sense to create links between the individual To_Do lists by topics and a joint To_Do subdirectory with topics. 31-Aug-98 3 3

34 Unix File System Creating links:
The ln (link) utility creates an additional link to an existing file. The link appears as another file in the another directory in the file structure; Example: assume that /usr/jenny is the working directory, and Jenny is creating a link to the file draft. The new link will appear in the /usr/alex directory, and the filename is letter: /usr/jenny [20]% ln draft /usr/alex/letter 31-Aug-98 3 3

35 Unix File System Creating Links: 31-Aug-98 3 3

36 Unix File System Creating Links:
the ln utility creates an additional pointer to an existing file. It does not make create another file. Because is a single file, the file status information is the same for all links. Only the filename differ; Changes in one file will be reflected immediately under the other name! 31-Aug-98 3 3

37 Advanced Unix Commands
du - Disk Usage /usr/bin/du [ -adkr ] [ -s | -o ] [ file ... ] /usr/xpg4/bin/du [ -a | -s ] [ -krx ] [ file ... ] The du utility displays the size of the space allocated to each file & the size of the file space allocated to each subdirectory of the file hierarchy rooted in each of the specified files. The du output consists of the amount of space allocated to a file and the name of the file. Note: A file with two or more links is counted only once. If there are links between files in different directories on separate branches of the file system, du will count the excess files more than once. 31-Aug-98 3 3

38 More Unix Commands du - Disk Usage Options:
-a In addition to the default output, reports the size of each file not of type directory in the file hierarchy rooted in the specified file. Regardless of the presence of the -a option, non-directories given as file operands will always be listed. -k Write the files sizes in units of 1,024-bytes, rather than the default of 512-byte units. -s Instead of the default output, reports only the total sum for each of the specified files. 31-Aug-98 3 3

39 More Unix Commands du - Disk Usage Options:
-d Do not cross filesystem boundaries. "du -d /" would report usage only on the root partition, for example. -o Do not add child directories' usage to a parent's total. Without this option, the usage listed for a particular directory is the space taken by the files in total, as well as the files in all directories beneath it. This option does nothing if -s is used. -r Generate messages about directories that cannot be read, files that cannot be opened, and so forth, rather than being silent (the default). 31-Aug-98 3 3

40 More Unix Commands id - return user identity /usr/bin/id [-a] [ user ]
/usr/xpg4/bin/id -g [ -nr ] [ user ] /usr/xpg4/bin/id -u [ -nr ] [ user ] If no user operand is provided, the id utility will write the user & group IDs and the corresponding user & group names of the invoking process to standard output. If the effective & real IDs do not match, both will be written. If multiple groups are supported by the underlying system, the supplementary group affiliations of the invoking process also will be written. 31-Aug-98 3 3

41 More Unix Commands id -: return user identity
If a user operand is provided and the process has the appropriate privileges, the user & group IDs of the selected user will be written. In this case, effective IDs will be assumed to be identical to real IDs. If the selected user has more than one allowable group membership listed in the group database, these will be written in the same manner as the supplementary groups described before. 31-Aug-98 3 3

42 More Unix Commands df - report number of free disk blocks & files
/usr/bin/df [-F FSType][-abegklntV][-o FSType-specific_options][directory | block_device|resource ... ] The df command displays the amount of disk space occupied by mounted or unmounted file systems, directories, or mounted resources, the amount of used and available space, and how much of the file system's total capacity has been used. 31-Aug-98 3 3

43 More Unix Commands df - report number of free disk blocks & files
-a Report on all file systems including ones whose entries in /etc/mnttab have the ignore option set; -b Print the total number of kilobytes free; -e Print only the number of files free; -F FSType Specify the FSType on which to operate. This is only needed if the file system is unmounted. The FSType should be specified here or be determinable from /etc/vfstab have the by matching the directory, block_device, or resource with an entry. 31-Aug-98 3 3

44 More Unix Commands ps - report process status
ps [ -aAcdefjl][ -g grplist] [ -n namelist][[ -o format] ...] [ -p proclist][ -s sidlist][ -t term][ -u uidlist][ -U uidlist ] [ -G gidlist ] The ps command prints information about active processes. Without options, ps prints information about processes associated with the controlling terminal. The output contains only the process D, terminal identifier, cumulative execution time, and the command name. Otherwise, the information that is displayed is controlled by the options below. 31-Aug-98 3 3

45 More Unix Commands ps - report process status
-d Print information about all processes except session leaders; -e Print information about every process now running; -f Generate a full listing. (See below for significance of columns in a full listing); -g grplist List only process data whose group leader's ID number(s) appears in grplist. (A group leader is a process whose process ID number is identical to its process group ID number); 31-Aug-98 3 3

46 More Unix Commands ps - report process status
-G gidlist Write information for processes whose real group ID numbers are given in grouplist. The grouplist must be a single argument in the group ID numbers are given in grouplist. The grouplist must be a single argument in the form of a blank- or comma-separated list; -j Print session ID and process group ID; -l Generate a long listing; -n namelist Specify the name of an alternative system namelist file in place of the default. This option is accepted for compatibility, but ignored; 31-Aug-98 3 3

47 More Unix Commands sync - update the super block
sync executes the sync system primitive. If the system is to be stopped, sync must be called to insure file system integrity. It will flush all previously unwritten system buffers out to disk, thus assuring that all file modifications up to that point will be saved. 31-Aug-98 3 3

48 More Unix Commands elm: an interactive mail system
elm [ -achkKmrtwz ] [ -f alternate-folder ] [ -d debug-level] elm [ -s subject] list of aliases or addresses elm is an interactive character-based, screen-oriented mailer program that supersedes mail & mailx. There are three main ways to use the elm mailer: First way: Use the mailer to specify a list of addresses on the command line when the mailer is invoked. This will allow sending of a single message to the specified recipients with all the options usually available in the elm system itself. 31-Aug-98 3 3

49 More Unix Commands elm: an interactive mail system
For example, the command elm -s testing joe would initiate the sending of a message to the alias joe with the subject testing indicated and would put you into an editor for you to enter the text of the message. If the subject flag and argument were not present, you would be prompted for a message subject. Second way: used most commonly when transmitting files and such, is to specify the subject of the message and the recipients using the command line and redirect a file as standard input. For example, the command elm -s testing joe < test.c would mail a copy of the file test.c to alias joe, with the subject testing indicated. The subject flag and argument are optional. 31-Aug-98 3 3

50 More Unix Commands elm: an interactive mail system
Third way: elm is invoked with neither subject nor addresses specified on the command line and without standard input redirected. You can then read any messages in your addresses specified on the command line and without standard input redirected. You can then read any messages in your incoming mailbox (or specified folder), reply to messages in the mailbox, mail messages, etc. 31-Aug-98 3 3

51 More Unix Commands 31-Aug-98 3 3

52 More Unix Commands joe: text editor 31-Aug-98 3 3

53 More Unix Commands tracerouter - prints the route packets take to reach network host; traceroute [ -m max_ttl ] [ -n ] [ -p port ] [ -q nqueries ] [ - r ] [ -s src_addr ] [ -t tos ] [ -v ] [ -w waittime ] host [ packetsize ] The Internet is a large and complex aggregation of network hardware, connected together by gateways. Tracking the route one's packets follow (or finding the miscreant gateway that's discarding your packets) can be difficult. Traceroute utilizes the IP protocol `time to live’ (TTL) field and attempts to elicit an ICMP TIME_EXCEEDED response from each gateway along the path to some host. 31-Aug-98 3 3

54 More Unix Commands tracerouter - prints the route packets take to reach network host; traceroute [ -m max_ttl ] [ -n ] [ -p port ] [ -q nqueries ] [ - r ] [ -s src_addr ] [ -t tos ] [ -v ] [ -w waittime ] host [ packetsize ] The only mandatory parameter is the destination host name or IP number. The default probe datagram length is 38 bytes, but this may be increased by specifying a packet size (in bytes) after the destination host name. 31-Aug-98 3 3

55 More Unix Commands 31-Aug-98 3 3

56 More Unix Commands 31-Aug-98 3 3

57 More Unix Commands telnet - user interface to a remote system using the TELNET protocol telnet [ -8ELcdr ] [ -e escape_char ] [ -l user ] [ -n file ] [ host [ port ] ] telnet communicates with another host using the TELNET protocol. If telnet is invoked without arguments, it enters command mode, indicated by its prompt telnet>. In this mode, it accepts and executes its associated commands. If it is invoked with arguments, it performs an open command with those arguments. 31-Aug-98 3 3

58 More Unix Commands telnet - user interface to a remote system using the TELNET protocol telnet [ -8ELcdr ] [ -e escape_char ] [ -l user ] [ -n file ] [ host [ port ] ] Once a connection has been opened, telnet enters input mode. In input mode, text typed is sent to the remote host. The input mode entered will be either "line mode," "character at a time," or "old line by line," depending on what the remote system supports. 31-Aug-98 3 3

59 More Unix Commands 31-Aug-98 3 3

60 More Unix Commands ftp - file transfer protocol
Created in 1970s for use by programs, FTP transfers files in different formats, optimized for fast transfer of large files; FTP clients are designed specifically for efficient transfer of files across the networks, recognizing a variety of host computer types; FTP client creates a virtual connection computer- to-computer, and files are retrieved from a named directory; 31-Aug-98 3 3

61 More Unix Commands ftp - file transfer protocol 31-Aug-98 3 3


Download ppt "Unix Fundamentals - Part ii"

Similar presentations


Ads by Google