Linux基本命令

------chvt n:切换终端----------------

-------------密码----------------------
jacky:jacky
root:root
-------------------------------------------------------------
0.echo $PATH //查看系统环境变量

1.locale //locale 命令将有关当前语言环境或全部公共语言环境的信息写到标准输出上

---------------misc------------

1.whoami //print effective userid:显示当前使用shell的用户,即使用该命令的用户

2.who //show who is logged on:显示 所有 登录Linux的用户

2.who -uH //查看详细情况

3.w // Show who is logged on and what they are doing.(比who更详细)
-------------查看文件-------------------------------

----cat命令:

1.cat -n file1 file2 | more -5

2.[jacky@localhost t1]$ cat -nTE aa

1 drwxrwxr-x 2 aaa root 4096 Sep 2 09:51 b$ //-E:每行末尾加$
2 drwxrwxr-x 2 jacky jacky 4096 Aug 21 20:23 dir$
3 ^Ilrwxrwxrwx 1 root root 1 Sep 2 08:57 slink2 -> a$ //-T:^I表示tab
4 -rw-r--r-- 1 root root 0 Aug 26 08:24 cc$
5 -rw-rw-r-- 1 jacky jacky 174 Sep 3 17:12 aa$
6 ^I-rw-rw-r-- 3 root jacky 39 Sep 2 09:49 a$
7 -rw-rw-r-- 3 root jacky 39 Sep 2 09:49 hlink2$
8 -rw-rw-r-- 3 root jacky 39 Sep 2 09:49 hlink3$
9 total 24$


-----tac:从文件的最后一行显示(与cat相反)


-----tail -3 aa.txt //显示倒数3行


-----head -3 aa.txt //显示头3行


-----cp 命令--------------------------

-a:same as -dR --preserve=all


-p: --preserve[=ATTR_LIST] //注:(default: mode,ownership【包括ACL的所有属性】,time‐stamps),该选项默认保护 被拷贝对象的 mode,owner,time
// if possible additional attributes: context, links, xattr, all

-d:same as --no-dereference --preserve=links //保护'符号链接'属性,

'cp -d slink slink1' //即-d使得 slink1 仍然是’符号链接‘;否则slink1是普通文件

-p:same as --preserve=mode,ownership,timestamps //-p:保护 复制文件的 访问模式,所有权,时间属性,包括ACL规则

-R,-r //copy directories recursively

=='例子'

cp -s file slink //创建符号链接

cp -l file hlink //创建硬链接

'cp -rp /home/t /temp' //复制这个目录树,并保护/home/t中文件(目录)的 mode,ownership,timestamps

'cp -a /home/t /temp' //复制整个目录树,并保护/home/t............ 所有属性



3.rm -r/-R dir //delete all the file in selected dir,including the dir and empty dir
//rm命令默认不能删除目录

rm -i file //提示是否删除文件
rm -I a b c d //当删除>3个文件或递归删除目录中文件时,提示。
rm -f file //强制删除文件
rm -ir dir //逐个提示是否删除dir目录中的子目录中的文件及子目录及dir目录(删除顺序:深度遍历)
rm -Ir dir //只提示一次是否递归删除所有文件及目录
rm -if file //*****此时-i失效*****
rm -ivr dir //-v:verbose:显示what is being done

'cp \ bcd ./-abc' //将' bcd'复制为'-abc'

rm -- -file //删除已“-”开头的文件
rm ./-file

4.mv *.txt t //move all the .txt to dir t

5.rmdir a/b/c //delete empty dir c

6.rmdir -p a/b/c //delete all the empty dir

7.mkdir -p a/b/c // create all the dir

8.ls >> a/b/a.dat //追加到文件尾
ls > a.dat //覆盖文件内容。

9.pwd //show current dir



-------ls (无法区分文本文件和二进制文件。file命令可以)

------Linux 文件类型;

2.1 f 普通文件(二进制文件,文本文件,ASCII文件。。。);
2.2 d 目录;
2.3 c|b字符设备或块设备文件(mknod命令创建,一般不用我们自己创建,这类文件一般和内核关联);
2.4 s 套接口文件;
2.5 l 符号链接文件;

/****增加易读性-h,倒序-r*****/

ls -i /dev/* //判断等效文件:查看/dev/目录下文件的 inode 号。(拥有相同inode号的文件,即互为 硬链接)


ls -a a/b //show all the files, including hidden files
. .. a.dat a.txt .txt

ls -l a/b

ls -F a/b //以特殊符号标识 不同文件类型; *:可执行文件(程序或脚本); /:目录 ; @:符号链接,软链接

a.dat a.gz a.txt Link to a.gz@

ls -lR a //*******查看目录递归结构********//
a:
total 4
drwxrwxr-x. 2 jacky jacky 4096 Mar 3 03:43 b

a/b:
total 4
-rw-rw-r--. 1 jacky jacky 102 Mar 3 03:40 a.dat
-rw-rw-r--. 1 jacky jacky 0 Mar 3 03:42 a.gz
-rw-rw-r--. 1 jacky jacky 0 Mar 3 03:33 a.txt
lrwxrwxrwx. 1 jacky jacky 40 Mar 3 03:43 Link to a.gz -> /home/jacky/Documents/command/t/a/b/a.gz

ls -alhr //列出当前目录下包括隐藏文件的所有文件或目录,增加易读性-h,倒序-r

------例子
[jacky@localhost t1]$ ll
total 28
rw-rw-r-- 5 jacky jacky 4 Aug 20 19:47 a (硬链接个数)
drwxrwxr-x 3 jacky jacky 4096 Aug 20 20:07 b
-rw-rw-r-- 5 jacky jacky 4 Aug 20 19:47 hlink
-rw-rw-r-- 5 jacky jacky 4 Aug 20 19:47 hlink1
-rw-rw-r-- 5 jacky jacky 4 Aug 20 19:47 hlink2
-rw-rw-r-- 5 jacky jacky 4 Aug 20 19:47 hlink3
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:12 slink -> a
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:16 slink1 -> a

------/***** Sort排序 *******/

1.[root@localhost t1]# ll | sort -k5 -r // -k:按照字段5;-r:反序。

drwxrwxr-x 2 jacky jacky 4096 Aug 21 20:23 dir
drwxrwxr-x 3 jacky jacky 4096 Aug 20 20:07 b
-rw-rw-r-- 3 root jacky 21 Aug 20 23:00 hlink3
-rw-rw-r-- 3 root jacky 21 Aug 20 23:00 hlink2
-rw-rw-r-- 3 root jacky 21 Aug 20 23:00 a
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:16 slink1 -> a
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:12 slink -> a
-rw-r--r-- 1 root root 0 Aug 26 08:24 cc
-rw-rw-r-- 1 jacky jacky 0 Aug 21 20:24 aa
total 20

2.ll | sort -o a.txt //将排序的结果 输出到文件 而非标准输出(write result to FILE instead of standard output)
ll | sort > a.txt


-----------ln



[jacky@localhost t]$ ln -v aa.txt hlink //-v verbose:print name of each linked file
`hlink' => `aa.txt' (硬链接)

[jacky@localhost t]$ ln -vs aa.txt slink
`slink' -> `aa.txt' (软链接)


-----find___________________________________________

+n for greater than n,

-n for less than n,

n for exactly n.

------------

time:天数 min:分钟数
-atime +4 -amin +4 //access: 访问操作,如:cat/vim
-ctime +4 -cmin +4 //status change:修改文件状态(包括所有ls -l查出的的状态),如:chmod/chown/touch(该时间).
-mtime +4 -mmin +4 //data modify: 文件数据被修改

--------------
-perm

a. 664 : 6 && 6 && 4 //恰好匹配664的文件
b.-664 : >= '664' //匹配权限 > 或 = 664 的文件
c./640 : 6 || 4 || 0 //匹配 [至少]满足u=rw || g=r || o=0 三个条件中[任何一个]的文件:600040,[000不可以],6XX,X4X,XX0
d./642 : 6 || 4 || 2 //匹配 6XX X4X XX2

//通配符(wildcard)需用‘’引起或以\开头。

[jacky@localhost t1]$ find . -name '*[0-2]' -ok ls -l {} \; // ;不能丢,-ok则在执行命令前询问,{}是查找出的文件名称占位符
< ls ... ./hlink2 > ? y
-rw-rw-r-- 3 jacky jacky 4 Aug 20 19:47 ./hlink2
< ls ... ./slink1 > ? y
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:16 ./slink1 -> a


[jacky@localhost t1]$ find . -name \*[0-2] -exec ls -l {} \; /*****通配符以\开头**/
-rw-rw-r-- 3 jacky jacky 4 Aug 20 19:47 ./hlink2
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:16 ./slink1 -> a

[jacky@localhost t1]$ find . -name \*hlink2 -exec grep 'love' {} \;
I love U so much!!

[jacky@localhost t1]$ find . -type l //查询当前目录下是软链接的文件;type:l-软链接,d-目录,f-普通文件
./slink1
./slink

[jacky@localhost t1]$ find . -type l -exec ls -F {} \;
./slink1@
./slink@


[jacky@localhost t1]$ find -name '?link*' -exec ls -Fl {} \; //
-rw-rw-r-- 3 jacky jacky 21 Aug 20 23:00 ./hlink2
-rw-rw-r-- 3 jacky jacky 21 Aug 20 23:00 ./hlink3
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:16 ./slink1 -> a
lrwxrwxrwx 1 jacky jacky 1 Aug 20 20:12 ./slink -> a


[jacky@localhost t1]$ find -name '?link*' -perm 664 //-perm:查找完全符合权限664的文件
./hlink2 //664:6 && 6 && 4
./hlink3 //-664:ge '664'
'/664':6 || 6 || 4
//3、为了查找系统中所有普通文件长度为0的普通文件,并列出它们的完整路径;

$ find / -type f -size 0 -exec ls -l { } \; //-size 0 <==> -empty


//4、查找/var/logs目录中更改时间在7日以前的普通文件,并在删除之前询问它们;

$ find /var/logs -type f -mtime +7 -ok rm { } \; //+7:>7 -7:<7


//5、为了查找系统中所有属于root组的文件;

$find . -group root -exec ls -l { } \;
-rw-r--r-- 1 root root 595 10月 31 01:09 ./fie1

[root@localhost Tes]# find . -user jacky -group root //查找文件user:group = jacky:root


//6、find命令将删除当目录中访问时间在7日以来、含有数字后缀的admin.log文件。

//该命令只检查三位数字,所以相应文件的后缀不要超过999。先建几个admin.log*的文件 ,才能使用下面这个命令

$ find . -name "admin.log[0-9][0-9][0-9]" -atime -7 -ok
rm { } \;
< rm ... ./admin.log001 > ? n
< rm ... ./admin.log002 > ? n
< rm ... ./admin.log042 > ? n
< rm ... ./admin.log942 > ? n


//7、为了查找当前文件系统中的所有目录并排序;

$ find . -type d | sort


//8、为了查找系统中所有的rmt磁带设备;

$ find /dev/rmt -print

//查找当前目录下空文件(文件必须为:f-普通文件;d-目录)
16,find . -empty
./t/bb.txt
./t/cc.txt
./t/a/b/a.txt
./t/a/b/a.gz
./t/a/b/.txt
./t/command.txt

//查找当前目录下的目录文件
17.find . -type d
.
./t
./t/a
./t/a/b

-size n[cwbkMG]
File uses n units of space. The following suffixes can be used:

‘b’ for 512-byte blocks (this is the default if no suffix is
used)

‘c’ for bytes

‘w’ for two-byte words

‘k’ for Kilobytes (units of 1024 bytes)

‘M’ for Megabytes (units of 1048576 bytes)

‘G’ for Gigabytes (units of 1073741824 bytes)


-------/*find命令中条件的逻辑运算*/

a.逻辑与 AND(默认)

1.find /chem /home -size +2048 -mtime +30 -exec ls -l {} \; //列出/chem 和 /home 目录下 '大于'1M 一个月前修改 的文件的长目录。

2.find /home -size +2048 -mtime +30 -ls // -ls 比 -exec ls -l 更有效率,因为目录列表是由find命令内部处理的,而不是为每个文件生成一个子shell

3.find /home/t1 -type l -print -name slink -exec rm {} \;
//1.找出满足-type 匹配标准的文件,然后-print
//2.查找 满足 -type && -name 的文件,如有,则 rm;没有,则 不删除
//总结: 满足 -name 的文件 必须先满足 -type, 才可以被删除。

b.逻辑或

1. find /home/ -size +2048 \( -mtime +20 -o -atime +10 \) -ls //列出/home目录下 '大于'1M 20天没修改 or 10天没访问的文件

/*当磁盘空间不够时,又旧又大的文件可用磁带备份,或删除之。 //size user perm
find 可以再找到文件后,自动进行删除,
下面就是典型的 @系统管理@ 用例 */

2. find / \( -name a.out -o -name core -o -name '*~' \
-o -name '.*~' -o -name '#*#' \) -type f -atime +14 \
-exec rm -f {} \; -o -fstype nfs -prune
/*该命令将搜索整个文件系统,找出符合的标准 及 对应的action处理如下:
* ‘;’用来分割 action [-exec|-prune]
*‘;’前的条件为 [a]: 文件名匹配,又是普通文件,且14天未曾访问。
* ‘;‘ 后的条件为 [b]: 文件系统类型是nfs(指远程磁盘)。
* 满足[a]--action:-exec rm -f {} \;删除之
* 如不满足[a],则判断[b];如果[b]为true,则 --action:-prune 每当find 搜索加载了NFS的文件系统时,就会略过整个NFS系统
*/



c.逻辑非

1.! -name gold.dat -name \*.dat //???



/*find命令在安全上的用途*/


a.查找设为 setuid 或 setgid 的文件

1.find / -type f \( -perm -2000 -o -perm -4000 \) -print
find / -type f -perm -6000 // -rwsr-sr-x. 1 root root 48840 Mar 16 23:01 /usr/bin/crontab

/*在选定的一组文件上执行相同命令*/

1.find /home/aaa -exec chown jacky {} \; -exec chgrp root {} \;// 等价于:find /home/aaa -exec chown jacky:root {} \;

2.ls -lR /home/aaa //查看更改情况

3.find /chem -name '*.c' -exec mv {} /chem1/src \; //将/chem下的 C语言源文件 移动到 src目录下

4.find /chem -name '*.c' -exec /usr/local/bin/prettify {} \; //将目录下当 .c 文件 执行prettify脚本程序(脚本的完整路径名包含在-exec中)

/*使用find 跟踪某段时间内 系统的变化 或 某个特定处理动作的结果*/

1.touch /tmp/starting_time
2.执行某项操作
3.find / -newer /tmp/starting_time //显示所有 执行过任何操作后 所修改的 或 增加的文件。它不会直接告诉所删除的文件,但会列出修改的目录

/*find完成批处理命令*/

1.find /tmp -name core -type f -print | xargs /bin/rm -f //


---------locate:快速搜寻文件系统内满足条件的文件。

工作原理:a.先建立一个包含系统内所有文件名称和路径的数据库,/etc/update.conf
b.之后寻找文件时就只查询这个数据库,而不必实际深入文件系统之中。

18.locate -n 10 link
/bin/link
/bin/readlink
/bin/unlink
/etc/prelink.cache
/etc/prelink.conf
/etc/prelink.conf.d
/etc/cron.daily/prelink
/etc/rpm/macros.prelink
/etc/sysconfig/prelink
/lib/modules/2.6.35.6-45.fc14.i686/kernel/drivers/char/synclink.ko


----------find && locate 都是根据‘文件名‘ or ‘ 文件属性‘查找文件,grep可以检索文件内容,找到文件中匹配模式(字符串or正则表达式)的文本行。

19. grep -i china file //-i 忽略大小写
China's SHaolin Temple is now part of

---//regex
grep
'^root' /etc/passwd --color

grep
'/bin/bash$' /etc/passwd --color

grep
':/home/.*:' /etc/passwd --color


----------touch:修改指定文件(目录)的访问时间(-a) and 修改时间(-m) 记录,默认修改为当前时间。

20.touch -t 1103082001.11 a.txt //修改时间戳Stamp: 2011 03 08 20:01:11
//create file if file doesn
't exist


----------diff:比较两个文件内容差异,diff3:比较三个文件内容差异


21.diff3 cat1 cat111 cat11
====3
1:2c
2:2c
Let's go
3:2,3c
WAIT ME
SunShine girl
====3
1:5a
2:5a
3:7,8c

------------tar(备份或压缩文件及目录):

'':首先应该明确:*nix系统中,使用tar对文件打包时,一般'不建议使用绝对路径。

通常是在'两台环境相似的机器上'进行'同步复制'的时候,才有需要使用绝对路径进行打包。
使用绝对路径打包时如果不指定相应的参数('-P'/'-C'),tar会产生一句警告信息:”tar: Removing leading `/’ from member names”,
并且实际产生的压缩包会将绝对路径转化为相对路径。


-----参数介绍

-r:将文件' 追加'到 备份文件末尾:append file to the end of an archive //tar rvf jacky.tar newfile
\
-t: '列出'备份文件所包含的文件: list the contents of an archive ==>'r/u不能用于.gz/.bz2'
/
-u: '更新'备份,如果备份文件中不存在要更新的文件,则执行'-r',追加到最后 //tar uvf jacky.tar name.txt

-c:'创建'新的备份文件

'-C:改变路径'

-f:指定备份文件名称,//其后必须有备份文件名,such as backup.tar

-v: 详细列出被处理的文件:verbosely list files processed

-x: 从备份文件中'释放'文件:'extract' files from an archive

-z: 用 gzip 来压缩/解压缩 文件:filter the archive through gzip

-j: 压缩/解压缩 xxx.tar.bz2 : filter the archive through bzip2

'-P': 允许使用'绝对路径'do not strip(剥去) leading `/ from the file names


-----命令举例

-----备份打包

1.tar cf archive.tar file1 dir1/ //将file1 和 dir1 备份--> archive.tar

2.tar -cvf archive.tar file1 //备份时列出被处里的文件信息

-----释放

3.tar xf archive.tar -C dir2/ //将archive.tar 中的文件 释放--> dir2/

4.tar xvf archive.tar -C dir2/ //释放时列出文件信息

-----查看

5.tar tf archive.tar //查看 archive.tar 中的文件

6.tar -tvf archive.tar //详细列出其中的文件

-----追加

7.tar rf archive.tar file2 //将文件file2 追加到 archive.tar 末尾

-----更新

8.tar uf archive.tar file1 //更新file1,如果不存在,则追加到末尾

-----压缩备份 & 解压释放

----//将/home/Jon/目录下的 Jon.txt 文件 && dir_jon目录 gzip -> Jon.tar.gz

9.tar czvf Jon.tar.gz -C /home/Jon/ Jon.txt dir_jon/ //-C:切换路径到/home/Jon/后,以其为[相对路径]
tar czvf Jon.tar.gz -P /home/Jon/Jon.txt /home/Jon/dir_jon //-P: 绝对路径
tar czvf Jon.tar.gz Jon.txt dir_jon/ //除非在/home/Jon/下,才不需要加-C/-P参数

0.tar xzvf archive.tar.gz -C dir2/ //解压释放 -> dir2目录
tar xzvf archive.tar.gz -P dir2/ //绝对路径

10.tar cf archive.tar `find . -mtime -1 -type f` //创建仅包括在前一天进行了更改的文件的存档

-----网络复制------

1.tar czPf - /bin/ksh /bin/csh | ssh 192.168.0.133 tar xzvPf - /bin/ //-P:绝对路径

2.tar czvf - -C /bin ksh csh | ssh 192.168.0.133 tar xzvf - -C /bin/ //-C:转换路径





-----gzip:压缩或解压文件(.gz格式)

1.gzip * //将当前目录下所有文件(such as, file1 file2)分别压缩为.gz格式(目录除外,不压缩目录)

gzip file1 file2 //[不保留原文件]:file1.gz && file2.gz 替换 file1 && file2 {将多个文件分别压缩}

gzip -c file1 file2 > a.gz //[保留原文件]:-c参数 {将多个文件压缩为一个gz}

cat file1 file2 | gzip > b.gz //[保留原文件]:比上一种压缩率高,更好


1.gzip jacky.tar //将.tar文件压缩为 .tar.gz

2.gzip -l jacky.tar.gz //显示jacky.tar.gz如下信息---压缩后文件的大小;未压缩前文件的大小;压缩比;未压缩前文件的名字

3.gzip -dv jacky.tar.gz //-d:decompress解压,-v:verbose
gunzip jacky.tar.gz

5.gzip -dc /path/to/image.gz | dd of=/dev/hdx //将压缩的备份文件恢复到指定盘
//-c:将output写到stdout;(从而,作为if=-)

---压缩率 -1/--fast 压缩快,因此压缩率低;-9/--best 压缩慢,因此压缩率高

6.gzip -1 a.txt

gzip -9 a.txt

'ADVANCED USAGE'
Multiple compressed files can be concatenated(连接的). In this case, gunzip will
extract all members at once. For example:

gzip -c file1 > foo.gz
gzip -c file2 >> foo.gz

Then

gunzip -c foo

is equivalent to

cat file1 file2

In case of damage to one member of a .gz file, other members can still be
recovered (if the damaged member is removed). However, you can get better
compression by compressing all members at once:

cat file1 file2 | gzip > foo.gz

compresses better than

gzip -c file1 file2 > foo.gz

If you want to recompress concatenated files to get better compression,
do:

gzip -cd old.gz | gzip > new.gz



29.cal 3 2011
March 2011
Su Mo Tu We Th Fr Sa
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

---------------------------------alias---------------------
30.alias cle=clear

[root@localhost mnt]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias rr='route | sort -k3 -r'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'




----------------------rpm的相关命令-------------------------------
1.rpm -ql flash-plugin //查看--list rpm包中所有文件的安装路径

2.rpm -aq | grep squid //查看已安装的squid相关软件。
'-a:查询所有已安装的包。'
3.rpm -qf /etc/inittab //查看inittab来自(from)哪个rpm包

4.rpm -q kernel //查看kernel包的具体版本号

5.rpm -Uvh file.rpm //升级一个rpm包

6.rpm -Uvh --oldpackage kernel-2.6.35.11-83.fc14.i686

-----'使用之前可能需要手动挂载光盘'

mount /dev/cdrom /mnt/source
-------

2.rpm -ivh /mnt/source/Server/kernel-2.6.35.11-83.fc14.i686 --percent //以百分比形式输出安装进度

3.rpm -ivh /mnt/source/Server/kernel-2.6.35.11-83.fc14.i686 --prefix /home/jacky/software //安装到指定路径

4.rpm -e file.rpm //卸载

6.rpm -fvh //只对安装的软件升级




----------------id:输出给定用户名的UID GID------------

1.id nobody



-----------------man命令:an interface to the on-line reference manuals---------------------------


1.manpath //查看man命令检索的文件所在路径:/usr/local/share/man:/usr/share/man

1.man man //查看man命令本身

-----相关文件

/etc/man_db.conf
man-db configuration file.

/usr/share/mani
A global manual page hierarchy.

/usr/share/man/index.(bt|db|dir|pag)
A traditional global index database cache.

/var/cache/man/index.(bt|db|dir|pag)
An FHS compliant global index database cache.






————————————————————————————————————————————————————————————————VI————————————————————————————————————————————————————


vi example.c //first line
vi + e.c //last line
vi +2 e.c //2nd line
:w e.c //save
:q //quit
:wq
:q! //don't modify and quit
:w e1.c //save to a new file
:x //the same as ZZ in normal,保存并退出
:!ls -l /etc/log //! execute anyway
:sh //暂时退出 exit或ctrl+d可以返回vim
:set nu //行好
:set nonu //取消行号
:/bin //查找bin , n到下一个bin,N到上一个bin
:f //显示当前编辑文件名
:set ic //查找时忽略大小写
!ls -l //强制执行


Normal
( ) //to another sentence
{ } //to paraph
[[ ]] //to next section
^ | $ //行首
5j | k | l | h //上下左右移动
gg //第一行首
G //末行首
w 移动每一单词
x | X //删除光标之前|后的一个char
dd //删除一行
D //删除光标到行尾
R //替换一个char
u //回复
4yy | p |P //复制 | 粘贴在光标一下|以上

r //gai xie
~ //可切换指定字母大小写
-----复制粘贴 //
[n] yy //复制从当前行开始的n行;省略n则复制当前行
[n] yw //复制接下来的n个字
p | P //粘贴

-----替换replace
R //一直替换直到按ESC停止
r //之替换当前char
-----删除命令
dw | db | dd | d$ |d0 //删除当前字 |前一个字|当前行|光标到行尾|到行首
d) | d( | d} | d{ //从当前字到句尾|句首|段尾|段首
dH | dM | dL //从当前行到屏幕首行|中间|末行

-----查找
/<pattern> //向文件尾查找匹配文本
?<pattern> //向文件头。。。。。
n | N //找到上一个匹配文本|下一个

----取消
u | U //撤销

----重复
dd... //则删除三行



----------------------Command------------------------



:s/old/new //只替换当前行的第一个old字符串
:2,5s/old/new //replace the first one in line2~5
:s/lod/new/g //replace all old in current line
:s/^/string/g //在行首插入string
:s/$/string/g //行尾








---------------mount and umount-------------------------------------------------

/***In order to make it possible to treat all types in a uniform way,
mount will execute the program /sbin/mount.TYPE (if that exists)
when called with type TYPE.
***/

/**1.当忘记从/etc/fstab中去掉 已被删除分区的 挂载配置时,
* 在重启时,会提示 Repair filesystem;
2.但此时 / 以只读方式挂载(mount命令查看),无法修改/etc/fstab,
执行 mount -o remount,rw / 即可以读写方式重新挂载 /
3.去掉/etc/fstab中 相关行,reboot即可
*/

0.mount -o remount,rw /

1.mount -o iocharset=cp936 /dev/sdb1 /mnt/usb //显示Window下的中文字符

1.mount -t vfat /dev/sdb1 /mnt/flash_momery //mount file
mount -l //显示lists all mounted filesystems,显示LABEL

2.fdisk -l //show the disk on Linux
3.df -lh //display the amount of disk space availiable of the filesystem

[root@localhost jacky]# df -lh //列出文件系统的使用情况. -l:只显示本地文件系统
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 8.9G 2.4G 6.5G 27% /
tmpfs 249M 436K 248M 1% /dev/shm
/dev/sda1 97M 43M 50M 46% /boot
/dev/sda3 2.0G 104M 1.8G 6% /home
/dev/sr0 686M 686M 0 100% /media/Fedora-14-i686-Live-Desktop
/dev/sdb1 2.0G 228K 2.0G 1% /mnt/flash_memory


----
'umount'卸载

4.umount /mnt/flash_momery //路径
umount /dev/sdb1 //设备

'umount -l /mnt/nfs/c' //-l:Lazy unmount. Detach the filesystem from the filesystem hierarchy now
//and cleanup all references to the filesystem as soon as it is not busy anymore
//立刻 从文件系统层级中 分离 被挂载的文件系统;在文件系统不忙的最快时刻,清空‘对fs的引用’

----
'umount'有时显示:'device is busy'

'a'-'解决方案'

[root@localhost /]# cd /mnt/nfs/c/ //在pts/0下,root进入挂载目录;

[root@localhost c]# umount 192.168.0.148:/mnt //此时由于挂载目录被占用,所以无法卸载
umount.nfs: /mnt/nfs/c: device is busy
umount.nfs: /mnt/nfs/c: device is busy

[root@localhost c]#
'fuser -mv /mnt/nfs/c/' //fuser:显示所有 正在使用 文件|目录的 进程
USER PID ACCESS COMMAND //-m NAME: NAME指定
'被挂载的文件系统中的文件(目录)''被挂载的设备'
/mnt/nfs/c/: root kernel mount /mnt/nfs/c // -m表示mount,即该选项指定挂载的fs or device

jacky 6426 ..c.. bash //在pts/1下,jacky进入挂载目录
root 6499 ..c.. bash //在pts/0下,root进入挂载目录;

[root@localhost c]#
'fuser -mvik /mnt/nfs/c' //-v:verbose mode
USER PID ACCESS COMMAND //-k:Kill processes accessing the file.
/mnt/nfs/c: root kernel mount /mnt/nfs/c //-i:杀死每个使用文件的进程时将提示
jacky 6426 ..c.. bash
root 6499 ..c.. bash
Kill process 6426 ? (y/N) y
Kill process 6499 ? (y/N) y

[jacky@localhost ~]$ su
Password:
[root@localhost jacky]# umount 192.168.0.148:/mnt
[root@localhost jacky]#

'b'-'解决方案'

[root@localhost c]# umount /mnt/nfs/c //
umount.nfs: /mnt/nfs/c: device is busy
umount.nfs: /mnt/nfs/c: device is busy

[root@localhost c]#
'umount -l /mnt/nfs/c' //


-------------------------------------------------------------------------------------------------------------

5.findmnt //show the mount point

TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda2 ext4 rw,relatime,barrier=1,data=
├─/proc /proc proc rw,relatime
│ ├─/proc/bus/usb /proc/bus/usb usbfs rw,relatime
│ ├─/proc/sys/fs/binfmt_misc none binfmt_m rw,relatime
│ └─/proc/fs/nfsd nfsd nfsd rw,relatime
├─/sys /sys sysfs rw,relatime
│ └─/sys/fs/fuse/connections fusectl fusectl rw,relatime
├─/dev udev devtmpfs rw,relatime,size=247960k,nr
│ ├─/dev/pts devpts devpts rw,relatime,gid=5,mode=620,
│ └─/dev/shm tmpfs tmpfs rw,relatime
├─/boot /dev/sda1 ext4 rw,relatime,barrier=1,data=
├─/home /dev/sda3 ext4 rw,relatime,barrier=1,data=
│ └─/home/jacky/.gvfs gvfs-fuse-daemon fuse.gvf rw,nosuid,nodev,relatime,us
├─/var/lib/nfs/rpc_pipefs sunrpc rpc_pipe rw,relatime
└─/mnt/nfs/c 192.168.0.148:/mnt nfs rw,relatime,vers=3,rsiz //NFS文件系统

6.ps //show current process



8.cat /etc/fstab //check filesystem info


-------------mkfs:格式化

9.mkfs -t ext3 /dev/hda4 // 先卸载再格式化;

10.mount.cifs -o jacky%jackydalong //JACKY-PC/Users /mnt/winshare
//将windows的网络共享文件 挂载到 linux,取代以前的smbmount(fedora5废除)










----------------------系统管理----------------------------------------------





---用户管理
文件
1./etc/passwd //所有用户帐号数据,查看所用用户;或system-config-users
2./etc/shadow //加密的用户密码
3./etc/group //组帐号文件
4./etc/gshadow //组帐号口令
5./etc/login.defs //通过该文件可更改创建用户时的一些设置;如CREATE_HOME no,则创建用户时不会创建/home/user

----
'login.defs文件CREATE_HOME yes',

1.useradd -M ccc //-M:不会创建主目录,即使login.defs文件指定要建立主目录

2.usermod -d /tmp/ccc/ ccc //-d:更改主目录。

3.cat /etc/passwd | grep ccc //ccc:x:513:514::/tmp/ccc:/bin/sh

4.cd //切换到ccc主目录/tmp/ccc。(/tmp/ccc/必须提前创建)

6./etc/default/useradd //定以 useradd命令 的文件

命令
0.system-config-users //打开图形化用户管理器:User Manager
1.useradd dalong1 //create a new username
2.passwd dalong1 //add passwd to username——dalong
3.userdel -r dalong1 //删除用户$HOME目录即邮件

4.usermod -g <主组名> -G <组名> -d <用户主目录> -s <用户shell> dalong1

usermod -g ccc -G aaa,bbb -d /tmp/ccc -s /sbin/nologin ccc //用户ccc必须先创建;

[root@localhost etc]# cat /etc/passwd|egrep "ccc|aaa"
aaa:x:502:502::/home/aaa:/bin/bash
ccc:x:510:514::/tmp/ccc:/sbin/nologin //此处显示/tmp/ccc,但在/tmp中并没有,仍然/home/ccc中


5.groupadd <组名> //创建组名
6.groupdel <组名> //delete group
7.直接修改文件来将一个用户加入到一个组:/etc/group.

8.chage -l root //查看 or 修改 密码的过期时间


11.chfn //改变用户信息;可在/etc/passwd中查看
12.finger jacky //显示jacky用户的详细信息
13.finger //显示所有登录系统的用户的信息

14.exit //退回到su之前的用户

-----改变文件拥有者
15.chown dalong:ntp command.txt //用ls -l查看文件所有者信息
16.chown dalong command.txt //此时等价dalong:jacky
17.chown
'-R' dalong:ntp * //递归更改当前目录及子目录所有文件owner

-----改变文件访问权限
18.chmod ugo+rw a.txt b.txt //所有人皆可读a.txt;b.txt
chmod a+rw a.txt b.txt //同上
chmod a=rw a.txt b.txt

19.chmod u+rw,o-rwx a.txt //a.txt所有者可读写,其他人没有任何权限
20.chmod -R a+r * //当前目录下所以文件及目录可被所有人读

21.chmod ug=rwx,o=x file <=> chmod 771 file

22.

-----进程管理

1.echo "我爱你" > /var/spool/mail/jacky
You have new mail in /var/spool/mail/jacky

2.at 17:30 today //在今天17:30调度启动程序。程序输出以邮件形式发到/var/spool/mail/jacky
//建议采用绝对时间24小时计时法。
32.at -l //即atq查看安排的作业序列

33.atrm 2 //删除制定的作业,即at -d

34.batch //和at唯一的区别:不能制定时间。在系统负载较低,资源较空闲时执行,适合与站资源较多的命令

35.-----cron命令:重复执行设定的命令
//已jacky登录
1.echo "33 17 * * * tar cvzf dalong.tar.gz /home/jacky" > ~/new/dalong.c
//dalong.c可包含多行命令,可手工编辑
2.crontab ~/new/dalong.c //安装dalong.c为新创建的/var/spool/cron/jacky文件
//即存放制定程序的文件名并不重要,如dalong.c;在crontab后都会变为......../cron/jacky文件
//当执行完成制定的命令后,有邮件通知/var/spool/mail/jacky

------------进程管理
1.ps -e | -h | -l //所有进程 | 不显示标题 | 详细信息
2.ps a | r | u | x //所有终端进程 | 当前终端正在running的 | 以user-oriented format | 不宜终端区分的所有进程
3.kill PID //终端后台进程,前台用Ctrl+c;
4.对于kill杀不掉的进程,发送信号9,强行关闭此进程。

6.ps -ef | grep named //*********************查看正在运行的相关进程*******************

7.kill -9 PID //*****************强制杀死进程***********************

5.top h|k|n|u|m|d //动态查看更新进程CDROM列表,并实时监控系统资源;
//显示help屏幕|杀死某进程|改变显示进程数量|显示指定user的进程|取消内存信息|改变刷新时间;


----------查看进程|服务占用的端口port

1.netstat -nltp |grep smb











-----------------------nslookup 查询DNS服务器ip及是否正确解析域名------------------


[root@localhost network-scripts]# nslookup
> www.baidu.com
Server: 192.168.0.2 //DNS ip
Address: 192.168.0.2#53

Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
Name: www.a.shifen.com
Address: 61.135.169.105
Name: www.a.shifen.com
Address: 61.135.169.125

--------------------关闭SELinux----------------------------
/etc/selinux/config中 将SELINUX=disabled ,然后重启



________________________________________________________________________________________________________________________________________

*****************************网络界面管理工具***************************************

------启动服务:

———————图形界面管理工具:system-config-services(fedora14 没有)

———————文本界面管理工具:ntsysv

———————命令行界面工具:

chkconfig named on|off

service named start|restart|down

pstree(进程树):pstree | grep httpd



----------------------------------------------------------------------------------------------------------------------


--------Linux启动时挂载Windows分区

前提:

1.虚拟机下可以使用双系统

2.Linux默认只识别 vfat 格式的Windows,不支持 NTFS 读写。需要第三方软件:kernel-ntfs-2.4.18-14.1686.rpm 来支持NTFS格式。

步骤:

1.在/etc/fstab设置:

/dev/hda1 /mnt/c vfat iocharset=cp936 0 0

/dev/hda4 /mnt/d vfat iocharset=cp936 0 0

2.重启LInux。



我在IBM工作,可以为大家内部推荐IBM各种职位 IBM全球职位尽在以下链接(请在浏览器中打开,QQ/微信 会阻止): http://ibmreferrals.com/ 很乐意为感兴趣的小伙伴分享:我的面试经验^_^ 如需咨询,请邮件发送以下邮箱,有问必回 1026096425@qq.com
原文地址:https://www.cnblogs.com/jackydalong/p/2408768.html