Presented by :- U.SHANMUGARAJAN M.SC COMPUTER SCIENCE THIAGARAJAR COLLEGE
What is Linux? Linux is the most used open source operating system. Everything on a Linux system can be done by typing commands History of Linux? Linux was developed by Linux Torvalds. On Octoer 5,1991, Linus announced the first official version of Linux. Which was version 0.02.
What is command shell? ⇨Shell is a Program that takes commands from the keyboard and gives them to the operating system to perform. ⇨On most Linux systems a BASH(Bourne-Again SHell) is the default shell. ⇨Ksh, tcsh and xsh are other shell programs available on a Linux systems. ⇨Command prompt user’s types. •$ - “logged in as a regular user”, •# - “logged in as root”
LINUX BASIC COMMANDS
A shell script is a text file contains Linux commands. We create shell program with any editors such as vi. Shell scripts allow input/output operations and manipulating variables. The sh command used to execute shell program. the following commands are also used in the shell programming 1> read – read the variable from the terminal. eg . read a 2> expr – expression. eg . ‘expr $a + $b’ add two variables a and b. Note that expr statement always start with ‘ and end with ‘. we also use arithmetic operators ‘-’ , ’*’ , ’/’ , ’%’ Shell programming
3> relational operators -gt - greater than -lt - less than -ge - greater than or equal to -le - less than or equal to -eq - equal to 4> pipeline ( | ) pipeline used to combine many commands into one. eg . Cat $fn | tr “a-z” “A-Z” It converts all lowercase to upper case and display. 5> cc compiles c program. Shell programming
TERMINAL
directory handling commands 1> mkdir – make directories eg. $mkdir dir1 2> rmdir – remove empty directories eg. $rmdir dir1 3> cd – changes directories eg. $cd dir1 (change directory to dir1) $cd (move to previous directory) 4> pwd – present working directory eg. $pwd
Display file contents 1> cat – shows contents of the file eg. $cat file1 we also use cat command for create, copy, append the file  cat>file1 – open new file named file1 Cat>>file1 – open file1 for append Cat file1>file2 – The contents of file1 copied to file2 use ctrl + d or ctrl + z for save the file. 2> tac – similar to cat but it displays contents of the file in reverse order eg. $tac file1
Display file contents 3> head – display first 10 lines of files. syntax. $head –n filename 4> tail – display last 10 lines of files. syntax. $tail –n filename
Display file contents 5> more The more command is useful for displaying files that take up more than one screen. More will allow you to see the contents of the file page by page. Use the space bar to see the next page, or q to quit. syntax. $more [options] filename options are -num - sets the no of lines to be display ` -d - more prompt the user with the message ‘[press space to continue, ’q’ to quit]’ -f - long lines are wrapped -s - convert multiple blank line into one line
Display file contents 6> less less command similar to more, but it provides some more options to view file. space - ahead one full screen ENTER - ahead one line b - back one full screen k - back one line g - top of the file G - bottom of the file /text - search forward for text n - repeat last search q - quit
File handling commands 1> ls – List all files and folders syntax :- ls [option]…[file] •-a – List files include hidden files. •-author – print the author of each file •-B – will not list the backup file ending ~ •-l – List all files with complete details. •-d – List directories •-i – print index number of each file •-s – print size of each file •-t – sort by modification time. •-1 – list one file per line. We combine two or more option to display files. Eg : ls –la – List all files with complete details include hidden files.
File handling commands 2> file – It determines the file type. 3> touch – create empty files eg 1. touch file3 4> rm – remove files or directories syntax : rm [options] filename -i - it confirm before delete the files -f - (force) remove directory contain files. (only root user use this). eg . rm file1, rm -f some_dir
File handling commands 5> vi – open Visual text editor eg. $vi file1.txt, $vi 6> sh – runs shell program eg. $sh filename 7> cp – copy files and directories syntax : cp source target -r - the -r option forces recursive copying of all files in all subdirectories. -i - prevents cp from overwriting existing file eg 1. cp sample.txt sample_copy.txt eg 2. cp sample_copy.txt target_dir
File handling commands 8> mv – move or rename files or directory eg 1. mv source.txt target_dir eg 2. mv old.txt new.txt 9> find – search for files in a directory eg . find file1.txt, find –name file1.txt 10>chown – change owner of file
File handling commands 11>chmod – change permission of file 0 – No permission 1 – Execute 2 – write 3 – Write and Execute 4 – Read 5 – Read and Execute 6 – Read and Write 7 – All permission syntax : chmod UGO U – users G – groups O – others
Text Processing commands 1> sort – sort lines of text files syntax : sort [OPTION] [FILE] eg. sort file1 - ascending order sort –r file1 - descending order sort -n file2 - numeric sort 2> tr – transalate characters in one set to corresponding characters in another set eg. tr 'a-z' 'A-Z' < lowercase.txt 3> echo – display a line of text eg. echo Linux, echo $HOME
Text Processing commands 4> grep – print lines matching a pattern Syntax : grep [OPTION] PATTERN [FILE] eg. grep –i apple sample.txt i – ignore case o – only matching n – print line numbers of matches v – print lines not containing pattern 5> wc – print the number of lines, words, and characters in files eg. wc –l file1.txt - count no of lines in file1 wc –w file1.txt - count no of words wc –c file1.txt - count no of character
Date – prints system date and time syntax . $date [options] eg :- Tuesday, August 23 10:20:32 IST 2016 •+ %d – Day of the months (in digits) •+ %m – Month of the year (in digits) •+ %y – Year (last two digits) •+ % D – Date as mm/dd/yy •+ %H – Hour (00 to 23) •+ %M – Minutes (00 to 59) •+ %S – Seconds (00 to 59) •+ %T – Time as HH:MM:SS •+ %a – Weekday (sun to sat) •+ %h – Month (jan to dec) •+ %r – Time in the AM/PM notation Date commands
1> history – prints recently used commands eg . $history 2> clear – clear the terminal. eg . $Clear 3> exit – exit from the terminal. eg . $exit 4> man – get help on entered commands. eg . $man ls – get help on the ‘ls’ command. 5> who – show who is logged into the system eg . $who 6> whoami – show current user logged in the system eg . $whoami 7> passwd – change password for current user eg . $passwd Other Useful commands
8> sudo -i – login as root user eg . $sudo -i 9> info – display information about the commands. eg . $info 10> cal – displays the calendar. eg . $cal Other Useful commands
Vi editor
Editors are mainly used for creating, deleting and editing the files. All systems have two standard editors, they are Ed and Vi. Ed allows the user for one line editing only but vi editor allows the user to edit text of one screen at a time. What is vi editor
Two modes in vi editor 1)Insert mode In this input mode, the keyboard behaves as a normal typewriter with the exception. 2)Command mode In command mode, all the keys on the keyboard become editing commands (x keys works as delete key). Modes in vi editor
Text is inserted. The ‘Esc’ key ends insert mode and return to command mode. We enter insert mode with  ‘i’ - insert  ’a’ - insert after  ‘A’ - insert at End Of Line  ‘o’ - new line after current line  ‘O’ - new line above current line Insert mode
letters or sequence of letters interactively command vi. commands are case sensitive. the ‘Esc’ key can end a command. Command mode KEYS ACTIONS h/j/k/l Move cursor left/down/up/right Ctrl + d Scroll down one half of a screen ctrl + u) Scroll up one half of a screen H (Shift + h) Move cursor to top of the page L (shift+ l) Move cursor to bottom of the page w 5w Move cursor a word at a time Move cursor 5 words ahead b 5b Move cursor back a word at a time Move cursor back 5 words
Command mode KEYS ACTIONS e 3e Move cursor to end of word Move cursor ahead to the end of 3rd word 0 :30 Move cursor to beginning of line Move cursor to line thirty $ Move cursor to end of line G Move cursor to end of file M Mark the line on which the cursor. i , a, A, o, O Go to insert mode D dd Delete contents of line after cursor Delete line
Command mode KEYS ACTIONS x X Delete character at cursor Delete character before cursor Y or yy Copy current line into unnamed storage buffer p P Paste unnamed storage buffer after current line Paste unnamed storage buffer before current line J Join current and following line into one line Ctrl – a Increment number under the cursor Ctrl – x Decrement number under the cursor . Repeat last command action
Creating a file in VI editor If we want to edit an existing file or to create a new file with name student , we have to give the following command. $vi student We also create unnamed file as follows $vi if we want to create hidden file then we have to give the following command $vi .filename save the file by entering command line mode and type :wq
we save the file in vi editor by going to command mode and press‘:’. This goes to the another mode called command line mode or last line mode. we save the file with following ways. :ZZ - save changes to current file and quit. :wq - save(write) changes to current file and quit :w - save changes to current file without quitting :w filename - save changes to a new file of name “filename without quitting. Saving the file
Closing the file once we created the file, we exit from the vi editor by using following steps •go to command line mode. •use :wq for save file and quit •use :qa for quit all files •use :q! for quit file without saving..
Linux Basic commands and VI Editor

Linux Basic commands and VI Editor

  • 1.
    Presented by :- U.SHANMUGARAJAN M.SCCOMPUTER SCIENCE THIAGARAJAR COLLEGE
  • 2.
    What is Linux? Linuxis the most used open source operating system. Everything on a Linux system can be done by typing commands History of Linux? Linux was developed by Linux Torvalds. On Octoer 5,1991, Linus announced the first official version of Linux. Which was version 0.02.
  • 3.
    What is commandshell? ⇨Shell is a Program that takes commands from the keyboard and gives them to the operating system to perform. ⇨On most Linux systems a BASH(Bourne-Again SHell) is the default shell. ⇨Ksh, tcsh and xsh are other shell programs available on a Linux systems. ⇨Command prompt user’s types. •$ - “logged in as a regular user”, •# - “logged in as root”
  • 4.
  • 5.
    A shell scriptis a text file contains Linux commands. We create shell program with any editors such as vi. Shell scripts allow input/output operations and manipulating variables. The sh command used to execute shell program. the following commands are also used in the shell programming 1> read – read the variable from the terminal. eg . read a 2> expr – expression. eg . ‘expr $a + $b’ add two variables a and b. Note that expr statement always start with ‘ and end with ‘. we also use arithmetic operators ‘-’ , ’*’ , ’/’ , ’%’ Shell programming
  • 6.
    3> relational operators -gt- greater than -lt - less than -ge - greater than or equal to -le - less than or equal to -eq - equal to 4> pipeline ( | ) pipeline used to combine many commands into one. eg . Cat $fn | tr “a-z” “A-Z” It converts all lowercase to upper case and display. 5> cc compiles c program. Shell programming
  • 7.
  • 8.
    directory handling commands 1>mkdir – make directories eg. $mkdir dir1 2> rmdir – remove empty directories eg. $rmdir dir1 3> cd – changes directories eg. $cd dir1 (change directory to dir1) $cd (move to previous directory) 4> pwd – present working directory eg. $pwd
  • 9.
    Display file contents 1>cat – shows contents of the file eg. $cat file1 we also use cat command for create, copy, append the file  cat>file1 – open new file named file1 Cat>>file1 – open file1 for append Cat file1>file2 – The contents of file1 copied to file2 use ctrl + d or ctrl + z for save the file. 2> tac – similar to cat but it displays contents of the file in reverse order eg. $tac file1
  • 10.
    Display file contents 3>head – display first 10 lines of files. syntax. $head –n filename 4> tail – display last 10 lines of files. syntax. $tail –n filename
  • 11.
    Display file contents 5>more The more command is useful for displaying files that take up more than one screen. More will allow you to see the contents of the file page by page. Use the space bar to see the next page, or q to quit. syntax. $more [options] filename options are -num - sets the no of lines to be display ` -d - more prompt the user with the message ‘[press space to continue, ’q’ to quit]’ -f - long lines are wrapped -s - convert multiple blank line into one line
  • 12.
    Display file contents 6>less less command similar to more, but it provides some more options to view file. space - ahead one full screen ENTER - ahead one line b - back one full screen k - back one line g - top of the file G - bottom of the file /text - search forward for text n - repeat last search q - quit
  • 13.
    File handling commands 1>ls – List all files and folders syntax :- ls [option]…[file] •-a – List files include hidden files. •-author – print the author of each file •-B – will not list the backup file ending ~ •-l – List all files with complete details. •-d – List directories •-i – print index number of each file •-s – print size of each file •-t – sort by modification time. •-1 – list one file per line. We combine two or more option to display files. Eg : ls –la – List all files with complete details include hidden files.
  • 14.
    File handling commands 2>file – It determines the file type. 3> touch – create empty files eg 1. touch file3 4> rm – remove files or directories syntax : rm [options] filename -i - it confirm before delete the files -f - (force) remove directory contain files. (only root user use this). eg . rm file1, rm -f some_dir
  • 15.
    File handling commands 5>vi – open Visual text editor eg. $vi file1.txt, $vi 6> sh – runs shell program eg. $sh filename 7> cp – copy files and directories syntax : cp source target -r - the -r option forces recursive copying of all files in all subdirectories. -i - prevents cp from overwriting existing file eg 1. cp sample.txt sample_copy.txt eg 2. cp sample_copy.txt target_dir
  • 16.
    File handling commands 8>mv – move or rename files or directory eg 1. mv source.txt target_dir eg 2. mv old.txt new.txt 9> find – search for files in a directory eg . find file1.txt, find –name file1.txt 10>chown – change owner of file
  • 17.
    File handling commands 11>chmod– change permission of file 0 – No permission 1 – Execute 2 – write 3 – Write and Execute 4 – Read 5 – Read and Execute 6 – Read and Write 7 – All permission syntax : chmod UGO U – users G – groups O – others
  • 18.
    Text Processing commands 1>sort – sort lines of text files syntax : sort [OPTION] [FILE] eg. sort file1 - ascending order sort –r file1 - descending order sort -n file2 - numeric sort 2> tr – transalate characters in one set to corresponding characters in another set eg. tr 'a-z' 'A-Z' < lowercase.txt 3> echo – display a line of text eg. echo Linux, echo $HOME
  • 19.
    Text Processing commands 4>grep – print lines matching a pattern Syntax : grep [OPTION] PATTERN [FILE] eg. grep –i apple sample.txt i – ignore case o – only matching n – print line numbers of matches v – print lines not containing pattern 5> wc – print the number of lines, words, and characters in files eg. wc –l file1.txt - count no of lines in file1 wc –w file1.txt - count no of words wc –c file1.txt - count no of character
  • 20.
    Date – printssystem date and time syntax . $date [options] eg :- Tuesday, August 23 10:20:32 IST 2016 •+ %d – Day of the months (in digits) •+ %m – Month of the year (in digits) •+ %y – Year (last two digits) •+ % D – Date as mm/dd/yy •+ %H – Hour (00 to 23) •+ %M – Minutes (00 to 59) •+ %S – Seconds (00 to 59) •+ %T – Time as HH:MM:SS •+ %a – Weekday (sun to sat) •+ %h – Month (jan to dec) •+ %r – Time in the AM/PM notation Date commands
  • 21.
    1> history –prints recently used commands eg . $history 2> clear – clear the terminal. eg . $Clear 3> exit – exit from the terminal. eg . $exit 4> man – get help on entered commands. eg . $man ls – get help on the ‘ls’ command. 5> who – show who is logged into the system eg . $who 6> whoami – show current user logged in the system eg . $whoami 7> passwd – change password for current user eg . $passwd Other Useful commands
  • 22.
    8> sudo -i– login as root user eg . $sudo -i 9> info – display information about the commands. eg . $info 10> cal – displays the calendar. eg . $cal Other Useful commands
  • 23.
  • 24.
    Editors are mainlyused for creating, deleting and editing the files. All systems have two standard editors, they are Ed and Vi. Ed allows the user for one line editing only but vi editor allows the user to edit text of one screen at a time. What is vi editor
  • 25.
    Two modes invi editor 1)Insert mode In this input mode, the keyboard behaves as a normal typewriter with the exception. 2)Command mode In command mode, all the keys on the keyboard become editing commands (x keys works as delete key). Modes in vi editor
  • 26.
    Text is inserted.The ‘Esc’ key ends insert mode and return to command mode. We enter insert mode with  ‘i’ - insert  ’a’ - insert after  ‘A’ - insert at End Of Line  ‘o’ - new line after current line  ‘O’ - new line above current line Insert mode
  • 27.
    letters or sequenceof letters interactively command vi. commands are case sensitive. the ‘Esc’ key can end a command. Command mode KEYS ACTIONS h/j/k/l Move cursor left/down/up/right Ctrl + d Scroll down one half of a screen ctrl + u) Scroll up one half of a screen H (Shift + h) Move cursor to top of the page L (shift+ l) Move cursor to bottom of the page w 5w Move cursor a word at a time Move cursor 5 words ahead b 5b Move cursor back a word at a time Move cursor back 5 words
  • 28.
    Command mode KEYS ACTIONS e 3e Movecursor to end of word Move cursor ahead to the end of 3rd word 0 :30 Move cursor to beginning of line Move cursor to line thirty $ Move cursor to end of line G Move cursor to end of file M Mark the line on which the cursor. i , a, A, o, O Go to insert mode D dd Delete contents of line after cursor Delete line
  • 29.
    Command mode KEYS ACTIONS x X Deletecharacter at cursor Delete character before cursor Y or yy Copy current line into unnamed storage buffer p P Paste unnamed storage buffer after current line Paste unnamed storage buffer before current line J Join current and following line into one line Ctrl – a Increment number under the cursor Ctrl – x Decrement number under the cursor . Repeat last command action
  • 30.
    Creating a filein VI editor If we want to edit an existing file or to create a new file with name student , we have to give the following command. $vi student We also create unnamed file as follows $vi if we want to create hidden file then we have to give the following command $vi .filename save the file by entering command line mode and type :wq
  • 31.
    we save thefile in vi editor by going to command mode and press‘:’. This goes to the another mode called command line mode or last line mode. we save the file with following ways. :ZZ - save changes to current file and quit. :wq - save(write) changes to current file and quit :w - save changes to current file without quitting :w filename - save changes to a new file of name “filename without quitting. Saving the file
  • 32.
    Closing the file oncewe created the file, we exit from the vi editor by using following steps •go to command line mode. •use :wq for save file and quit •use :qa for quit all files •use :q! for quit file without saving..