已转开发,博客新地址:http://welcomezhang.iteye.com/

Linux学习5:linux分享学习笔记

上一篇 / 下一篇  2011-08-06 13:30:10 / 个人分类:Linux

一、文件/目录处理
5}/[.su}u:N0–新建/复制/删除
yaZ"H!|E]`#^S0
cp -r 复制文件夹51Testing软件测试网 U$O ]CJ#T7J |2V
51Testing软件测试网1uQo9f0o2`y4QM
–文件权限51Testing软件测试网){[y] p-m+o.aTT f
-bash-3.00$ ls -l build_pkg.sh
#r&nKW_7[0-rwxr-xr-x 1 zhangweikuang.pt users 872 7月 13 07:50 build_pkg.sh51Testing软件测试网$t`Y7\Vk
其中,第2列表示有多少档名连结到此节点(i-node);我们使用的目录树却是使用文件名来记录, 因此每个档名就会连结到一个i-node。
k EC:m4?4]KB*g0rwx 421(可通过8421码来记忆)
+ZFJ~4j n,CU0ugo(a)
1{?oY]G:n3L0chmod(change mode)更改权限51Testing软件测试网 W*F];k Q*F8Pe
eg. 250代表-w- r-x ---,代表咱国家法律,意会吧~~
f_#n6k m051Testing软件测试网mW A:UJ
–符号链接
y`'\{;f2b-u0
-bash-3.00$lndiff.pl diffhardlink
7d*Np%E'o0-bash-3.00$ln -sdiff.pl diffsoftlink51Testing软件测试网,s(z`)en9Iy+`a
-rwxrwxr-x 2 jianzhi jianzhi 1048 6月 8 17:39 diffhardlink
1Fc tlE#q*i6~P0-rwxrwxr-x 2 jianzhi jianzhi 1048 6月 8 17:39 diff.pl51Testing软件测试网 s5u8C)zv
lrwxrwxrwx 1 zhangweikuang.pt users 7 7月 26 18:26 diffsoftlink -> diff.pl51Testing软件测试网hj.t ~b&\,X
硬链接和软链接的区别(伟匡简单地理解):
6d#L3y$}*sTd-G0软链接完全等同于windows下的快捷方式,当源文件被删除后,快捷方式断链,linux下会不停闪烁。51Testing软件测试网sF+a'UW n,F5p
硬链接相对于某一份文件的clone,删除某一个文件时,另一个依然存在,这是linux下的一个特色。51Testing软件测试网U S9w]n&p ~

Y:l4\&Qje051Testing软件测试网7}VQJj vwP
二、文本处理51Testing软件测试网9r4{ eis"}J4i
–grep/sed/awk (待good good study)51Testing软件测试网2]s X$s9EA2p^
who |awk '{Print $1}'|sort|uniq|wc -l51Testing软件测试网*{ j)l4i Ah't
who |awk '{Print $1}'|sort -u|wc -l
%g5nXd,vE$Av0awk -F'\t' '{if ($3 == 4) print $0 }' nav.txt | more
"O~m/b]0
-F,k/lE @t4qK0–vim51Testing软件测试网$gW8w9FF2j `
http://twiki.corp.taobao.com/bin/view/Taobao_AD_QA/Linux_vi_welcomezhang51Testing软件测试网5@](yWy

I~` x1p L+~ l}051Testing软件测试网S E!hW _
三、任务处理 –jobs/fg/bg/&
xzn/pq|+[*_0&
最经常被用到,这个用在一个命令的最后,可以把这个命令放到后台执行51Testing软件测试网rn8v8^m'P V
-bash-3.00$ sleep 100 &51Testing软件测试网l@;v#m.Uu^"[x

3p/E&QO.]P0ctrl + z挂起,可以将一个正在前台执行的命令放到后台,并且暂停51Testing软件测试网e5xZ t2Df#K6}$d-s

9NDN$K{c F3H.X0jobs查看当前有多少在后台运行的命令
lT,@aiS0[1] Done sleep 10051Testing软件测试网+S c@)M|Z
[2]- Stopped vim qp.txt
'M+S7W U$@H0[3]+ Stopped vim qphardlink51Testing软件测试网)^"G OaoYL

\,tCq+b0fg将后台中的命令调至前台继续运行51Testing软件测试网Md,uq D0F
如果后台中有多个命令,可以用 fg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)51Testing软件测试网:b*`(h MAu4V8W
51Testing软件测试网,s|7Y6eUf
bg将一个在后台暂停的命令,变成继续执行
b,AD7k3w${C"D~r0如果后台中有多个命令,可以用bg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)

#srFUa I8u/{KM;B1Lx0
f Dj O9S0

9XB _Z"Xx~:Swk051Testing软件测试网 B;Eq(x&]/WI

四、Shell
6JC ] b6_ @2jS"@X0–标准输入
standard input:程序获取输入的地方。
+j2p;T&S&B0-bash-3.00$ cat51Testing软件测试网-bV*E6~&]3zaHe+H xEb
this is a line of test
1HL*Fi^(w-F~4U0this is a line of test
H*W-aIt MR0
51Testing软件测试网M&~;c8Cl-N:I5]

51Testing软件测试网WAubh

-标准输出stardard output:程序输出信息(如文本)的地方。
jYNUx?I;J0标准错误输出stardard error:程序输出错误信息的地方。51Testing软件测试网U5a%hM2E)];f
51Testing软件测试网Rf\ VB!a%R Vt:f
–重定向
:R|hb b n0标准输出重定向:51Testing软件测试网"jDL_!x%cHV
-bash-3.00$ cat > sample.txt51Testing软件测试网mmF{*@
this a txt by cat51Testing软件测试网-w#T2h |Jb,| X
the detination is testing redirect standard output
\'F0yS5i,`%T0CTRL+D
51Testing软件测试网,G,o5j0A;s0q

51Testing软件测试网u+p2p a/cJtZ4j6K

向屏幕追加标准输出
)\`6F%hw:xmkS8oX0
-bash-3.00$ cat sample.txt
ht.MG$T.L} dj%Y0this a txt by cat
RbM/u d.H n\x1],F0the detination is testing redirect standard output
t\I M;h,}(@0-bash-3.00$ cat sample2.txt >> sample.txt51Testing软件测试网f2b+x.M*T A*s1yc
-bash-3.00$ cat sample.txt51Testing软件测试网7Dg f^6F
this a txt by cat
!f6UM;I'UY2}7K0the detination is testing redirect standard output
?&Yj mJz4|a7Y0the second sample51Testing软件测试网~$N@ J$O%{
stardard output(so)可能销毁原文件(重名时)51Testing软件测试网!B+g?1w)?3\)T a|Z&c
使用cat+so可以将多个文件逐个连接成一个较大的文件
/n aw.rr5r:P&{0
-bash-3.00$ cat sample.txt51Testing软件测试网5X]gS.|^;y |/f4v
this a txt by cat
3N;~9KW:X1XEW0the detination is testing redirect standard output
L%cw)kZ0-bash-3.00$ cat sample2.txt51Testing软件测试网(Av/o|;X^%C3_-D$Gw+M
the second sample51Testing软件测试网#d8d:o!Pek ]%O
-bash-3.00$ cat sample3.txt
!?bC,\ w:MZ0the third sample
skSh ~O+X0-bash-3.00$ cat sample.txt sample2.txt sample3.txt > sample_all.txt
5XduiBA-F%~K0-bash-3.00$ cat sample_all.txt
FFPmG"]$R*KOy(j(x0this a txt by cat
CX%D"Si$]1nFV2I%u k0the detination is testing redirect standard output
V8Ql%emsv7U_0the second sample51Testing软件测试网,X+A``N$B,W f
the third sample
[6F~8GEq0

er5Jb8jid0

nHFI#du1R0-管道:一个程序的输出是另一个程序的输入。51Testing软件测试网+W!~)nlH:TF4Eh
-bash-3.00$ who51Testing软件测试网gEuv.rDp
jiayi pts/1 Jul 31 13:16 (10.13.138.9)51Testing软件测试网2m'CK2os)IV.}
yangwan. pts/2 Jul 29 07:12 (10.13.138.63)51Testing软件测试网,G }6XmL8s L[)\J
zhangwei pts/6 Jul 31 17:08 (10.13.138.21)51Testing软件测试网*Grr$P2iM
jianzhi pts/9 Jul 29 11:32 (10.13.138.27)
|,M4^z9xu+]0-bash-3.00$ who
|grep 'zhang*'
+N l:FgkP0zhangwei pts/6 Jul 31 17:08 (10.13.138.21)
,w S2]PQi3A?#b051Testing软件测试网#sGxB[/o
–环境变量
0K$j%Y#{.w0PATH51Testing软件测试网#`!AqX:?I
-bash-3.00$echo $PATH
&yI q4mG0
/usr/java/jdk1.6.0_22/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin
2Fe`DL^_~0-bash-3.00$ ifconfig
O uEq`R2]_}0-bash: ifconfig: command not found51Testing软件测试网9zYN+X/hE_o
-bash-3.00$exportPATH=$PATH:/sbin
'~mc}-AJ8Jb1L0-bash-3.00$ifconfig
*A6Kh%^xY8Y0eth0 Link encap:Ethernet HWaddr 00:1E:C9:B6:DF:97
/}V_J6j5U2{0f!G @0inet addr:10.232.41.124 Bcast:10.232.41.255 Mask:255.255.255.051Testing软件测试网XB3V n SyyjR1gs
inet6 addr: fe80::21e:c9ff:feb6:df97/64 Scope:Link51Testing软件测试网b i4p Y$e!F s^
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:151Testing软件测试网3[KDS9h(g"Wy0D
......51Testing软件测试网-t6|9@)\ y0}w.n3jn
-bash-3.00$ echo $PATH51Testing软件测试网0X,cHblO\,@
/usr/java/jdk1.6.0_22/bin:/usr/lib64/qt-3.3/bin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/sbin
51Testing软件测试网] [!?.Z(lBx6B

51Testing软件测试网"H)H;wd)}+[ K2K!V

LANG51Testing软件测试网;v$|u]xEF
echo $LANG51Testing软件测试网\.Q+YJC6x"H
locale -a51Testing软件测试网 GA:I$eT{%YS
export LANG='zh_CN.gbk'51Testing软件测试网}4?5?"M6CZ?{
echo $LANG
&It^8v5[&EM0
51Testing软件测试网EYm,X(h1P)qd+~%h

NcG+e3Ob4v3n9}X0
SP kk7] M0–Shell编程 (待good good study)51Testing软件测试网U'{S9M;z3z ~N
51Testing软件测试网9D Ea-F c"X/}

&c^u s6_Aut0五、网络传送文件51Testing软件测试网5X|(_hfF2Z3e\
–linux互相传送:scp51Testing软件测试网W,]vlL!U
scp /path/to/localfile <host>:/path/to/remotefile51Testing软件测试网!t:w*BSGh'[0|pKA
scp <host>:/path/to/remotefile /path/to/localfile51Testing软件测试网 h `NSn;CQ
scp /path/to/localfile <user>@<host>:/path/to/remotefile
5s*z%S4V$u#{.U n/d0scp <user>@<host>:/path/to/remotefile /path/to/localfile
%t%h|!Nz9@z)xk0
Y5N*dC:?:{0–linux/windows:sz/rz51Testing软件测试网ha*@ _M B|
51Testing软件测试网 V6Pl;],]

*Dd]4vH9O _051Testing软件测试网eS D-jD/m6f4t
六、 ctrl-c、ctrl-z、ctrl-d
RN&o&F Y |8k0
ctrl-c 发送 SIGINT 信号给前台进程组中的所有进程。常用于终止正在运行的程序。51Testing软件测试网4v5n(Xp"F{
ctrl-z 发送 SIGTSTP 信号给前台进程组中的所有进程,常用于挂起一个进程。
e6EZ @#ul0ctrl-d 不是发送信号,而是表示一个特殊的二进制值,表示 EOF。

sVW'T ^7X2oW5M0

8XXj qp0Key Function51Testing软件测试网;G {5J'Ph__
Ctrl-c Kill foreground process51Testing软件测试网bT[kh g j
Ctrl-z Suspend foreground process51Testing软件测试网.g;eHF.?+h'~n
Ctrl-d Terminate input, or exit shell51Testing软件测试网E_|d4]J DM2T

51Testing软件测试网^-i,gp*z,|

七、常用命令51Testing软件测试网])z$RvI4w'n7g,h
ž识别主机(查看主机名)
:uname -n 或 hostname
j'ClH e0ž识别用户(查看当前的用户)51Testing软件测试网&J3?4ns'^U
查看当前所有的用户:whoami 或 id -un51Testing软件测试网o$Vj[$U^I dU
查看用户自己: who 或 w51Testing软件测试网+chLxpA
51Testing软件测试网:QG3zA3d+w
ž打包
oR'D*z7cq0
tar -cvf /tmp/file.tar /path/ --exclude=“file.*”
'KZ O/O$P4e0tar xvf /tmp/file.tar -C /path/dir51Testing软件测试网-h?9}Av5S d}.b m
tar czvf
PnFAj0tar xjvf
:EQi9~/M(g,~+d"b3W0ž压缩51Testing软件测试网 I,\T9nXQ
gzip/gunzip
(d4n [6t9HHe&_0bzip2/bunzip251Testing软件测试网 O/b:v0]C*h_O7_'q&y7p

\X [g*bWd/F-O0八、如何登录英文版Google51Testing软件测试网3^ sUKlK+{*Gt
http://www.google.com/ncr 51Testing软件测试网H g:Xb8_&I


TAG: Linux linux

 

评分:0

我来说两句

Open Toolbar