shell basic
DESCRIPTION
introduce the basic shell command and some use Cases.TRANSCRIPT
![Page 2: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/2.jpg)
How to learn
• man man man !
• practice
![Page 3: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/3.jpg)
dir/file manipulation
• mkdir / mkdir -p!
• rmdir / rmdir -p!
• rm -rf!
• cp -i!
• ln -s
![Page 4: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/4.jpg)
cd
![Page 5: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/5.jpg)
ls
• ls -- list directory contents!• Options!
• -l,-a,-t!• -Ut
![Page 6: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/6.jpg)
ls
![Page 7: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/7.jpg)
tree
• tree -- list files in tree-like format!• Options!
• -a,-d,-f!• -P,-I
![Page 8: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/8.jpg)
tree
![Page 9: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/9.jpg)
Display Files
![Page 10: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/10.jpg)
cat
• cat - Concatenate Files!• cat -n !• cat -s
![Page 11: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/11.jpg)
cat
![Page 12: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/12.jpg)
cat multiple files
![Page 13: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/13.jpg)
less & more
• less/more!
• less line move,more page move!• does not read the entire input file before starting!• less -N line-number!• ls /etc | less
![Page 14: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/14.jpg)
tail & head
• tail !• tail -f!• tail -5!
!
• head!• head -5
![Page 15: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/15.jpg)
wc
• wc -l
![Page 16: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/16.jpg)
echo
• echo -e!• echo -n
![Page 17: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/17.jpg)
echo
![Page 18: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/18.jpg)
Identifying Commands
• type - Display A Command's Type!• type cd!• type ll
![Page 19: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/19.jpg)
type
![Page 20: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/20.jpg)
Identifying Commands
• which - Display An Executable's Location!• which ls!• cat `which hlfile`
![Page 21: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/21.jpg)
which
![Page 22: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/22.jpg)
Redirction
![Page 23: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/23.jpg)
Redirection
• stdin,stdout,stderr!• 0 1 2!
• /dev/null!• < > >>!• Case!
• redirect error!• redirect stdout and error to a file
![Page 24: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/24.jpg)
2>&1
![Page 25: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/25.jpg)
Permissions
![Page 26: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/26.jpg)
" chmod – Change a file's mode!
" umask – Set the default file permissions!
" su – Run a shell as another user!
" sudo – Execute a command as another user!
" chown – Change a file's owner
![Page 27: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/27.jpg)
from《The Linux Command Line》William E. Shotts, Jr.
![Page 28: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/28.jpg)
![Page 29: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/29.jpg)
umask
• umask!
• the default permissions of created file!
• octal notation !
• express a mask of bits to be removed from a file's mode attributes!
• common default value: 022 002
![Page 30: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/30.jpg)
umask
![Page 31: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/31.jpg)
umask 022
owner group other
original file mode rw-110
rw-110
rw-110
umask 000 010 010
mode of created file rw-110
r—100
r—100
![Page 32: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/32.jpg)
umask 002
owner group other
original file mode rw-110
rw-110
rw-110
umask 000 000 010
mode of created file rw-110
rw-110
r—100
![Page 33: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/33.jpg)
chmod
• chmod!
• change file mode(permissions)!
• usage!
• chmod 755 file!
• chmod ug+x file
![Page 34: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/34.jpg)
chmod
![Page 35: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/35.jpg)
Search
![Page 36: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/36.jpg)
Grep
• Options!• -v, -l,-L, -A, -B,n, -r/-R!
• Case!• get templates contains `misc` cssfile!
• get templates not contain `footer.php`!
• contain `misc` but not `footer.php`
![Page 37: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/37.jpg)
get templates contains `misc` cssfile
![Page 38: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/38.jpg)
get templates not contain `footer.php`
![Page 39: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/39.jpg)
contain `misc` but not `footer.php`
![Page 40: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/40.jpg)
Grep
![Page 41: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/41.jpg)
Find
• Options!• -name, -perm, -delete,-regex!• !!
• Case!• find all .swp files!• delete all .swp files!• find not .png and jpg file
![Page 42: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/42.jpg)
find and delete
![Page 43: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/43.jpg)
Find
![Page 44: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/44.jpg)
find perm
![Page 45: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/45.jpg)
trap
![Page 46: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/46.jpg)
Case Study
• deploywww!• fetch all imgs of a cssfile!• git pu
![Page 47: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/47.jpg)
fetch all imgs of a css file
![Page 48: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/48.jpg)
git pu
![Page 49: Shell basic](https://reader033.vdocuments.us/reader033/viewer/2022052412/558504abd8b42a8f078b51d8/html5/thumbnails/49.jpg)
Reference
• 《The Linux Command Line》William E. Shotts, Jr.!
• 20130109 - 李志业 - Shell编程