Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Unix Developed by Ken Thompson and Ritchie originally in assembly, and later in C, thus making it portable to other machines. It is an.

Similar presentations


Presentation on theme: "Introduction to Unix Developed by Ken Thompson and Ritchie originally in assembly, and later in C, thus making it portable to other machines. It is an."— Presentation transcript:

1 Introduction to Unix Developed by Ken Thompson and Ritchie originally in assembly, and later in C, thus making it portable to other machines. It is an operating system. It acts as interface between user and hardware. The main feature of Unix is "open system". Supports multi user and multi task features.

2 Components of UNIX SHELL:
Computer understands the language of 0's and 1's called the binary language. The Shell is an special program that takes in the human understandable command and if it is an valid one it will pass on to the Kernel for execution. KERNE: The Kernel is the heart of the system. It contains a set of programs normally written in C to communicate with the hardware. The Kernel acts as the interface between the computer hardware and various programs/application/shell.

3 Unix File System In Unix each and everything treated as a file
The normal file known as Regular file The directory file known as directory file The device file known as device file The base of the Unix file system is "/" (called as root) and also it is administrative directory

4 Unix File System /bin - It maintains all the user executable commands. (ls, rm ..) /etc - It contains all system configuration files. (unlink, cron ..) /etc/password - It contains each and every user information with 7 fields /dev - It contains all device files. (ip, log..) /tmp - Stores all temporary files information /sbin - It contains all administrative executable commands. (uname..) /lib - It contains all library files information /home or /usr - It is users home directory

5 Login Process login: venky password: ***** It will display the prompt
$ - User working prompt # - administrator working prompt

6 logname pwd date clear cal cal 2015 cal 03 2015 uname uname -rhostname
Basic Commands logname pwd date clear cal cal 2015 cal uname uname -rhostname

7 Basic Commands hostname -i who finger username who am i uptime
su - username whoami which exit man commandname

8 Files Creation cat - It is used for creating new files (or) to open existing files (or) to append data to the existing file cat > filename --> To create a file cat filename (or) cat < filename --> To open a file cat >> filename > To append data to a file cat file1 file2 file3 .. filen touch - To create empty file and to change the time stamp touch filename touch file1 file2 .. filen cat > .filename --> creating hidden files

9 Files Deletion rm filename - to delete file
rm -i filename - to get confirmation before deleting rm -f filename - to delete a file forcibly rm file1 file2 file3 - to delete multiple files

10 Working with directories
mkdir - To create new directory Syntax: mkdir directoryname mkdir dir1 dir2 .. dirn mkdir abc xyz abc/a1 abc/a2 abc/a1/a11 abc/a1/a12 xyz/x1 xyz/x2 mkdir .dirname --> to create hidden directory cd dirname cd to come out from current working directory cd / -- root directory cd o cd ~ -- to come to user's home directory

11 Removing Directories rmdir - To remove directory rmdir dirname
rmdir -r dirname --> To delete recursively rmdir -ri dirname rm -rf dirname --> To delete recursively entire directory with forcibly

12 Copy cp - To copy a file or directory Syntax: cp sourcefile targetfile
cp -i file1 file2 cp abc/a1/a11/emp xyz/x1 cd abc/a1/a11 cp emp ../../../xyz/x1 cp file1 file2 .. filen directory cp emp a1 sample abc cp -R sourcedir targetdir cp -R abc xyz

13 Move mv - To rename or to move file/directory mv file1 file2
mv dir1 dir2 mv emp .emp --> to hide existing file mv .emp emp --> to unhide a file mv .abc abc --> to unhide a directory

14 Viewing list of files ls - list current directory files and sub directories ls -a - list all files along with hidden files ls -r - reverse order ls -R - list all files recursively ls -t list files based on date & time

15 Wildcard characters * - It matches 0 or more characters
? - It matches any single character [] - It maintains any single character in the given list [-] - It matches any single character in the given range ls t* ls *s ls b*k ls a? ls [bkn]* ls [a-h]* rm * cp abc/a1/a11/* xyz/x1

16 Count lines, words and characters
wc - It is the command which gives number of lines, words and characters in a given file wc filename wc -l filename --> counts no of lines wc -w filename --> counts no of words wc -c filename --> counts no of characters wc -lw filename --> counts no of lines and words

17 Compare, diff, comm and file
cmp - It compares 2 files character by character, if no output, then files are same otherwise the files are not same. cat > a1 hello cat > a2 helo diff - It displays different lines between 2 files diff file1 file2 comm - It displays common lines between two files file - It displays he type of file whether it ASCII text file (or) empty file (or) directory

18 Redirecting Input/Output/Errors
stdin(0) < --> Redirect Input stdout(1) > (or) 1> --> Redirect Output stderr(2) 2> --> Redirect Errors cat emp > file1 cta sample 2> file2 cat file1 file2 file3 > out_file 2> err_file

19 Filters - grep grep [Globally search a regular expression and print it]: It is used for to search a string in a file or files syntax: grep pattern filename(s) grep hi sample grep hello sample grep hi a1 a2 a3 --> It will search hi in a1, a2 and a3 files grep hi * --> It will search hi in all files grep "hello world" sample grep -i "Hello" sample --> It ignores the case sensitive

20 Filters - grep grep -c "hi" sample --> counts no of lines having "hi" grep -n "hi" sample --> It displays line numbers containing "hi" word grep -v "hi" sample --> It display other than "hi" string lines grep "h*" sample grep "b[aeiou]" sample --> displays lines which are having ball, bill, bell, bull, etc grep "b..d" sample --> displays band, bond, bird, b12d, etc

21 Filters - grep Word pattern characters:
\< \> --> word boundary \< --> start of the word \> --> end of the word grep "\<hi\>" sample grep "\<hi" sample grep "hi\>" sample grep "\<[0-9][0-9][0-9][0-9]\>" sample

22 Filters - grep Line pattern characters: ^ --> start of the line
$ --> end of the line grep "^h" sample --> displays lines starting with "h" grep "^the" sample --> displays lines starting with "the" characters --> there, the, etc grep "^\<the\>" sample --> displays lines starting with "the" word only grep "o$" sample --> displays lines ends with "o" grep "[0-9]" sample --> It displays lines ends with digit grep "^[bkt]" sample --> It displays lines stating with b or k or t

23 Filters - grep grep "^[^bkt]" sample --> displays lines which are not starting with b or k or t grep "^unix$" sample --> displays lines having only unix grep "^...$" sample --> displays lines which are having 3 characters grep "^\." sample --> displays lines starting with "." character grep "^$" sample --> displays empty lines grep -c "^$" sample --> counts number of empty lines grep -v "^$" sample --> display non empty lines How to remove empty lines in a file? grep -v "^$" sample > temp mv temp sample

24 Filters - grep fgrep: It searches multiple strings fgrep "unix"
> oracle > perl" sample egrep: will support regular expression egrep 'Rahma+n' test egrep 'Google*' google.txt egrep "(unix | perl)" sample egrep 'Go{2}gle' google.txt Cat Pattern Rahman|sachin egrep -f pattern Legend

25 Filters - sed sed: It is used to replace a string
syntax: sed "s/oldstring/newstring/g" filename sed "s/unix/linux/" sample --> replaces unix with linux only on first occurrence sed "s/unix/linux/g" sample --> replaces unix with linux globally sed "s/UNIX/linux/gi" sample --> ignore case sensitive sed "s/^unix/linux/gi" sample sed "s/^$/hello/g" sample --> empty lines replaced by hello sed "s/unix//gi" sample --> delete unix word from sample file

26 Filters - sed sed -n '3p' sample --> displays 3rd line from sample file sed -n '2,5p' sample --> displays 2nd line to 5th line from sample file sed -n '$p' sample --> displays last line of sample file sed -n '2,4p >7,10p' sample --> displays 2nd to 4th lines and 7th to 1oth lines sed '3d' sample --> deletes 3rd line from file

27 Filters - tr tr: It translates character by character
tr "a e i o u" "A E I O U" < sample --> takes input from sample and it replaces small vowels with capital vowel character tr "," "\t" < emp --> In emp file all , characters will be replaces with tab space tr "[a-z]" "[A-Z]" < sample --> to convert all characters from lower case to upper case tr "[a-zA-Z]" "[A-Za-z]" sample --> It converts sample file content into reverse case tr -d "a" < sample --> It deletes 'a' character from sample file tr -d "a e i o u" < sample --> It deletes vowel characters from file

28 Delimiter delimiter means field separator. The default delimiter is tab key entry key means record separator. cat emp --> here , is the delimiter 101,venky,2000,10 102,chaitu,4000,20 cat emp1 --> here tab is the delimiter 101 Dinesh unix hyd 102 ramesh perl chn

29 cut cut: It is used to extract required fields and characters from a file cut -f 2,4 student --> displays 2nd and 3rd fields from student file cut -f 2-5 student --> displays 2nd to 5th fields from student file cut -d"," -f 2,4 emp --> displays 2nd, 4th fields from emp file (the delimiter is ,) cut -c 1-10 student --> displays 1st character to 10th character from student file cut -c 5-10, student --> displays every line 5th character to 10th character and 15th character to 20th character from student file

30 sort sort: It sorts the given file contents based on ASCII values in ascending order Syntax: sort filename sort -r sample --> sorts in descending order sort -u sample --> displays unique lines i.e it eliminates duplicate lines sort -n sample --> sorts based on numeric comparison

31 uniq uniq: It displays uniq lines in the given file.
Syntax: uniq sample uniq -u sample --> displays non duplicate lines uniq -d sample --> displays only duplicate lines uniq -c sample --> it counts how many times the lines are repeated in the file

32 head and tail head: It displays the first 'n' lines from given file. By default head displays first 10lines. syntax: head -n filename head -5 sample --> displays the first 5lines tail: It displays the last 'n' lines from given file. By default head displays last 10lines. syntax: tail -n filename tail -5 sample --> displays the last 5lines tail +5 sample --> displays from 5th line to last line

33 Piping piping(|): It is used for to combine two or more commands.
count number of users connected to servers who | wc -l count number of files in current directory ls | wc -l count number of sub directories in current directory ls -l | grep "^d" | wc -l display 3rd line to 7th line from sample file head -7 sample | tail +3

34 File Permissions for file: read --> open a file
write --> write and modify read & execute --> execute a file for directory: read --> ls write --> create and delete files read & execute --> cd user -> u read -> r + -> add permission group -> g write -> w - -> deny permission others -> o execute -> x = -> assign permission

35 File Permissions - chmod
chmod: It is used for to change the file permissions syntax: chmod who/[+/-/=]/permission filename/dirname chmod g+x sample1 --> It adds execute permission to group members chmod u+x, g-w sample1 --> It adds execute permission to owner and it removes write permission from group chmod g=w sample --> It adds only write permission to group and it delete read and execute permission from group members

36 File Permissions - chmod
octal code: read -> 4 write -> 2 execute -> 1 7-rwx 6-rw 5-rx 4-r 3-w,x 2-w 1-x 0-nopermission chmod 756 sample --> rwxr_xrw_ chmod 642 sample --> rw_r___w_ chmod 755 sample --> rwxr_xr_x chmod 700 sample --> rwx______ chmod 777 sample --> rwxrwxrwx

37 File Permissions – chown, chgrp
chown: To change owner of the file/diretory chown ownername file/directory chgrp: To change group of the file/directory chgrp groupname file/directory

38 write and wall write: It is used for to write message to another user account, but user should be logged into the server $ write chaitu hello ctrld $ mesg n --> to deny messages mesg y --> to allow messages wall: It is used to send broadcast message to all users, whoever connected to server and mesg is "y" $ wall welcome world

39 mail mail: to send the mail syntax: mail username
$ mail chaitu --> this mail is transferred to chaitu user mail box (/var/spool/mail/chaitu) subject: hello Hi, hw r u? ctrld $ $ mail chaitu abhi dinesh --> this mail is transferred to users chaitu, abhi and dinesh $ mail chaitu < student --> It transfers student file contents to chaitu user

40 telnet and ftp telnet: Telnet protocol is in_built in windows/linux. It is used for to connect to remote servers syntax: telnet ipaddress login: venky password: ***** Note: from start  run  type telnet ipaddress ftp: file transfer protocol. It is used to transfer files from one server to another server account. syntax: ftp ipaddress login: password:

41 ftp ftp> ftp> ls -> server ftp> !ls -> client
ftp> pwd -> server ftp> !pwd -> client ftp> cd dirname -> client ftp> lcd dirname -> server ftp> get filename -> to download file ftp> mget file1 file2 .. filen -> to download multiple files ftp> put filename -> to upload file ftp> ? -> list all ftp commands ftp> bye -> to quit from ftp

42 Zip gzip filename -> to gip the file
gzip sample -> it create sample.gz gunzip filename -> to unzip the file gunzip sample.gz -> it creates sample compress filename: To compress the file compress filename compress sample -> creates sample.z uncompress sample.z -> creates sample

43 Disk Status and tee df --> It displays disk space in bytes
df -h --> It displays disk space in kilo bytes du --> I tee: It is used to write data to the file as well as to screen cat test1 | tee test2t displays directory wise disk usage in form of blocks

44 Jobs foreground job: By default jobs come under foreground
$ cp file1 file2 --> foreground job $ cp file1 file2 & --> background job 512 (PID) $ sort sample > a1 & 513 (PID) In foreground, user can execute only one job, but in background user can execute many jobs How to kill foreground job? ctrl C (or) ctrl Z

45 Jobs $ ps (or) ps -f --> displays current running process list in the current user account $ ps -ef --> It displays currently running process list in Linux server How to kill background job? $ kill PID (or) $ kill -9 PID --> -9 option to kill forcibly $ jobs --> displays only background jobs with job id's How to bring background job to foreground? $ fg jobid

46 Job scheduling - crontab
2. at 3. batch 1. crontab: It executes the given jobs repeatedly in server account *(0-59) -> minutes *(0-23) -> hours *(1-31) -> days *(1-12) -> month *(0-6) -> weekday --> '0' for sunday

47 Job scheduling - crontab
$ crontab -e --> to open the crontab editor * * * * * date --> every minute, it executes date command and it writes output into your mailbox 30 10 * * * sh script1 --> It executes script1 every day at 10:30AM 30 10 * * 0 sh script2 --> It executes script2, every sunday at 10:30AM 30 22 * * 1,3,5 sh script3 --> It executes script3 every monday, wednesday & friday at 10:30PM ,15 * * sh script4 > test.txt --> It executes script every month 1st and 15th at 10:30PM and it writes output into file test.txt crontab -r --> to remove all crontab jobs crontab -l --> It list all crontab jobs

48 Job scheduling - at at: It executes the given jobs only once
$ at now --> It executes the given job immediately at> ls at> sh script1 at> ctrl d $ at now + 3 minutes --> after 3 minutes $ at now + 2 hours --> after 2 hours $ at now + 3 days --> after 3 days $ at now + 1 month --> after 1 month

49 Job scheduling – at and batch
$ at 4PM tomorrow --> tomorrow at 4'o clock $ at 10:30am july 10 --> july 10th at 10:30am $ atq --> It displays all 'at' command jobs with job ids $ atrm jobid --> It removes given job batch: The batch jobs will execute, when server is free and server load is less $ batch

50 Thank You


Download ppt "Introduction to Unix Developed by Ken Thompson and Ritchie originally in assembly, and later in C, thus making it portable to other machines. It is an."

Similar presentations


Ads by Google