Download - Dev day linux redu
![Page 1: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/1.jpg)
Tarcisio Coutinho16 Nov 2012
Dev-dayLinux - 101
![Page 2: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/2.jpg)
Timeline
● 1965 :: MULTICS :: MTI, Bell Labs (AT&T) e General Eletric
● 1969 :: Ken Thompson :: Unics (Assembly)● 1971 :: Ken Thompson :: Rewrites the system on B
language (to solve portability problems)● 1973 :: Thompson and Denis Richie :: C programming
language● 1974 :: UNIX \o/● 1983 :: AT&T closes the UNIX's source code● 1983 :: Andrew Tanenbaum :: MINIX● 1984 :: Richard Stallman :: GNU (GCC, Emacs)● 1991 :: Linux Torvalds :: GNU/Linux
![Page 3: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/3.jpg)
GNU/Linux Distribution Timeline
http://futurist.se/gldt/
![Page 4: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/4.jpg)
GNU/Linux
![Page 5: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/5.jpg)
GNU/Linux Structure
![Page 6: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/6.jpg)
Shell
![Page 7: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/7.jpg)
What is Shell?
● Provides the command prompt and to interpret commands
● Provides user interface for the OS and Kernel
![Page 8: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/8.jpg)
Shell implementations
● bash (bourne again shell :: GNU implementation)● ash (Almquist Shell :: BSD)● csh (C shell :: BSD)● tcsh (tee-shell)● sh (Stephen Bourne)● ksh (Korn shell)
![Page 9: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/9.jpg)
Shell Variable Basics
● bash maintains a set of shell variables○ PS1 :: Prompt String 1 :: Default interaction ○ PS2 :: Prompt String 1 :: Continuation interactive
prompt○ PATH :: contains a list of all the directories that
hold commands or other programs you are likely to execute
● bash variables are untyped
![Page 10: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/10.jpg)
Export Variables
● When a variable is exported to the environment, it is passed into the environment of all child processes
● let's go to the terminal○ REDU="Redu Tech"
■ conventionally uppercase
○ echo $REDU or echo ${REDU}■ $ prefix to interpret a shell var
○ echo "echo \$REDU" | bash
![Page 11: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/11.jpg)
Fun with PS1 :: Information
● \u - Username● \h - Hostname● \w - Full path of the current woking directory
![Page 12: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/12.jpg)
export PS1="\u@\h \w"
![Page 13: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/13.jpg)
export PS1="\u@\redu: \w "
![Page 14: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/14.jpg)
Fun with PS1 :: Colors
● \e[ :: indicates the beginning of color
● x;ym :: indicates color code
● \e[m :: indicates end of color prompt
White 1;37Green 1;32Cyan 1;36Yellow 1;33
![Page 15: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/15.jpg)
PS1="\e[01;32m\u\e[m@\redu: \w "
![Page 16: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/16.jpg)
PS1="\e[01;32m\u\e[m\e[1;37m@\e[mredu: \w "
![Page 17: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/17.jpg)
PS1="\e[01;32m\u\e[m\e[1;37m@\e[m\e[1;36mredu:\e[m \w "
![Page 18: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/18.jpg)
PS1="\e[01;32m\u\e[m\e[1;37m@\e[m\e[1;36mredu:\e[m\e[1;33m\w\e
[m "
![Page 19: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/19.jpg)
Streams, Pipes and Redirects
![Page 20: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/20.jpg)
Streams
● Everything is a file.○ a program reading from the terminal’s device file
will receive characters typed at the keyboard
● When a program is launched, it is automatically provided with three file descriptors○ Standard input (abbreviated stdin) :: 0○ Standard output (abbreviated stdout) :: 1○ Standard error (abbreviated stderr) :: 2
● The standard input is different than parameters
![Page 21: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/21.jpg)
Pipes and Redirects
● Pipes |○ provides communication inter-process
■ tie the output of one program to the input of another
■ e.g. echo "echo 'Hello Redu'" | bash
● Redirection○ allows you to manage the origin of input streams
and the destination of output streams■ > :: Redirection operator■ >> :: Append operator■ < :: Receive stdin from file
![Page 22: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/22.jpg)
GNU and Unix Commands
![Page 23: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/23.jpg)
Tricks
● cd - :: go to the recent directory○ Works with git branches
■ git checkout -
● !! :: call most recent command○ bang-bang
● $( ) :: Command substitution or sub-shell○ cd $(pwd)/..
![Page 24: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/24.jpg)
GNU and Unix sed & awk
![Page 25: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/25.jpg)
Sed
● Stream based processing text editor
echo "sed tutorial. sed is a powerful text editor" | sed 's/sed/awk/'
echo "sed tutorial. sed is a powerful text editor" | sed 's/sed/awk/g'
echo "sed tutorial. sed is a powerful text editor" | sed 's/sed/awk/2g'
![Page 26: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/26.jpg)
Sed
echo "line without numbers \nline with numbers: 1 2 3 " | sed -r 's/[0-9]+/X/g'
echo "line without numbers \nline with numbers: 1 2 3 " | sed -rn 's/[0-9]+/X/g'
echo "line without numbers \nline with numbers: 1 2 3 " | sed -rn 's/[0-9]+/X/gp'
![Page 27: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/27.jpg)
Sed
● Delete lines○ sed '1,2-3 d' [FILE]○ sed '/[pattern]/d [FILE] ○ sed -i '1 d' [FILE]
● Add lines○ sed '/[pattern]/ i [text]' [FILE]○ sed '/[pattern]/ a [text]' [FILE]
○ sed "1s/^/[text]" [FILE]
![Page 28: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/28.jpg)
Awk
● AWK○ processing text programming language
■ column based
awk -F [pattern] '{ [CMD] }'
$n -> variable from split by pattern match
ls -l | awk -F ' ' '{print $0}'
![Page 29: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/29.jpg)
Quests
![Page 30: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/30.jpg)
Fun with Seds
● Parse rails logs○ Request count development.log
○ Top 10 most slow compound log job
grep awk head wcuniq sort tail sed 'N;'sed cut nl expandtr
![Page 31: Dev day linux redu](https://reader033.vdocument.in/reader033/viewer/2022051015/553891fb4a79595b7a8b47b6/html5/thumbnails/31.jpg)
Dev-dayLinux - 101