which 只能查询命令

#which rpm

whereis 

#whereis rpm

whatis

#whatis rpm 和下面命令一样的效果,查询rpm命令都在哪章man有解释

#man -f rpm

locate

维护着一个查询数据库

#vim /etc/updatedb.conf

1)文件系统类型

2)目录

如果被更改之后,需要更新数据库

#updatedb 手动更新数据库

#locate 被查找的关键字

#locate *.txt

*是通配符 

 

find

#find 路径 条件 跟条件相关的操作符 [-exec|-ok 动作]

路径

默认不写路径时查找的是当前路径

条件

 

-name 文件名称      按名称查找

# find / -name a.txt

# find / -name a.t??

# find / -name a.tx?

# find / -name '*a.txt'

 

?表示单个字符

*表示所有字符

[abc]

[a-z]

[a-Z]

[a-zA-Z]

[!a-z]

 

一般情况下{}不能用

{1..100}

{abc,abd,efg}

 

按大小查找

-size

#find  / -size 50M

#find  / -size +50M

#find  / -size -50M

查找大于10M小于20M

#find / -size +10M -a -size -20M  

-a可以换成-and

#find / -size -10M -o -size +20M  

-o可以换成-or

# find ./  ! -size -10M

 

附加:dd命令做测试数据

#dd if=/dev/zero of=/tmp/aa.txt bs=5M count=2

 

按文件类型查找

-type

f

d

b

c

l

s

p

# find / -type c -exec ls -l {} \;

 

# find /tmp/ -name aa.txt -exec rm -i {} \;

# find /tmp/ -name aa.txt -ok rm  {} \;

< rm ... /tmp/aa.txt > ? y

 

-exec 对之前查找出来的文件做进一步操作

-ok   -exec一样,只不过多了提示

 

按权限查找:

-perm 

# find ./  -perm 644

./dd.txt

 

按用户和组查找

-user

-group

# find ./ -user wing

./bb.txt

# find ./  -group user3

./cc.txt

 

按时间

-atime  access时间

-mtime  modify时间

-ctime  change时间

 

-amin

-mmin

-cmin

 

查找两分钟内访问过的文件

# find /tmp -amin -2

/tmp/a.txt

 

查找两分钟前访问过的文件

# find /tmp -amin +2

 

#stat a.txt

 

 

练习:

测试-type 的其他类型

测试能对一个文件所做的所有你会的操作都修改了哪些时间

 

进程控制

查看进程

#ps 

#ps auxf

只能查看所有终端进程

显示进程拥有者

显示系统内所有进程

显示进程之间的父子关系

 

USER 进程拥有者

PID  process identify

TTY  进程在哪个终端运行

 查看tty的方法:

 #tty

 ? 表示这个进程开启的时候没有占用终端

 

TIME 进程占用cpu的总时间

CMD  进程名称

%CPU 进程占用的cpu百分比

%MEM 进程占用memory百分比

VSZ  进程占用的虚拟内存大小

RSS  占用的物理内存大小

STAT 当前进程状态

 R running

 S sleep

 T stop  

 Z zombie(僵死,僵尸)

 #man ps

D    Uninterruptible sleep (usually IO)

R    Running or runnable (on run queue)

S    Interruptible sleep (waiting for an event to complete)

T    Stopped, either by a job control signal or because it is being traced.

W    paging (not valid since the 2.6.xx kernel)

X    dead (should never be seen)

Z    Defunct ("zombie") process, terminated but not reaped by its parent.

<    high-priority (not nice to other users)

N    low-priority (nice to other users)

L    has pages locked into memory (for real-time and custom IO)

s    is a session leader

l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

+    is in the foreground process group

 

 

#ps -elf

-e显示所有进程

-l长格式显示

-f完整格式

#ps -e 常用

 

pstree

查看进程树

#pstree

-a 显示参数

-p 显示pid

-u 显示用户名

 

lsof(应用范围有限,只能查看带端口的进程)

lsof -i:80

查看端口为80的进程

 

pidof

#pidof 进程名称

 

# pgrep -l eyes

1179 xeyes

 

top 

实时的查看进程的状态

往下翻页

往上翻页

按内存排序

cpu排序

输入pid杀死进程

打印帮助

退出

 

杀死进程

pid杀死进程

#kill 信号(signal) pid

-1   HUP  重新加载进程或者重新加载配置文件

-9   KILL 强制杀死

-15  TERM 正常杀死(这个信号可以默认不写)

-18  CONT 激活进程

-19  STOP 挂起进程

#kill -HUP  pid

#kill -STOP pid

 

#kill -l

#man 7 signal 所有信号的解释

 

#killall 信号 进程名称

 

#pkill -9 进程名称

#pkill -t 终端  

不加-9只杀死在终端上运行的进程,加-9连终端本身一起干掉

#pkill -u 用户名称

#xkill

 

前后台操作

ctrl+z  把程序放到后台(这方法会让程序在后台暂停)

#fg %1  把程序调到前台,%是用来修饰job number1就是job number

#jobs   查看工作号

#bg %1  让暂停的程序在后台运行

#kill -9 %1

#kill -9 pid

进程优先级

优先级本身是不能修改,通过nice值修改优先级。

普通账户只能调高nice值,不能往低调

root账户随便调

nice值越高,优先级越低。

nice值范围:-2019

 

查看进程优先级

#top

#ps -elf

PR:priority

NI:nice

指定进程优先级

#nice --15 firefox &   

修改进程优先级

# renice 10 7116   nice值前面不能加-