Unix_commands_theory
Upcoming SlideShare
Loading in...5
×
 

Unix_commands_theory

on

  • 452 views

 

Statistics

Views

Total Views
452
Views on SlideShare
452
Embed Views
0

Actions

Likes
0
Downloads
22
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Unix_commands_theory Unix_commands_theory Document Transcript

  • UNIX (UNICS) [UNiformed Information and Computational language]Operating system: Interface between hardware and user through applications. Only OS can interact with hardware directly.Applications: Start menu - .dll Calculator - .exeuser Applications / GUI OS HardwareProgramming languages: (Language used to write programs) Low (Machine language): o Binary coded o E.g.: ADD A,B ; MOV A,B Medium (Assembly language): o OS(system) can easily convert it to machine language directly o Short commands o E.g. :A+B High: o OS(system) cannot interpret high language o Requires interpreter to be converted to machine language o E.g.: C, C++, JAVA, etc.UNIX features: Portable, multitasking, multiuser OS Developed in 1969 by group of AT&T employees at BELL labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas Mcllroy and Joe Ossanna. Initially developed in assembly language but later on recorded entirely in C language.UNIX System V: Abbreviated: SysV 1st commercial version of UNIX OS Release SVR4 in 1991 Incorporated elements od BSD and SunOS into System V
  • UNIX Standards: [All standards belong to POSIX] 1980s: Motivation 1998: POSIX 1990s: Spec 1170 1997 : Single UNIX Specification version 2 2001 : POSIX:2001, Single UNIX Specification version 3 2004 : POSIX:2004 2008 : POSIX:2008UNIX Components: Computer hardware UNIX Kernel: o System booted – Kernel loaded o 1OS 1UNIX kernel Multiple users o Connection between hardware and shells The shell: o 1Shell 1User o Connection between Kernel and applications / utilities Utilities and application programs Utilities & Application programs The Shell UNIX Kernel Computer Hardwar e UNIX components / computer hardware for UNIX
  • LOG Process/ Shell creation:Daemon: Background processes which becomes active when system boots up till the time when system shuts down Take large memory, power and CPU usageFork: Duplicating/ parallel processing If forked element dies, the one creating it still livesSpawn / exec: Creating from within self Child creation If parent dies, the child also dies. init fork init getty login shell exec/ exec/ exec/ spawn spawn spawn fork shell Log process / Shell creationProcess: inits are the daemons of UNIX system. For the log in process, init forks another init (one for every terminal/ login /user) This forked init further spawns/exec onegetty This getty further spawns/exec one login
  • This login is nothing but GUI displaying the page for Login ID and password. It compares the entered details of login ID and password with the authenticated ID and passwords saved in files. If ID and password matches, then login spawns/exec one shell, else getty and login processes terminates and goes back to init process. This shell interacts with application to do further process. It can also fork other shells for doing parallel processing of more than one applications/utilities. Once the user logs out, forked init dies causing the entire getty,login,shell,forked shells to die (as they are childs).Shell prompts: Successful login is indicated by appearance of shell prompts or system prompts on the terminal. List of default prompts are: Sr. No. Prompts Shells 1 $ (dollar) Bourne &Korn shells (sh, bash &ksh) 2 % (percent) C shells (csh&tcsh) 3 # (hash) Any shell as root [admin login]Commands in UNIX: Commands are instructions/programs written to perform specific action Lower cased and cryptic Have arguments (-), format specifiers (+) & options Can use 2dary prompt (>) [command more than one line] Killed using <delete> or <ctrl-u> Types: o External (commands in files which shell doesn’t recognize) & o Internal (Shell commands)Basic UNIX commands: echo uname who who am i date cal cat spell man
  • Note: > : insertion / overwriting >> : appending ctrl+z : exiting the file q : coming out of editor exit : logout as well as closing putty window H.W.: Types of kernel Generation of computers File system of UNIX OS Commands description File system: File: store information Directory: Special kind of file which stores other files and directories File system: System made up of files and directories / bin dev home lib temp sbin etc usr vardsk fdd lpo bin sbin lib local romeo juliet progs Login.sql .profile File System Static inbuilt folders:
  • /(root):bin: Binary executables (shell software and UNIX commands)dev: device files necessary for hardware configuration i.e to operate peripherals like printers andterminalhome:user folderslib:temp: temporary files and folder becomes empty when rebootedsbin: Self binary executables which start and stop by themselvesetc:usr:var: files and folders with variable information e.g. help file, root path to printer, file linksNote: Rest folders are variablePath names: Route taken to reach a file in the file system is known as path to that file Depending on beginning point from where path is defined, there are two types of path names: o Absolute path name: Beginning from root o Relative path name: Beginning from present working directory (PWD)Wild-cards:Characters such as ?, *, [], ! have special meaning attached to them in regard to pattern matching.They are called wild-cards or Meta-characters. *- zero or one or many ? - exactly one character []- character class (forward order only) ! - Bang character (not, negating)Note: echo* --- list files and directories (similar to ls [not hidden ones])File and directory commands:
  • Sr. No. Command Explanation 1. ls : Lists file and directories ls -a All files and directories including the hidden ones ls -A All files and directories excluding .& .. 2. wc Lines, words, characters count wc –l Lines count wc –m Character count wc –c Bytes count (similar to character count :wc -m) wc –w Words count wc –L Maximum line length 3. mkdir Make a directory 4. cd directory Change to named directory (if exists) 5. cd Change to home directory 6. cd~ Change to home directory 7. cd.. Change o parent directory 8. cp file1 file2 Copy file1 and call it file2 (duplicate) cp –r dir1 dir2 Copy recursively all files and directories from dir1 to dir2 (duplicate) 9. mv file1 file2 Move(different) or rename(same directory) file1 to file2 mv dir1 dir2 Move(different parent) or rename(same parent directory) file1 to file2 10. rm Remove file rm * Remove all files 11. rmdir Remove directory (only when empty) 12. cat file Display a file 13. less file Display a file, one page at time 14. head file Display first few lines of file 15. tail file Display last few lines of file 16. ln : Link creation ln file1 file2 Hard link file2 of file1 (file2 linked to content of file1) [file1 ln –s file1 file2 deleted : link exists] Soft link file2 of file1 (file2 linked to file1)[file1 deleted : link broken] 17. grep ‘keyword’ file Search a file for keyword [displays sentence in which word appears]File attributes and permission:
  • Owner (u-user) Group (g) (a) All All others (o-others)File attributes: Name Creation Size Owner Group to which owner belongs to Link information Permissions inode number (where meta data is stored)Note: Every file has inode block (meta data-data of data) and data blockFile type: d (directory) l (symbolic link) b (block special file) c (character special file) p (named pipe special file) s (local socket special file)Note: socket: Port Piping: Deals with inter-process communication i.e. input and output of one program are related to input and output of other programFile Permissions: permission owner (u) group (g) other (o) rwx rwx rwx
  • Reading (r) Writing (w) Execution (x)File access commands: Sr. No. Command Explanation 1. ls: Long listing format ls – a All files and directories ls -al Al visible as well as hidden files and directories 2. chmod Change file permission 3. chgrp Change file ownership 4. chown Change group of file 5. file Identify type of file based on their contentExamples: ls: ls –l total 4 [block of data] [permission user group size date time file/dir name] drwxrwxrw- user6 user61023 2 may 2012 1:30 pm keviniti1 -rw-r--r-- user6 user6 3232 1 may 2012 10:44 pm niti.txt file: file niti.txt niti.txt : ASCII text chmod: o chmod 655 niti.txt [octal representation / assignment] o chmod u=rw, go=rx [full assignment – previous rites dropped] o chmoda+r, u+w, go+x [partial assignment – added to previous rites ] ls –l -rw-r-xr-x user6 user6 3232 1 may 2012 10:44 pm niti.txt [only present owner can do so i.e. user6] chown: chown user1 niti.txt [only present owner can do so i.e. user6] chgrp: chgrp user1 niti.txt [only present owner can do so i.e. user6] Pipe and piping
  • Pipe: DataPiping: Process on intercommunication between commands. In this output of onecommand is taken as input to other command. (original source and destinations arealtered) command1 command2 output of command1 input to command2 PipingRedirection (Input, Output, Error):Redirection: Altering the source and destinationInput redirection: Keyboard is the standard input. Instead of keyboard, if input is takenfrom a file, then it is called input redirection. All commands cannot be made to do inputredirection. Only those commands, which accept input from keyboard, can be redirected.e.g. < or 0<, etc.Output redirection: Display screen is the standard output. Generally when program is madeto execute, its output goes to standard shell prompt output i.e. display screen. Instead ofdisplay screen, if output is made to go somewhere else like file, printer, disappear or othercommand, then it is known as output redirection.e.g. 1> or >, 1>> or >>, | (piping), etc.Error redirection: Display screen is the standard error output. Generally when program isexecuted and errors are not required to be displayed or required to be stored somewheretemporarily, then it can be redirected to file. This is known as error redirection. %e.g. 2>, 2>>, etc. Redirection:
  • Sr. Redirection Description Examples No. symbols 1. < Input redirection wc niti.txt wc<niti.txt 2. > Output redirection wc< niti.txt > output.txt who> filename 3. >> Output redirection with appending cat>> niti.txt 4. | Output of one command as input to other who | wc –l command who | grep ‘user6’Filters: Program that gets most of its data from its standard input (main input stream) and write its main result / output into its standard output (main output stream). Inputs should be greater than or equal to outputs UNIX filters are used as elements of pipelines E.g.s: grep, wc, cat, tee, head, tail, cut, sort, uniq, awk, sed, etcProcess: Program (set of instructions) in action / execution is known as process. Kernel is the main process (in process hierarchy). It generates or spawns other processes. Each process has unique id called process identity (PID). Maximum number of PID is 32767. Process is responsible for creating other processes, which becomes its child.Types of processes: Interactive of foreground processes: o Act upon user directories o Normally attached to terminal Non-interactive or background processes: o Runs independent of terminal Daemons: o Comes into existence as soon as system boots up and will be alive till system is shut down o Cannot kill these processes prematurely o Its combination of foreground and background processes o Only admin can interact (direct / redirect) with daemons but they cannot stop themRunning command in background:
  • Command is made to run in background by terminating it with an amperes and (&) symbol.e.g. who | sort –r >user.lst The shell immediately returns the PID as well as shell prompt ($) The user can find the process status using the PID. As soon as background process is completed, output pops out and mixes with the foreground processes. Hence it is recommended to redirect the output to a file.Process attributes: Sr. no. Process attributes Description 1. PID Process identification number 2. TTY Terminal type 3. TIME Cumulative time 4. CMD Command 5. UID User ID 6. PPID Parent PID 7. STIME Starting time 8. C CPU time consumed‘ps’ command: Displays attributes of processes that are currently running o –f : full list o –a : all users o –u : user o –t : terminal o –e : every thing (default)‘nice’ command: [only by admin] All processes in UNIX have equal priority. Process priority: o UNIX: 0(highest) to 39(lowest-default) o LINUX: -19(highest) to +20(lowest-default) Users can decrease the priority but cannot increase them (only admins can increase priority) E.g. nice -19 LINUX: 20+(19)=39 E.g. nice - -19 LINUX: 20+(-19)=1Signals:
  • Messages(signals) are sent to process in one of the following occasions: Under error condition or user interrupt, the kernel generates the signal During inter process communication, the participating process generates these signals Types of signals Sr. No. Signal no. Name Function 1. 1 SIGHUP Hangup 2. 2 SIGINT Interruupt 3. 3 SIGQUIT Quit 4. 9 SIGKILL Sure kill 5. 15 SIGTERM s/w termination 6. 24 SIGSTOP Stop‘trap command’: Traps are one or more signals to decide further course if action. Syntax: trap [commands] signal_numbers E.g.: trap “exit” 2 3 15 To reset: trap 2 3 15‘kill’ command: [only by admin] Terminating a process prematurely is called killing. This can be done with DEL or BREAK key. To kill background process, kill command is used. Syntax: kill PID Sr. No. Shortcut Description Signal 1. ctrl + c User interrupt Signal 2 2. ctrl + Sure kill Signal 9 3. ctrl + z Stop Signal 24