Session4
-
Upload
learn-2-be -
Category
Technology
-
view
766 -
download
2
Transcript of Session4
![Page 1: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/1.jpg)
L2B Second Linux Course
Please visit our Facebook Group
Session4
![Page 2: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/2.jpg)
L2B Linux course
L2B Second Linux Course
Session outlines: Text Processing Tools Text Processing Tools Exercises VIM VIM Exercises Basic System Configuration Tools
![Page 3: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/3.jpg)
L2B Linux course
L2B Second Linux Course
Text Processing Tools
![Page 4: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/4.jpg)
L2B Linux course
L2B Second Linux Course
Extracting Text cat
• One or more files less
• Easy to read• /text• n/N• v open an editor• Used by man command to present man pages
![Page 5: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/5.jpg)
L2B Linux course
L2B Second Linux Course
Extracting Text head
• First 10 lines only• -n change number of lines
tail• Last 10 lines only• -n change number of lines• -f monitoring the file
![Page 6: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/6.jpg)
L2B Linux course
L2B Second Linux Course
Extracting Text cut
• Display specific columns• -d column delimiter• -f number of field• -c cut by characters
– cut -c2-5 /usr/share/dict/words
![Page 7: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/7.jpg)
L2B Linux course
L2B Second Linux Course
Extracting Text Grep
• Display lines where a pattern is matched• -i case-insensitively• -n print line numbers of matches• -v print lines not containing pattern• -AX include the X lines after each match• -Bx include the X lines before each match
![Page 8: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/8.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Analyzing Text wc
• Counts words, lines, bytes and characters• -l only line count• -w only word count• -c only byte count• -m character count (not displayed)
![Page 9: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/9.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Analyzing Text sort
• Sort text and original file is not changed• -r reverse (descending) sort• -n numeric sort• -u (unique) removes duplicate lines• -t c field separator• -k X which field• uniq & uniq -c
![Page 10: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/10.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Analyzing Text diff and patch
• diff foo.conf-broken foo.conf-works• -u better for patchfiles• Patching
– diff -u foo.conf-broken foo.conf-works > foo.patch– patch -b foo.conf-broken foo.patch
![Page 11: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/11.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Analyzing Text aspell
• Interactively spell-check files:– aspell check letter.txt
• Non-interactively list mis-spelled words in– Only reads data from standard input– aspell list < letter.txt
![Page 12: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/12.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Manipulating Text
tr and sed
![Page 13: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/13.jpg)
L2B Linux course
L2B Second Linux Course
Tools for Manipulating Text Tr
• Converts characters in one set to corresponding characters in another set
• Only reads data from STDIN• tr 'a-z' 'A-Z' < lowercase.txt
![Page 14: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/14.jpg)
L2B Linux course
L2B Second Linux Course
sed (stream editor) search/replace operations on a stream of text Normally does not alter source file -i to alter source file -i.bak to back-up and alter source file
![Page 15: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/15.jpg)
L2B Linux course
L2B Second Linux Course
sed Examples sed 's/dog/cat/i' pets sed 's/dog/cat/g' pets sed '1,50s/dog/cat/g' pets sed '/digby/,/duncan/s/dog/cat/g' pets sed -e 's/dog/cat/' -e 's/hi/lo/' pets
![Page 16: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/16.jpg)
L2B Linux course
L2B Second Linux Course
Characters for Complex Searches ^ represents beginning of line $ represents end of line Character classes as in bash:
• [abc], [^abc]• [[:upper:]], [^[:upper:]]
Used by: grep, sed, less, others
![Page 17: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/17.jpg)
L2B Linux course
L2B Second Linux Course
VIM
![Page 18: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/18.jpg)
L2B Linux course
L2B Second Linux Course
VIM Advantages: Speed: Do more with fewer keystrokes Simplicity: No dependence on mouse/GUI Availability: Included with most Unix-like OSes
Disadvantages Difficulty: Steeper learning curve than simpler
editors
![Page 19: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/19.jpg)
L2B Linux course
L2B Second Linux Course
Three main modes: Command Mode (default): Move cursor,
cut/paste text Insert Mode: Modify text Exit Mode: Save, quit, etc
![Page 20: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/20.jpg)
L2B Linux course
L2B Second Linux Course
First steps with vim vim filename(command mode) Insert mode
• I at the cursor • A append to end of line• I insert at beginning of line• o insert new a line (below)• O insert new line (above)
Exit mode• :w writes (saves) the file to disk• :wq writes and quits• :q! quits, even if changes are lost
![Page 21: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/21.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Right Arrow moves right one character 5, Right Arrow moves right five characters Arrow Keys, h, j, k, l (the same as arrows) w, b Move by word ), ( Move by sentence }, { Move by paragraph xG Jump to line x gg Jump to the first line G Jump to the last line
![Page 22: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/22.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode As in less
• /, n, N As in sed The selected line only
• :1,5s/cat/dog/ All of the entire file
• :%s/cat/dog/gi
![Page 23: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/23.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Line
• cc • dd • yy
Letter• cl • dl • yl
![Page 24: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/24.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Word
• cw• dw • yw
Sentence ahead• c) • d) • y)
![Page 25: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/25.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Sentence behind
• c(• d( • y(
Paragraph above • c{ • d{ • y{
![Page 26: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/26.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Paragraph below
• c} • d} • y}
u undo Ctrl-r redo U undo all changes to the last modified line
![Page 27: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/27.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode v starts character-oriented highlighting V starts line-oriented highlighting Visual keys used with movement keys:
• w, ), }, arrows Highlighted text can be
• Deleted• Yanked• Changed• Filtered• search/replaced, etc.
![Page 28: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/28.jpg)
L2B Linux course
L2B Second Linux Course
Command Mode Ctrl-w, s splits the screen horizontally Ctrl-w, v splits the screen vertically Ctrl-w, Arrow moves between windows Ctrl-w twice, Arrow moves between windows To search for help inside vim convert to the
exit mode and ask for help by running the following
• :help
![Page 29: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/29.jpg)
L2B Linux course
L2B Second Linux Course
Configuring vi and vim :set
• :set number• :set all• :set number (:se nu)• :set nonumber (:se nonu)• :set ignorecase (:se ic)• :set noignorecase (:se noic)• :set showmatch (:se sm)• :set noshowmatch(:se nosm)• :set autoindent• :set noautoindent
![Page 30: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/30.jpg)
L2B Linux course
L2B Second Linux Course
Configuring vi and vim :help :help something :set
• :set textwidth=3• :set textwidth=0• :set wrapmargin=10• :set wrapmargin=0
~/.vimrc vimtutor
![Page 31: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/31.jpg)
L2B Linux course
L2B Second Linux Course
Basic System Configuration Tools
![Page 32: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/32.jpg)
L2B Linux course
L2B Second Linux Course
Introduction Network interfaces are named sequentially:
eth0, eth1, etc Multiple addresses can be assigned to a
device with aliases Aliases are labeled eth0:1, eth0:2, etc. Aliases are treated like separate interfaces View interface configuration with :
ifconfig [ethX] Enable interface with ifup ethX Disable interface with ifdown ethX
![Page 33: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/33.jpg)
L2B Linux course
L2B Second Linux Course
Graphical Network Configuration system-config-network System > Administration > Network
Network Configuration Files For Devices /etc/sysconfig/network-scripts/ifcfg-ethX Complete list of options in
/usr/share/doc/initscripts-*/sysconfig.txt
![Page 34: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/34.jpg)
L2B Linux course
L2B Second Linux Course
Example Of Dynamic Configuration DEVICE=ethX HWADDR=0:02:8A:A6:30:45 BOOTPROTO=dhcp ONBOOT=yes Type=Ethernet
![Page 35: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/35.jpg)
L2B Linux course
L2B Second Linux Course
Example Of Static Configuration DEVICE=ethX HWADDR=0:02:8A:A6:30:45 IPADDR=192.168.0.254 NETMASK=255.255.255.0 GATEWAY=192.168.2.254 ONBOOT=yes Type=Ethernet
![Page 36: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/36.jpg)
L2B Linux course
L2B Second Linux Course
Network Configuration Files and Other Global Network Settings /etc/sysconfig/network
• NETWORKING=yes• HOSTNAME=server1.example.com• GATEWAY=192.168.2.254
![Page 37: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/37.jpg)
L2B Linux course
L2B Second Linux Course
DNS configuration Server address is specified by dhcp or in
/etc/resolv.conf• nameserver 192.168.0.254• nameserver 192.168.1.254
![Page 38: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/38.jpg)
L2B Linux course
L2B Second Linux Course
Setting the System's Date and Time GUI:
• system-config-date• System->Administration->Date & Time
CLI: date [MMDDhhmm[[CC]YY][.ss]]• date 01011330• Date 010113302007.05• Date 12312359• Date 123123592007• Date 01010101.01
![Page 39: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/39.jpg)
L2B Linux course
L2B Second Linux Course
Scripting Taking input with positional parameters
• $1• $2• $3• $4, etc.• $*• $#
![Page 40: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/40.jpg)
L2B Linux course
L2B L2B Second Linux Course Second Linux Course
Scripting Taking input with the read command
• read x• read -p "Enter a filename: " file
![Page 41: Session4](https://reader033.fdocuments.net/reader033/viewer/2022060108/5550d685b4c90599308b51dc/html5/thumbnails/41.jpg)
For More info Please Visit Our Facebook Group