command
basic
-
backslash 1 for shell command, (newline) represent a same line
-
vairables with curly brackets variable expansion ${}
- distinguish it from other string: echo “${foo}name”
- excute some script:
get array
${array[1]}
replace variables:${var/de/12}
;
-
curly braces $(): command expansion
text transform
awk vs sed: text process
differ:
- sed:
- awk: more powerful
awk
- print match
|
|
- print some colume
|
|
- find some columme is equal to a value
|
|
- get total count: if … do
|
|
sed
- print the match
|
|
|
|
wc

word, line, character, and byte count
-l: line -w: worods -c: characters
source
read and excute commands from the file
use case
define some global variable
|
|
source a.txt
file manager
1. inspecg
- du: display directory usage
- -s(summarize): total for the direcotry
- -a: all file size
|
|
create:
- mkdir
- -p: create intermediate directories as required
update
- mv
del;
- rm
- -r –recursive: remove the directories and their contents
- -f –force:
- ignore prompt(whether to remove the file)
- a file is unwritable;stdin is a terminal,
- not show any error message if the file not exis;
- ignore prompt(whether to remove the file)
mv
mv source target rename: if target isn’t exist;
move: target is a directory and exist;
rm
-
-f –force: force without prompt,prompt when
- a file is write protected
1
chmod 444 a.txt; rm a.txt
- a file is write protected
-
-r –recursive: remove directory and their contents recursively
tree
tree -l num: depth, current dirctory is 1; tree -d: print directories only;
http
curl
create request
|
|
|
|
redirection
change the standinput(keyboard) standout(screen) to another object
-
three open file:
- 0:
- 1: standard output(default in terminal )
- 2: standard error(default in terminal )
-
>
: overwrite file -
>>
: append file -
case:
1 2
>/dev/null = 1>/dev/null 2>&1: error
basic concept
-
EOF: represent start[end] of file;
-
single arror vs double array output: single: overwrite double: append input: single: for file double:
1 2 3
cat << EOF ab EOF
-
change the output to a file
echo 'a' > a.txt
-
change the input to a file
|
|
: overwrite
: append
directory manage
1. find: walk a file hierarchy
-maxdepth:
-mindepth:
-name: file name
-type: f: file
2. cd
-
: last dirctory
download and archieve
-
wget:download
- -c: resume getting a partially-downladed file
- -O: the name of the downloaded file
-
tar: compress or exact file: tar xvfz
1 2
tar -cvf a.tar file1 fil2 tar -xvf a.tar
-
-C: the target directory
-
-f: the archive file
-
-v: verbose
-
-z: work only in c mode, compress the file with gzip
-
mode:
- -c: compress
- -x: exact
-
privilege
chown
what: change owner
umask
director:777 files:6666
sync file
rsync
rsync source to dest
argumetns:
- -a: archive mode, which preserves file permissions, ownership, timestamps, etc.
-t
,--times
preserve modification times-g
,--group
preserve group- -o
,
–owner` preserve owner (super-user only)
- -z: comprese during tranfering
what happen if uid not exist in des host: the file will owed by souce host owner’s id
|
|
example:
-
rsync - avz /movies/* /api : sync all files to /api/, /api/move1 /api/movie2
-
rsync -avz /movies /api: sync directory and file to /api, /api/movies/movie1….
-
parameters
- –exclude,–include: from left to right
- -a: preserve meta data;
- -r, –recursive recurse into directories
- -l, –links Copy symlinks as symlinks
- preserve
- -p, –perms Preserve permissions
- -t, –times Preserve times
- -g,-o, –Preserve group,user(only take effect in super user mode)
- –devices, This option causes rsync to transfer character and block device files to the remote system to recreate these devices.
- –specials: This option causes rsync to transfer special files such as named sockets and fifos.
- -c: compress during sync
- –include
- –exclude
-
case: sync a.txt to b a/{c.txt,d.pdf, a1/a.txt} b
1
sync a/ b --include *.txt --inclue='*.txt' --include='*/' --exclude='*' -avc
rsync /mnt/tang01/qbitdownload/movie/* /mnt/tang01/movies/movie ' –exclude='*' -avc –chmod=a=rwx'
process manager
ps, pgrep
ps: report the running process pgrep: get all pid of match name(only need partly match )
ps:
- ps -u root: get the state of owner’s root
|
|
- ps aux : detail information of some pid
- -o: specify the output fromat
- ps -o user,group,pid -p 1234
kill
pkill
- pkil processname: only partly match
|
|
- pkill -x: full match