You are on page 1of 9

All About UNIX

UNIX Fundamental UNIX: UNIX is a multiuser, multiprocessing operating system designed to facilitate programming, text processing, communication and many more tasks that are expected from an OS. It has three environments: Personal Environment Time-Sharing Environment Client/Server Environment

UNIX Structure: UNIX consists of four major components: 1. 2. 3. 4. USER USER SHELL The Kernel The Shell A standard set of utilities Application Program USER

Utilities

Application

KERNEL

Fig: Components of UNIX 1. The Kernel: The kernel is the heart of UNIX system. It contains the two most basic parts of the OS: process control resource management

2. The Shell: The shell is the part of UNIX that is most visible to the user. It receives and interrupts the commands entered by the user. Some standard UNIX shells are as follows: Bourne shell- developed by Steve Bourne at the AT&T Labs, C shell- developed in Berkeley by Bill Joy Korn shell-developed by David Korn at AT&T Labs Bash shell tcsh shell- a compatible version of C shell, used in Linux. There are two major parts of a shell: Interpreter: reads your commands and works with the kernel to execute them. Programming capability: it allows writing a shell (command) script. A shell script is a file that contains shell commands that perform a useful function, its known as shell program. 3. Utilities: A utility is a standard UNIX program that provides a support process for users. Three common utilities are: Text editors Search programs Sort programs 4. Applications: Applications are programs that are not a standard part of UNIX. Common Commands:

1. Date and time: date 2. Date and GMT time: date u 3. Calendar: cal 4. Whos online: who 5. Whos online with idle time and PID: who u 6. Whos online with idle time, PID along with header: who uH 7. For user id: whoami 8. Change command: passwd 9. Print message: echo 10. Online documentation: man 11. Online Documentation including information, including commands:
man k sort

12. Print: lpr 13. Terminal: tty 14. Clear screen: clear 2

15. Set terminal: stty 16. Set terminal with current terminal option settings: stty a 17. Display selected settings in a format that can be used as an argument
to another set terminal command: stty g

18. Set terminal with general configuration: stty sane 19. Set erase key: stty erase ^e 20. Set interrupt key:sty intr ^9 21. Record session: script 22. System name only: uname n 23. System OS name: uname s 24. System OS release: uname r 25. System name with OS and its release: uname sr 26. System name with all options: uname a 27. Calculator: bc
Basic vi Editor: The vi editor is a screen editor available on most UNIX systems. When one invoke the vi editor, it copies the contents of a file to a memory space known as a buffer. Once the data have been loaded into the buffer, the editor presents a screen full of the buffer to the user for editing. If the file does not exists, an empty buffer is created. The vi editor has three modes: Command mode Text mode Changing mode Basic vi commands:

1. Insert text before the current character: i 2. Insert text at the beginning of the current line: I 3. Appends text after the current character: a 4. Adds text at the end of the current line: A 5. Opens an empty text line for new text after the current line: o 6. Opens an empty text line for new text before the current line: O 7. Deletes the current character: x 8. Delete the current line: dd 9. Moves the cursor one character to the left: h, <=, Backspace 10. Moves the cursor one character to the right: l, =>, Spacebar 11. Moves the cursor to the beginning of the current line: 0 12. Moves the cursor to the end of the current line: $ 13. Moves the cursor one line up: k, 14. Moves the cursor one line down: j, 15. Moves the cursor to the beginning of the previous line: 16. Moves the cursor to the beginning of the next line: +, return 17. Joins two consecutive lines: J 18. Undoes only the last edit: u 3

19. Undoes all changes on the current line: U 20. Scrolls up one line: ctrl+y 21. Scrolls down one line: ctrl+e 22. Scrolls up half of a screen: ctrl+u ( u for up) 23. Scrolls down half of a screen: ctrl+d (d for down) 24. Scrolls up whole screen: ctrl+b (b for beginning) 25. Scrolls down whole screen: ctrl+f (f for finish) 26. Saves buffer contents to original file and continues: :w 27. Saves buffer contents to filename and continues: :w filename 28. Saves the contents of the buffer and exits: :wq, zz 29. Quit if contents have not been changed: :q 30. Exits vi without saving: :q!
File Syetems: Filename: A filename that starts with a period is a hidden file, generally used by a UNIX utility. Example of system hidden files are .profile, .mailrc, and .cshrc Wildcards: A wildcard is a token that specifies that specifies one or more different characters can be used to satisfy a specified request. In other words, wildcards are like blanks that can be filled in by any character. There are three wildcards in UNIX: The single character (?) wildcard The set ([]) wildcard The multiple character (*) wildcard File Types: UNIX provides seven types of file as figure shows:

Files

Regular

Directory

Character Special

Block Special

Symbolic Link

FIFO

Socket

Fig: Files in UNIX

Regular Files also known as ordinary files contain user data that need to be available for future processing. Regular files are two types: text file a file of characters drawn from the computers character set. UNIX computer use the ASCII character set. binary file is a collection of data stored in the internal format of the computer. There are two types of binary files: data files & program files. Data files contain application data & program file contain instructions that make a program work.

Directory Files that contains the names and the locations of all files stored on a physical device. Character Special Files represents a physical device, such as a terminal, that reads or writes one character at a time. Block Special Files represents a physical device, such as a disk, that reads or writes data a block at a time. Symbolic link Files is a logical file that defines the location of another file somewhere else in the system. FIFO Files A first-in-first-out, also known as a named pipe, is a file that is used for interprocess communication. Socket a special file that is used for network communication.

Directories: A directory is a file that contains the names and inodes of other files. There are four special directories that play an important role in the directory structure:

Root directory (/) is the highest level in the hierarchy. It is the root of the whole file structure; therefore, it does not have a parent directory. It belongs to the system administrator and can be changed by only the system administrator. Home directory (~) contains any files we create while in it and may contain personal system files such as our profile file and the command history. Working directory (.) is the one that we are in at any point in session. Working directory change when change our directory of work. Parent directory (..) is immediately above the working directory. When we are in our home directory, its parent is one of the system directories.

File Systems: A UNIX file system has four structural sections: Boot Block Super Block Inode Block Data Block

Fig: A Disk file format

Boot Block when an operating system is started, a small program known as the boot program is used to load the kernel into memory. The boot program, when present, is found at the beginning of a disk in the boot block. Super Block contains information about the file system. Stored here are such items as the total size of the disk, how many blocks are empty, and the lo0cation of bad blocks on the disk. Inode Block contains information about each file in the data block. The file information is stored in records known as

inodes. There is one inode for each file on the disk. They contain information about the file, most notably the owner of the file, its file type, permissions and address. Data Blocks contains several types of files. It contains all the user files, special files that are related to the user data as regular files, directory files, symbolic link files, and FIFO files. Finally, it contains character special, block special, and socket special system files. Links: A link is a logical relationship between a node and a file that relates the name of a file to its physical location. UNIX defines two types of links:

Hard links here the inode in the directory links the filename directly to the physical file. Symbolic links here the inode is related to the physical file through a special file.

List Commands:

1. Print working directory: pwd 2. List directory: ls 3. inode list: ls ai 4. Long list: ls l 5. List with all hidden files: ls a ~ 6. List directory: ls ld 7. List user and group ID: ls nd 8. List directory in reverse order: ls r 9. List with the basic time sort: ls -lt 10. List with sequence of last time access: ls lu 11. List with the inode date change: ls lc 12. List directories with a slash (/): ls p 13. Recursive list: ls Rp 14. Print one column: ls -1
Directory Commands:

1. 2. 3. 4. 5. 6.

Make directory: mkdir Make directory with mode: mkdir m Make parent directory: mkdir p Change directory: cd Change directory with home reference: cd ~ Remove directory: rmdir

File commands:

1. Create a file: vi, cat 2. Edit a file: vi, sed 6

Display Commands: 1. Display a file: mkdir 2. Clear screen before displaying: more c 3. Displays error message: more d 4. Does not screen wrap long lines: more f 5. Ignores form feed characters: more l 6. Squeezes multiple blank lines: more s 7. Display control characters: more r 8. Suppresses text underlining: more u 9. Waits at end of output for user to enter any key to continue: more w 10. Sets the number of lines in a screen: more lines 11. Starts output at the indicated line number: more nmbr 12. Locates first occurrence of pattern and starts output two lines before it: more +/ptrn 13. Display next screen of output: more space 14. Advance one line: more return 15. Display half of a screen: more d 16. Skips n screens and display a screen: more nf 17. Moves back n screens and display a screen: more nb 18. Displays the current filename and line number: more :f Operation commands: Copy: The copy commands have several modes:

Preserve Attributes Option When the designation file exists, its permissions, owner and group to be changed, however, by using the preserve (-p) option. Interactive Option We can guard a file being accidentally deleted by a copy command by using the interactive (-i) option. When the interactive option is specified, copy asks if we want to delete an existing file. Recursive Copy A collection of files can be copied using recursive copy (-r) option. While the wildcard copy copies the matching files in a directory, the recursive copy copies the whole directory and all of its subdirectories to a new directory. Wildcard Copy Wildcards can be used to copy files as long as the destination is another directory. Wildcard cant be used where the source and destination is same.

1. Copy command: cp 2. Copy using the preserve option: copy p 3. Copy using the interruption option: copy i 4. Recursive copy: copy r

Move: The move command (mv) used to move either an individual file, a list of files, or a directory. After a move, the old file name is gone and the new file name is found at the destination. Move has two options:

Interactive move If the destination file already exists, its contents are destroyed unless we use the interactive flag (-i) to request that move warn us. When the interactive flag is on, move asks if we want to destroy the existing file. Command: move i file1 file2 Force move When we want to write a file even if it already exists, we can skip the interactive message with the force (-f) option. Command: move f file1 file2.

Link: Link command receives either a file or directory as input, ant its output is an updated directory. Link has three options:

Symbolic link the default link is type hard. To create a symbolic link, the symbolic option (-s) is used. Interactive link if the destination file already exists, it contents are destroyed unless we request to be warned by using the interactive flag (-i). When the interactive flag is on, link asks if we want to destroy the existing file. Force when we are about to overwrite a file, we are asked if we want to destroy the file or not. If we are sure that we want to write it, even if it already exists, we can skip the interactive message with the force (f) option. Remove: The remove (rm) utility deletes an entry from a directory by destroying its link to the file. To delete a file, we must have the write permission of that file. There are three options for the remove command:

Force Removal Force removal (-f) works just like the forced

remove. The file will be removed even it is write protected as long as we have the write permission in the directory. Command: rm -f Recursive Removal The recursive removal (-r) removes all files and empty directories in the path from the source directory. Files are deleted first, then the directory, so a directory can have files before the remove command. Command: rm r Wildcard Remove Remove can be used with wildcards. It destroys everything without any notification. Command: rm r f*. Security and File Permission

You might also like