0. 一句话说完的常用指令
# 当前路径下递归查找以.txt结尾的文件夹
find . -name "*.txt"
# 当前路径下不递归查找以.txt结尾的文件夹,-maxdepth 1表示查找深度为1
find . -maxdepth 1 -name "*.txt"
1. ps 查看进程情况
ps -ef 显示所有进程信息,连同命令行
##ps -ef | grep python 查找进程名为python的进程
- UID :程序被该 UID 所拥有
- PID :就是这个程序的 ID
- PPID :则是其上级父程序的ID
- C :CPU使用的资源百分比
- STIME :系统启动时间
- TTY :登入者的终端机位置
- TIME :使用掉的CPU时间。
- CMD :所下达的是什么指令
UID PID PPID C STIME TTY TIME CMD
root 929 1 0 08:55 ? 00:00:03 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
doubles+ 13218 7780 0 14:09 pts/20 00:00:00 grep --color=auto python
2. kill 杀掉进程
kill -9 yourpid
kill 与 kill -9的区别
3. lsof查看某个端口(port)是否被占用
lsof -i
lsof -i:80 # 查看80端口被占用的情况
lsof输出各列信息
-
COMMAND:进程的名称
-
PID:进程标识符
-
PPID:父进程标识符(需要指定-R参数)
-
USER:进程所有者
-
PGID:进程所属组
-
FD:文件描述符,应用程序通过文件描述符识别该文件。如cwd、txt等
- cwd:表示current work dirctory,即:应用程序的当前工作目录,这是该应用程序启动的目录,除非它本身对这个目录进行更改
- txt :该类型的文件是程序代码,如应用程序二进制文件本身或共享库,如上列表中显示的 /sbin/init 程序
- lnn:library references (AIX);
- er:FD information error (see NAME column);
- jld:jail directory (FreeBSD);
- ltx:shared library text (code and data);
- mxx :hex memory-mapped type number xx.
- m86:DOS Merge mapped file;
- mem:memory-mapped file;
- mmap:memory-mapped device;
- pd:parent directory;
- rtd:root directory;
- tr:kernel trace file (OpenBSD);
- v86 VP/ix mapped file;
- 0:表示标准输出
- 1:表示标准输入
- 2:表示标准错误
一般在标准输出、标准错误、标准输入后还跟着文件状态模式:r、w、u等
- u:表示该文件被打开并处于读取/写入模式
- r:表示该文件被打开并处于只读模式
- w:表示该文件被打开并处于
- 空格:表示该文件的状态模式为unknow,且没有锁定
- -:表示该文件的状态模式为unknow,且被锁定
同时在文件状态模式后面,还跟着相关的锁
- N:for a Solaris NFS lock of unknown type;
- r:for read lock on part of the file;
- R:for a read lock on the entire file;
- w:for a write lock on part of the file;(文件的部分写锁)
- W:for a write lock on the entire file;(整个文件的写锁)
- u:for a read and write lock of any length;
- U:for a lock of unknown type;
- x:for an SCO OpenServer Xenix lock on part of the file;
- X:for an SCO OpenServer Xenix lock on the entire file;
- space:if there is no lock.
-
TYPE:文件类型,如DIR、REG等,常见的文件类型
- DIR:表示目录
- CHR:表示字符类型
- BLK:块设备类型
- UNIX: UNIX 域套接字
- FIFO:先进先出 (FIFO) 队列
- IPv4:网际协议 (IP) 套接字
-
DEVICE:指定磁盘的名称
-
SIZE:文件的大小
-
NODE:索引节点(文件在磁盘上的标识)
-
NAME:打开文件的确切名称
4. SCP跨服务器复制
两台机器IP分别为:A.104.238.161.75,B.43.224.34.73。
- ->本地
在A服务器上操作,将B服务器(43.224.33.73)上/home/lk/目录下所有的文件全部复制到本地的/root目录下
[root@XX ~]# scp -r root@43.224.34.73:/home/lk /root
root@43.224.34.73's password:
k2.sql 100% 0 0.0KB/s 00:00
k.zip 100% 176 0.2KB/s 00:00
.bash_history 100% 32 0.0KB/s 00:00
.bash_logout 100% 18 0.0KB/s 00:00
.bashrc 100% 231 0.2KB/s 00:00
k3.sql 100% 0 0.0KB/s 00:00
.bash_profile 100% 193 0.2KB/s 00:00
- 本地->
在A服务器上将/root/lk目录下所有的文件传输到B(43.224.33.73)的/home/lk/cpfile目录下
[root@XX lk]# scp -r /root/lk root@43.224.34.73:/home/lk/cpfile
root@43.224.34.73's password:
k2.sql 100% 0 0.0KB/s 00:00
k3.sql 100% 0 0.0KB/s 00:00
.bash_profile 100% 193 0.2KB/s 00:00
.bash_logout 100% 18 0.0KB/s 00:00
.bash_history 100% 32 0.0KB/s 00:00
k.zip 100% 176 0.2KB/s 00:00
.bashrc 100% 231 0.2KB/s 00:00
scp在夸机器复制的时候为了提高数据的安全性,使用了ssh连接和加密方式,如果机器之间配置了ssh免密码登录,那在使用scp的时候密码都不用输入。
4. 显示文件十六进制格式
# -n length 只格式化输入文件的前length个字节。
# -C 输出规范的十六进制和ASCII码。
hexdump -n 255 -C blk00000.dat