Shell Basic
@zhiyelee!
F2E!
https://github.com/zhiyelee
How to learn
• man man man !
• practice
dir/file manipulation
• mkdir / mkdir -p!
• rmdir / rmdir -p!
• rm -rf!
• cp -i!
• ln -s
cd
ls
• ls -- list directory contents!
• Options!
• -l,-a,-t!
• -Ut
ls
tree
• tree -- list files in tree-like format!
• Options!
• -a,-d,-f!
• -P,-I
tree
Display Files
cat
• cat - Concatenate Files!
• cat -n !
• cat -s
cat
cat multiple files
less & more
• less/more!
• less line move,more page move!
• does not read the entire input file before starting!
• less -N ...
tail & head
• tail !
• tail -f!
• tail -5!
!
• head!
• head -5
wc
• wc -l
echo
• echo -e!
• echo -n
echo
Identifying Commands
• type - Display A Command's Type!
• type cd!
• type ll
type
Identifying Commands
• which - Display An Executable's Location!
• which ls!
• cat `which hlfile`
which
Redirction
Redirection
• stdin,stdout,stderr!
• 0 1 2!
• /dev/null!
• < > >>!
• Case!
• redirect error!
• redirect stdout and error t...
2>&1
Permissions
" chmod – Change a file's mode!
" umask – Set the default file permissions!
" su – Run a shell as another user!
" sudo – Exe...
from《The Linux Command Line》William E. Shotts, Jr.
umask
• umask!
• the default permissions of created file!
• octal notation !
• express a mask of bits to be removed from a ...
umask
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—...
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...
chmod
• chmod!
• change file mode(permissions)!
• usage!
• chmod 755 file!
• chmod ug+x file
chmod
Search
Grep
• Options!
• -v, -l,-L, -A, -B,n, -r/-R!
• Case!
• get templates contains `misc` cssfile!
• get templates not contain ...
get templates contains `misc` cssfile
get templates not contain `footer.php`
contain `misc` but not `footer.php`
Grep
Find
• Options!
• -name, -perm, -delete,-regex!
• !!
• Case!
• find all .swp files!
• delete all .swp files!
• find not .png a...
find and delete
Find
find perm
trap
Case Study
• deploywww!
• fetch all imgs of a cssfile!
• git pu
fetch all imgs of a css file
git pu
Reference
• 《The Linux Command Line》William E. Shotts, Jr.!
• 20130109 - 李志业 - Shell编程
Shell basic
Upcoming SlideShare
Loading in …5
×

Shell basic

387
-1

Published on

introduce the basic shell command and some use Cases.

Published in: Software, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
387
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Shell basic

  1. 1. Shell Basic @zhiyelee! F2E! https://github.com/zhiyelee
  2. 2. How to learn • man man man ! • practice
  3. 3. dir/file manipulation • mkdir / mkdir -p! • rmdir / rmdir -p! • rm -rf! • cp -i! • ln -s
  4. 4. cd
  5. 5. ls • ls -- list directory contents! • Options! • -l,-a,-t! • -Ut
  6. 6. ls
  7. 7. tree • tree -- list files in tree-like format! • Options! • -a,-d,-f! • -P,-I
  8. 8. tree
  9. 9. Display Files
  10. 10. cat • cat - Concatenate Files! • cat -n ! • cat -s
  11. 11. cat
  12. 12. cat multiple files
  13. 13. 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
  14. 14. tail & head • tail ! • tail -f! • tail -5! ! • head! • head -5
  15. 15. wc • wc -l
  16. 16. echo • echo -e! • echo -n
  17. 17. echo
  18. 18. Identifying Commands • type - Display A Command's Type! • type cd! • type ll
  19. 19. type
  20. 20. Identifying Commands • which - Display An Executable's Location! • which ls! • cat `which hlfile`
  21. 21. which
  22. 22. Redirction
  23. 23. Redirection • stdin,stdout,stderr! • 0 1 2! • /dev/null! • < > >>! • Case! • redirect error! • redirect stdout and error to a file
  24. 24. 2>&1
  25. 25. Permissions
  26. 26. " 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
  27. 27. from《The Linux Command Line》William E. Shotts, Jr.
  28. 28. 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
  29. 29. umask
  30. 30. 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
  31. 31. 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
  32. 32. chmod • chmod! • change file mode(permissions)! • usage! • chmod 755 file! • chmod ug+x file
  33. 33. chmod
  34. 34. Search
  35. 35. 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`
  36. 36. get templates contains `misc` cssfile
  37. 37. get templates not contain `footer.php`
  38. 38. contain `misc` but not `footer.php`
  39. 39. Grep
  40. 40. Find • Options! • -name, -perm, -delete,-regex! • !! • Case! • find all .swp files! • delete all .swp files! • find not .png and jpg file
  41. 41. find and delete
  42. 42. Find
  43. 43. find perm
  44. 44. trap
  45. 45. Case Study • deploywww! • fetch all imgs of a cssfile! • git pu
  46. 46. fetch all imgs of a css file
  47. 47. git pu
  48. 48. Reference • 《The Linux Command Line》William E. Shotts, Jr.! • 20130109 - 李志业 - Shell编程
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×