Professional Documents
Culture Documents
linux
cat
cat [-AbeEnstTuv] [--help] [--version] fileName
> fileName
-n --number 1
-b --number-nonblank -n
-s --squeeze-blank
-v --show-nonprinting
: /usr/bin/ :
cd /usr/bin
home directory :
cd ~
:
cd ../..
: chmod
:
: chmod [-cfvR] [--help] [--version] mode file...
: Linux/Unix : chmod
:
mode : : [ugoa...][[+-=][rwxX]...][,...] u
g (group) o a
+ - =
r w x X
-c :
-f :
-v :
-R : ()
--help :
--version :
: file1.txt :
chmod ugo+r file1.txt
file1.txt :
chmod a+r file1.txt
file1.txt file2.txt
:
chmod ug+w,o-w file1.txt file2.txt
ex1.py :
chmod u+x ex1.py
:
chmod -R a+r *
chmod chmod 777 file
chmod abc file
a,b,c
: chown
: root
: chmod [-cfhvR] [--help] [--version] user[:group] file...
: Linux/Unix chown
(root)
(root)
:
user : IDgroup : (group)-c :
-f :
-h : (link) link -v :
-R : (
)--help : --version :
3
:
file1.txt users jessie :
chown jessie:users file1.txt
users lamport :
chmod -R lamport:users *
cp
-a
-r source
-f
aaa () bbb :
cp aaa bbb
C Finished :
cp *.c Finished
cut
num1 num2
test2
this is test1
shell>> cut -c0-6 example ## print 6
test2
this i
: find
: find
:
expression
find path expression - ( ) , !
path expression path expression
-print expression
expression
-mount, -xdev :
-amin n : n
-anewer file : file
-atime n : n
-cmin n : n
-cnewer file : file
-ctime n : n
-empty : -gid n or -group name : gid n group name
-ipath p, -path p : p ipath
-name name, -iname name : name iname
-size n : n b 512 c k kilo
bytes w -type c : c
d:
c:
b:
p:
f:
l:
s: socket
-pid n : process id n
( )
exp1 -and exp2
! expr
-not expr
exp1 -or exp2
exp1, exp2
:
c
# find . -name "*.c"
# find . -ftype f
20
# find . -ctime -20
less
less
( vi)
: ln
:
: ln [options] source dist
option :
-f : dist -d : -i :
dist -n : dist -s :
(symbolic link)-v : -b :
-S SUFFIX : SUFFIX -V METHOD :
--help : --version :
:
yy symbolic link : zz
ln -s yy zz
yy hard link : zz
ln yy xx
locate
locate
distribution contab
# locate your_file_name
-u
-U
-u
-U
-e
-l
1
locate
-f
-q
proc
-n
-r
-o
-d
-h
-v
-V
locate chdrv : chdrv
locate -n 100 a.out : a.out
locate -u :
100
: ls
:
: ls [-alrtAFR] [name...]
:
-a (ls "."
-l
-r ()
-t
-A -a
"." () ".." ()
-F "*", "/"
-R
s
ls -ltr s*
/bin :
ls -lR /bin
ls -AF
"/", "*" :
more
more [-dlfpcsu] [-num] [+/pattern] [+linenum] [fileNames..]
cat
space b back
vi
h
-num
-d [Press space to continue, q to quit.]
-p
-c -p
-s
-u
TERM terminal
9
+/ pattern
+num num
fileNames
mv
aaa bbb :
mv aaa bbb
C Finished :
mv -i *.c
rm
rm [options] name...
-i
-f
-r
C :
rm -i *.c
10
Finished :
rm -r Finished
rmdir
-p
rmdir AAA
AAA :
BBB
BBB
rmdir -p BBB/Test
Test
Test
BBB
split
INPUT PREFI
Xaa, PREFIXab... PREFIX `x INPUT `-
-b, --bytes=SIZE
SIZE
-C, --line-bytes=SIZE
byte
11
byte
-l, --lines=NUMBER
NUMBER
-NUMBER
-l NUMBER
--verbose
--help
--version
SIZE : b 512
k 1K
m 1 Meg
PostgresSQL
Postgres
split
dump
% createdb dbname
% cat filename.dump.* | pgsql dbname
touch
touch [-acfm]
[-r reference-file] [--file=reference-file]
12
[-t MMDDhhmm[[CC]YY][.ss]]
[-d time] [--date=time] [--time={atime,access,use,mtime,modify}]
[--no-create] [--help] [--version]
file1 [file2 ...]
touch
ls -l
a
m
c --no-create
f unix
r --file
d
t date
--no-create
--help
--version
touch file
touch file1 file2
file 5 6 18 3 date
MMDDHHmm
14
linux [2]
Linux
: at
:
: at -V [-q queue] [-f file] [-mldbv] TIME
: at TIME TIME
HH:MM HH MM am, pm, midnight, noon,
teatime( 4 )
MMDDYY MM/DD/YY M
M DD YY now +
minutes, hours, days, weeks
today tomorrow ent
er at ctrl+D
:
-V :
-q : (Queue) at queue
queue queue a, b, c... z A, B, ... Z 52
-m : /,
-f file :
-l : ( atq at -l)
-d : ( atrm at -d)
-v :
:
5 /bin/ls :
at 5pm + 3 days /bin/ls
5 /bin/ls :
at 5pm + 2 weeks /bin/ls
17:20 /bin/date :
at 17:20 tomorrow /bin/date
15
cal
(1-9999)
``cal 89\ 1989
1752 9 3 10
-m :
-j :
-y :
cal :
Th Fr Sa Su Mo Tu We Th Fr Sa
3 4 5 6 7 8 9
18 19 10 11 12 13 14 15 16
25 26 17 18 19 20 21 22 23
29 30
17
cal -m :
cal -jy :
18
Sun
306
310
317
324
331
366
Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
307 308 309 336 337
311 312 313 314 315 316 338 339 340 341 342 343 344
318 319 320 321 322 323 345 346 347 348 349 350 351
325 326 327 328 329 330 352 353 354 355 356 357 358
332 333 334 335 359 360 361 362 363 364 365
[root@mylinux /root]#
: crontab
:
:
crontab [ -u user ] filecrontab [ -u user ] { -l | -r | -e }
:
crontab
-u user user (
root) -u user
:
-e : VI
VISUAL ( setenv VISUAL joe)
-r :
-l :
:
f1 f2 f3 f4 f5 program
f1 f2 f3 f4 f5
program
f1 * program f2 *
f1 a-b a b f2 a-b
a b
f1 */n n f2 */n n
f1 a, b, c,... a, b, c,... f2 a, b, c,... a, b,
20
c...
20 /usr/bin/backup :
5:00 alex@domain.name :
0 17 * * 1-5 mail -s "hi" alex@domain.name < /tmp/maildata
0 20 , 2 20 , 4 20 .... echo "haha"
20 0-23/2 * * * echo "haha"
:
> /dev/null 2>&1
: date
:
:
date [-u] [-d datestr] [-s datestr] [--utc] [--universal] [--date=datestr] [--set=datestr] [-help] [--version] [+FORMAT] [MMDDhhmm[[CC]YY][.ss]]
:
date
:
:
% : %
%n :
%t :
%H : (00..23)
%I : (01..12)
%k : (0..23)
%l : (1..12)
21
%M : (00..59)
%p : AM PM
%r : (12 hh:mm:ss [AP]M)
%s : 1970 1 1 00:00:00 UTC
%S : (00..61)
%T : (24 )
%X : %H:%M:%S
%Z :
:
%a : (Sun..Sat)
%A : (Sunday..Saturday)
%b : (Jan..Dec)
%B : (January..December)
%c :
%d : (01..31)
%D : (mm/dd/yy)
%h : %b
%j : (001..366)
%m : (01..12)
%U : (00..53) ( Sunday )
%w : (0..6)
%W : (00..53) ( Monday )
%x : (mm/dd/yy)
%y : (00.99)
%Y : (0000..9999)
MMDDhhmm[[CC]YY][.ss]
MM DD hh mm CC YY
ss
:
-d datestr : datestr ()
--help :
-s datestr : datestr
-u :
--version :
:
:
date +%T%n%D
:
date +%B %d
22
(12:34:56) :
date --date 12:34:56
:
0 ( 1999/03/07) -
date +%-H:%-M:%-S 0 08:09:04
8:9:4 ( root)
root clock -w CMOS
: sleep
:
: sleep [--help] [--version] number[smhd]
: sleep
:
--help :
--version :
number : s m h d
s m h d
:
1
date;sleep 1m;date
time
time
CPU Linux
Linux time
time
23
-o or --output=FILE
time
-a or --append
-o
-f FORMAT or --format=FORMAT
FORMAT
time
\t
\n
%
C
time
Time resources
Memory resources
IO resources
Command info
Time Resources
E [hour]:minute:second
CPU
e CPU
S kernel mode
U user mode
P CPU CPU
Memory Resources
M KB
t KB
K stack+data+text KB
D unshared data area KB
p unshared stack KB
X shared text KB
24
byte
IO Resources
F
swap file)
W
c CPU
w I/O
I
O
r Socket Message
s Socket Message
k ( Signal )
Command Info
C
x ( Exit Status )
-p or --portability
real %e
user %U
sys %S
POSIX
-v or --verbose
time -v ps -aux
ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.4 1096 472 ? S Apr19 0:04 init
25
uptime
uptime [-V]
uptime
-V
uptime
chfn
shell>> chfn
shell>> chfn
Changing finger information for user
Password: [del]
Name[]:Johnney Huang ### finger
Office[]:NCCU
Office Phone[]: [del]
Home Phone[]: [del]
chsh
shell>> chsh
shell
shell>> chsh
Changing fihanging shell for user1
Password: [del]
New shell [/bin/tcsh]: ### [ shell]
[del]
shell>> chsh -l ### /etc/shells
/bin/bash
/bin/sh
/bin/ash
/bin/bsh
/bin/tcsh
/bin/csh
27
finger []
finger
finger
Login Name
User Name
Home directory
Shell
Login status
mail status
.plan
.project
.forward
.plan .project .forward Home Directory .plan
.pr
oject .forward finger
E-mail address
-l
-s
finger root
28
last
-R hostname
-num num
username username
tty
shell>> last -R -2
johnney pts/1 Mon Aug 14 20:42 still logged in
johnney pts/0 Mon Aug 14 19:59 still logged in
wtmp begins Tue Aug 1 09:01:10 2000 ### /var/log/wtmp
:login
^_^
passwd
29
-k
-l
-u
-f
-d , , root
.
-S , root .
[username] .
: who
:
: who - [husfV] [user]
: ID
CPU
:
-h :
-u : /
-s :
-f :
-V :
30
linux [3]
Linux
/etc/aliases
newaliases
# sendmail -bi
:
mail, mailq, newaliases, sendmail
mail []
mail
mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] user1 [user 2 ...]
i tty
(interrupt)
I
(Interactive)
v
(verbose)
31
n
s
c
b
mail.rc
cc
bcc
user2 user2
mail user1@email.address
mail user1@email.address user2
cronjob
mesg
:
: mesg [y|n]
y :
n :
:
mesg n
mesg
talk
write
wall
32
/etc/aliases
newaliases
# sendmail -bi
:
mail, mailq, newaliases, sendmail
: talk
:
:
talk person [ttyname]
:
:
person : person@machi
ne.name
ttyname : tty tty
.1 :
Rollaend
talk Rollaend
Rollaend :
33
pts/2 :
ctrl+l
: wall
:
:
wall [ message ]
:
"hi" :
wall hi
: write
:
:
write user [ttyname]
:
:
user :
34
ttyname : tty
tty
.1 :
Rollaend
write Rollaend
Rollaend :
ctrl+c
.2 : Rollaend
write Rollaend pts/2
Rollaend pts/2
pts/3 :
ctrl+c
: mesg n
kill
35
nice
nice [-n adjustment] [-adjustment] [--adjustment=adjustment] [--help] [--versi
on] [command [arg...]]
, , ,
adjustment 10, -20 () 19 ()
ls 1 :
nice -n 1 ls
ls 10 :
nice ls ls 10
: (priority) CPU Linux (rou
nd-robin) CPU CPU
ps
ps [options] [--help]
(process)
ps ,
-A
-w
-au
-aux
au(x) :
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
USER:
PID: pid
36
%CPU: CPU
%MEM:
VSZ:
RSS:
TTY: (minor device number of tty)
STAT: :
D: (
b I/O )
R:
S:
T:
Z:
W:
<:
N:
L: ( A I/O)
START:
TIME:
COMMAND:
ps
PID TTY TIME CMD
2791 ttyp0 00:00:00 tcsh
3092 ttyp0 00:00:00 ps
% ps -A
PID TTY TIME CMD
1 ? 00:00:03 init
2 ? 00:00:00 kflushd
3 ? 00:00:00 kpiod
4 ? 00:00:00 kswapd
5 ? 00:00:00 mdrecoveryd
.......
% ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.7 1096 472 ? S Sep10 0:03 init [3]
root 2 0.0 0.0 0 0 ? SW Sep10 0:00 [kflushd]
root 3 0.0 0.0 0 0 ? SW Sep10 0:00 [kpiod]
root 4 0.0 0.0 0 0 ? SW Sep10 0:00 [kswapd]
........
pstree
37
pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-G|-U] [pid|user]
pstree -V
, pid () init
(root) , id ,
-a ,
-c , ( *
pstree
init-+-amd
|-apmd
|-atd
|-httpd---10*[httpd]
%pstree -p
init(1)-+-amd(447)
|-apmd(105)
|-atd(339)
%pstree -c
init-+-amd
|-apmd
|-atd
|-httpd-+-httpd
| |-httpd
| |-httpd
| |-httpd
....
renice
renice priority [[-p] pid ...] [[-g] pgrp ...] [[-u] user ...]
(Process)()
-p pid id pid
-g pgrp (process group) id pgrp ()
38
-u user user
top
top [-] [d delay] [q] [c] [S] [s] [i] [n] [b]
process
d : ( interactive command) s
q : superuser top
c :
S : ( dead child process ) CPU time
s : ,
i : (idle) (zombie)
n : top
b : "n" top
;
top -n 10
:
top -s
top.log :
top -n 2 -b < top.log
skill
39
, TERM () , HUP , IN
T , KILL , STOP , CONT , 0
: -9 , -SIGKILL , -KILL , -l -L
-f /
-i /
-v /
-w /
-n /
, ,,,
-t ( tty pty )
-u
-p ( pid )
-c :
,,
() /
ALRM 14
HUP 1
INT 2
KILL 9 /
40
PIPE 13
POLL
PROF
TERM 15
USR1
USR2
VTALRM
STKFLT / i386, m68k, arm ppc
UNUSED / i386, m68k, arm ppc
TSTP /
TTIN /
TTOU /
STOP /
CONT /,
PWR /
WINCH
CHLD
ABRT 6
FPE 8
ILL 4
QUIT 3
SEGV 11
41
TRAP 5
SYS /
EMT /
BUS /
XCPU /
XFSZ /
PTY
skill -KILL -v pts/*
user1 , user2 , user3
skill -STOP user1 user2 user3
: kill
expr
###
shell>> expr length "this is a test"
14
###
shell>> expr 14 % 9
5
###
shell>> expr substr "this is a test" 3 5
is is
42
: tr
### 1.?
"tr":
#!/bin/sh
dir="/tmp/testdir";
files=`find $dir -type f`;
for i in $files
do
dir_name=`dirname $i`;
ori_filename=`basename $i`
new_filename=`echo $ori_filename | tr [:upper:] [:lower:]` > /dev/null;
#echo $new_filename;
mv $dir_name/$ori_filename $dir_name/$new_filename
done
clear
console clear
: reset, tset
: tset [-IQqrs] [-] [-e ch] [-i ch] [-k ch] [-m mapping] [terminal]
:
reset tset
?
login
o
cat
reset :
-p
44
-e ch
erase ch
-i ch
ch
-k ch
ch
-I
-Q erase
-Q
erase
-r
-s
TERM .login .profile
:
# reset ?
erase control-h
# reset -e ^B
# reset -s
Erase is control-B (^B).
Kill is control-U (^U).
Interrupt is control-C (^C).
TERM=xterm;
compress
compress unix .Z
uncompress
45
tar gzip
gzip
c
f (force)
v (verbose)
b 9 16 bits
16 bits (bits)
d
V
source.dat source.dat.Z
source.dat.Z
compress -f source.dat
source.dat source.dat.Z
-v -f
target.dat.Z
-b
9-16
16
46
compress -b 12 source.dat
source.dat.Z source.dat y
-df .Z source.dat
source.dat.Z
compress -d source.dat
compress -d source.dat.Z
lpd
-l:
#port: lpd getservbyname TCP/IP port
lpd port
/etc/rc.d
47
lpq
--
lpq [l] [P] [user]
lpq lpd
1. lp
# lpq -PlpRank Owner Job Files Total Size1st root 238 (standard input) 1428646 b
ytes
lpr,lpc,lpd
lpr
lpr [ -P printer ]
lpd
lpr
-p Printer: Printer
lp
www.c kkk.c lp
lpr -Plp www.c kkk.c
48
: lprm
--
/usr/bin/lprm [P] [file...]
-P
hpprinter 1123
1011
lprm 1011
fdformat
/dev/fd0d360 A:
360KB
/dev/fd0h1440 A:
1.4MB
/dev/fd1h1200 B:
1.2MB
/dev/fd0
49
setfdprm
-n
fdformat -n /dev/fd0h1440
A 1.4MB
mformat
mformat [-t cylinders] [-h heads] [-s sectors] [-l volume_label] [-F] [-I fsVer-sion] [-S
sizecode] [-2 sectors_on_track_0] [-M software_sector_size] [-a] [-X] [-C] [-H hidden_
sectors] [-r root_sectors] [-B boot_sector] [-0 rate_on_track_0] [-A rate_on_other_trac
ks] [-1] [-k] drive:
DOS mtools USE
_2M 2M S,2,1,
M
-t synlider
-h head
-s
-l
-F FAT32
-I FAT32
-S sector = 2^(+7)
-c cluster FAT
mat
-s
-M
-a mformat Atari
mfor
50
-X XDF xdfcopy
-H
-n
-r FAT12 FAT16
-B
-k
-0 0
-A 0
-2 2m
-1 2m
mformat a:
a:
/dev/fd0
mkdosfs
mkdosfs [ -c | -l filename ]
[ -f number_of_FATs ]
[ -F FAT_size ]
[ -i volume_id ]
[ -m message_file ]
[ -n volume_name ]
[ -r root_dir_entry ]
[ -s sector_per_cluster ]
[ -v ]
device
[ block_count ]
51
-c
-l
-f FAT , File Allocation Table) 2 Linux
FAT 2 FAT
-F FAT 12 16 12 16
FAT16
FAT16 FAT12
-i Volume ID 4 2e203a47
-m
-m 418
TAB DOS
-n Volume Name DOS format
-r 112
224
512
-s cluster 2
-v
Te
52