+ All Categories
Home > Software > Shell basic

Shell basic

Date post: 20-Jun-2015
Category:
Upload: lee-zhiye
View: 325 times
Download: 0 times
Share this document with a friend
Description:
introduce the basic shell command and some use Cases.
Popular Tags:
49
Shell Basic @zhiyelee F2E https://github.com/zhiyelee
Transcript
Page 1: Shell basic

Shell Basic

@zhiyelee!F2E!

https://github.com/zhiyelee

Page 2: Shell basic

How to learn

• man man man !

• practice

Page 3: Shell basic

dir/file manipulation

• mkdir / mkdir -p!

• rmdir / rmdir -p!

• rm -rf!

• cp -i!

• ln -s

Page 4: Shell basic

cd

Page 5: Shell basic

ls

• ls -- list directory contents!• Options!

• -l,-a,-t!• -Ut

Page 6: Shell basic

ls

Page 7: Shell basic

tree

• tree -- list files in tree-like format!• Options!

• -a,-d,-f!• -P,-I

Page 8: Shell basic

tree

Page 9: Shell basic

Display Files

Page 10: Shell basic

cat

• cat - Concatenate Files!• cat -n !• cat -s

Page 11: Shell basic

cat

Page 12: Shell basic

cat multiple files

Page 13: Shell basic

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

tail & head

• tail !• tail -f!• tail -5!

!

• head!• head -5

Page 15: Shell basic

wc

• wc -l

Page 16: Shell basic

echo

• echo -e!• echo -n

Page 17: Shell basic

echo

Page 18: Shell basic

Identifying Commands

• type - Display A Command's Type!• type cd!• type ll

Page 19: Shell basic

type

Page 20: Shell basic

Identifying Commands

• which - Display An Executable's Location!• which ls!• cat `which hlfile`

Page 21: Shell basic

which

Page 22: Shell basic

Redirction

Page 23: Shell basic

Redirection

• stdin,stdout,stderr!• 0 1 2!

• /dev/null!• < > >>!• Case!

• redirect error!• redirect stdout and error to a file

Page 24: Shell basic

2>&1

Page 25: Shell basic

Permissions

Page 26: Shell basic

" 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

from《The Linux Command Line》William E. Shotts, Jr.

Page 28: Shell basic
Page 29: Shell basic

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

umask

Page 31: Shell basic

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

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

chmod

• chmod!

• change file mode(permissions)!

• usage!

• chmod 755 file!

• chmod ug+x file

Page 34: Shell basic

chmod

Page 35: Shell basic

Search

Page 36: Shell basic

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

get templates contains `misc` cssfile

Page 38: Shell basic

get templates not contain `footer.php`

Page 39: Shell basic

contain `misc` but not `footer.php`

Page 40: Shell basic

Grep

Page 41: Shell basic

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

find and delete

Page 43: Shell basic

Find

Page 44: Shell basic

find perm

Page 45: Shell basic

trap

Page 46: Shell basic

Case Study

• deploywww!• fetch all imgs of a cssfile!• git pu

Page 47: Shell basic

fetch all imgs of a css file

Page 48: Shell basic

git pu

Page 49: Shell basic

Reference

• 《The Linux Command Line》William E. Shotts, Jr.!

• 20130109 - 李志业 - Shell编程


Recommended