Linux

面试思路
• VMware
• Linux系统安装
• 文件目录操作
• 进程
• 网络配置
• 包管理/软件安装
• shell编程

Linux教程
Linux 教程 | 菜鸟教程 (runoob.com)
Linux学习教程,Linux入门教程(超详细) (biancheng.net)
VMWare虚拟机
vmware workstation16许可证密钥
ZF3R0-FHED2-M80TY-8QYGC-NPKYF
YF390-0HF8P-M81RQ-2DXQE-M2UT6
ZF71R-DMX85-08DQY-8YMNC-PPHV8
前面的如果已经失效,用下面的
FA1M0-89YE3-081TQ-AFNX9-NKUC0
处理器适配架构:
模拟器32位(即Mac处理器的指令集):i386
模拟器64位(即Mac处理器的指令集):x86_64
真机32位(即ARM处理器的指令集):armv7、armv7s
真机64位(即ARM处理器的指令集):arm64
centOS镜像下载地址:
http://mirrors.aliyun.com/centos/8.4.2105/isos/x86_64/
Linux连接工具;
MobaXterm
桥接跟NAT区别:
桥接网络是兄弟关系,跟宿主机相同网络,但是桥接电脑过多可能会出现IP冲突
nat是父子关系,是宿主机的子网络,效率没桥接高,但是不会出现冲突

用户管理
[root@localhost ~]# useradd dgb2
[root@localhost ~]# passwd s7865787
passwd:未知的用户名 s7865787。
[root@localhost ~]# passwd dgb2
更改用户 dgb2 的密码 。
新的 密码:
无效的密码: 密码未通过字典检查 - 太简单或太有规律
重新输入新的 密码:
抱歉,密码不匹配。
passwd: 鉴定令牌操作错误
[root@localhost ~]# passwd dgb2
更改用户 dgb2 的密码 。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# su dgb2
[dgb2@localhost root]$ cd ~
[dgb2@localhost ~]$ pwd
/home/dgb2文件目录操作
填空题
因为实在没办法出大题,所以出小题吧:
• 查看文件与目录
◦ 列出全部文件与目录;只列出目录;列出长串数据包括权限与属性
• 常用命令
◦ 查看历史执行过的命令;查看时间日期;设置系统时间;切换到root用户
◦ 获得一串路径中的文件名,获得一串路径中的目录名
◦ 当前目录、上一层目录、当前用户home目录,在Linux中用什么表示
◦ 显示当前目录;输出环境变量;修改环境变量(删除/添加)
◦ 单引号、双引号、反引号的区别
• 文件目录权限管理
◦ 查看权限,修改权限
◦ 权限在目录和文件中的意义有什么不同
• 创建、删除、复制、剪切、改名
◦ 删除某个文件;删除以ab开头的文件;递归强制删除目录下的所有目录以及文件;确认删除不要询问;
◦ find找到了多个文件或目录,此时要将它们全部删除
◦ 创建一个空文件;创建目录;创建多级目录
◦ 将文件复制到文件夹下;复制某个文件到文件夹下,并且更名;复制文件的时候将文件的所有特性都复制过去;复制一个空文件夹到另外的目录;递归复制一个非空目录到另外的目录;复制目录的时候强制覆盖不提示
◦ 将文件移动到某个目录中;将一个目录中的全部内容移动到另外的目录中;mv移动文件从目录a到目录a是什么效果;
• 查询文件/命令位置
◦ 查找某个可执行文件ifconfig;查找仅限path环境变量中可以找到的命令ifconfig;
◦ 在/etc目录下查找文件名包含abc的文件名;查找大于/小于/等于200M的文件
• 查看文件内容
◦ ps查看进程信息,加行号;翻页查看;查找文件中的某个字符串
◦ 查看文件前20行,查看文件后20行
◦ 持续检测文件输出
• 编辑文件
◦ vim有哪几种模式
◦ 一般模式下:寻找某个字符串、显示行号、删除一行、删除5行、复制一行、复制多行、粘贴、倒退/前进
• 重定向流:累加、覆盖
• 管道命令:|、grep、cut、xargs
• 压缩/解压
◦ 压缩类型与相应的压缩命令
◦ 压缩文件与压缩目录
基础操作
• 帮助指令:
1.man,例:man ls
2.help。例:help cd
• 获得文件名或目录名
basename /str
dirname /str

• 当前目录:.
• 上一层目录: …
• 当前用户主文件夹: ~
~zhangsan :代表 /home/zhangsan

• 显示当前目录:
pwd
• 环境变量PATH
打印环境变量:echo P A T H 拼接环境变量: P A T H = " PATH 拼接环境变量:PATH=" PATH拼接环境变量:PATH="PATH":/xxx/yyy

[root@localhost ~]# echo $PATH
/usr/local/java/jdk-11.0.15.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin• 单引号和双引号,反引号区别
区别:单引号属于强引用,它会忽略所有被引起来的字符的特殊处理,被引用起来的字符会被原封不动的使用;而双引号属于弱引用,它会对一些被引起来的字符进行特殊处理。简单来说,单引号直接输出内部字符串,不解析特殊字符;双引号内则会解析特殊字符。

反引号用来包含一个命令字符串的,其中的命令会先执行,得到的结果会返回到层命令再执行

MySQL的反引号是为了区分MySQL的保留字与普通字符而引入的符号,有MySQL保留字
例如:SELECT select FROM test WHERE select=’字段值’作为字段的,必须加上反引号来区分• 查看文件与目录
ls -a //列出全部文件与目录,包括隐藏的
ls -d // 仅列出目录。测试过,并没效果
ls -l // 列出长串数据,包括权限与属性等

[root@localhost ~]# ls -d *
公共 模板 视频 图片 文档 下载 音乐 桌面 aaa anaconda-ks.cfg a.txt data.txt dir1 dump.rdb initial-setup-ks.cfg insert_course.sh test.sh

[root@localhost ~]# ls
公共 模板 视频 图片 文档 下载 音乐 桌面 aaa anaconda-ks.cfg a.txt data.txt dir1 dump.rdb initial-setup-ks.cfg insert_course.sh test.sh

[root@localhost ~]# ls -l
总用量 28
drwxr-xr-x. 2 root root 6 8月 18 2022 公共
drwxr-xr-x. 2 root root 6 8月 18 2022 模板
drwxr-xr-x. 2 root root 6 8月 18 2022 视频
drwxr-xr-x. 2 root root 6 8月 18 2022 图片
drwxr-xr-x. 2 root root 6 8月 18 2022 文档
drwxr-xr-x. 2 root root 6 8月 18 2022 下载
drwxr-xr-x. 2 root root 6 8月 18 2022 音乐
drwxr-xr-x. 2 root root 6 8月 18 2022 桌面
drwxr-xr-x. 2 root root 6 11月 28 19:22 aaa
-rw-------. 1 root root 1106 6月 27 2022 anaconda-ks.cfg
-rw-r–r–. 1 root root 24 10月 21 02:32 a.txt
-rw-r–r–. 1 root root 40 9月 13 03:46 data.txt
drwxr-xr-x. 2 root root 6 2月 23 15:14 dir1
-rw-r–r–. 1 root root 140 8月 28 18:10 dump.rdb
-rw-r–r–. 1 root root 1398 6月 27 2022 initial-setup-ks.cfg
-rwxrwxrwx. 1 root root 323 9月 28 18:02 insert_course.sh
-rwxr-xr-x. 1 root root 37 9月 22 18:31 test.sh

[root@localhost ~]# ls -al
总用量 160
dr-xr-x—. 18 root root 4096 2月 23 15:14 .
dr-xr-xr-x. 17 root root 224 6月 27 2022 …
drwxr-xr-x. 2 root root 6 8月 18 2022 公共
drwxr-xr-x. 2 root root 6 8月 18 2022 模板
drwxr-xr-x. 2 root root 6 8月 18 2022 视频
drwxr-xr-x. 2 root root 6 8月 18 2022 图片
drwxr-xr-x. 2 root root 6 8月 18 2022 文档
drwxr-xr-x. 2 root root 6 8月 18 2022 下载
drwxr-xr-x. 2 root root 6 8月 18 2022 音乐
drwxr-xr-x. 2 root root 6 8月 18 2022 桌面
drwxr-xr-x. 2 root root 6 11月 28 19:22 aaa
-rw-------. 1 root root 1106 6月 27 2022 anaconda-ks.cfg
-rw-r–r–. 1 root root 24 10月 21 02:32 a.txt
-rw-------. 1 root root 19673 2月 15 14:04 .bash_history
-rw-r–r–. 1 root root 18 5月 11 2019 .bash_logout
-rw-r–r–. 1 root root 176 5月 11 2019 .bash_profile
-rw-r–r–. 1 root root 176 5月 11 2019 .bashrc
drwx------. 11 root root 251 8月 29 02:04 .cache
drwx------. 12 root root 229 8月 21 2022 .config
-rw-r–r–. 1 root root 12288 9月 14 02:40 .create_insert.sh.swm
-rw-r–r–. 1 root root 12288 9月 13 18:27 .create_insert.sh.swo
-rw-r–r–. 1 root root 12288 9月 13 11:50 .create_insert.sh.swp
-rw-r–r–. 1 root root 100 5月 11 2019 .cshrc
-rw-r–r–. 1 root root 40 9月 13 03:46 data.txt
drwx------. 3 root root 25 6月 27 2022 .dbus
drwxr-xr-x. 2 root root 6 2月 23 15:14 dir1
-rw-r–r–. 1 root root 140 8月 28 18:10 dump.rdb
-rw-------. 1 root root 16 8月 18 2022 .esd_auth
-rw-------. 1 root root 1558 1月 11 14:45 .ICEauthority
-rw-r–r–. 1 root root 1398 6月 27 2022 initial-setup-ks.cfg
-rwxrwxrwx. 1 root root 323 9月 28 18:02 insert_course.sh
-rw-------. 1 root root 34 8月 30 13:17 .lesshst
drwx------. 3 root root 19 8月 18 2022 .local
drwxr-xr-x. 5 root root 66 8月 29 02:04 .mozilla
-rw-------. 1 root root 148 2月 20 01:58 .mysql_history
drwxr-----. 3 root root 19 8月 18 2022 .pki
-rw-------. 1 root root 1166 8月 28 15:05 .rediscli_history
-rw-r–r–. 1 root root 129 5月 11 2019 .tcshrc
-rwxr-xr-x. 1 root root 37 9月 22 18:31 test.sh
-rw-r–r–. 1 root root 12288 9月 22 11:59 .test.sh.swp
-rw-------. 1 root root 16097 10月 21 12:44 .viminfo
-rw-------. 1 root root 134 2月 23 15:10 .Xauthority

• history:
查看执行过的历史命令
• su root
切换到root用户
• 时间日期:
cal:本月日历
cal 2021 :显示本年日历
date:当前日期,2021年 09月 19日 星期日 17:32:51 CST
date “+%Y-%m-%d” : 2021-09-19
date “+%H:%M:%S” : 17:37:27
date -s “年月日时分秒” ,设置系统时间
文件目录权限
查看文件权限:ls -al
dr-xr-x—. 4 root root 204 9月 17 08:44 .
dr-xr-xr-x. 17 root root 224 9月 17 04:47 …
-rw-------. 1 root root 1096 9月 17 04:55 anaconda-ks.cfg
drwx------. 4 root root 44 9月 17 04:58 .cache d:表示目录,若是-则代表文件
r-x:用户权限
r-x:用户组权限
—:其他组用户权限 改变文件权限:chmod 777 文件名
r :4,w :2,x: 1
4是100 2是10 1是1执行权限:
对文件来说,执行权限是可执行,对目录来说,执行权限是进入目录
读权限:
对文件来说是能看到文件里面的内容,对目录来说是能看到目录下的文件
写权限:
对目录来说是能在目录中添加文件等这样的修改目录结构操作,对文件来说是修改文件内容删除文件
删除目录
rmdir 目录名 (只能删除空目录)
rm -rf 目录名 (可以递归强制删除非空目录)

xargs:可以将前一个查询结果foreach给后面
find /root -name “c*” | xargs rmdir 删除
删除文件
rm xxx // 删除xxx文件
删除xx开头的文件
rm xx*
删除目录
rm -r /tmp/etc
确认删除,不要询问
\rm -r /tmp/etc创建文件
touch:创建一个空文件,touch a.txt

创建一个以-开头的文件,并删除
touch ./-a
rm ./-a

创建一个新的目录
mkdir hello
mkdir -p /home/xx/yy (创建多级目录需要加参数p)复制文件
将yyy复制到tmp文件夹下,并更名为zzz
cp /xxx/yyy /tmp/zzz
复制x到当前目录
cp /var/x .
可以将文件的所有特性全部复制过来
cp -a复制目录
将etc目录下所有内容复制到tmp下 :
cp -r /etc/ /tmp
强制覆盖,不提示?y (cp前加一个 \)
\cp -r /etc/ /tmp移动文件、目录或更名
将文件移动到目录中:mv 文件 目录
将目录1更名为目录2:mv 目录1 目录2 (两个文件在同一个目录就是重命名)
查询文件位置
• 查找可执行文件
[root@localhost ~]# which ifconfig
/usr/sbin/ifconfig• 列出path路径中可以找到的命令
[root@localhost ~]# whereis ifconfig
ifconfig: /usr/sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz

[root@localhost ~]# which a.txt
/usr/bin/which: no a.txt in (/usr/local/java/jdk-11.0.15.1//bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@localhost ~]# whereis a.txt
a:
• 列出所有与abc相关的文件名,abc只是文件部分名称
locate abc (执行之前执行一遍 updatedb)
find / -name abc
find /etc -name ‘abc
find / -size +200M (查找大于200M的文件,-200是小于,200是等于)

[root@localhost ~]# locate nabcc
/etc/brltty/Contraction/nabcc.cti
/etc/brltty/Text/en-nabcc.ttb
/usr/share/liblouis/tables/text_nabcc.dis

[root@localhost ~]# find ~ -name aaa
/root/aaa
[root@localhost ~]# find ~ -name ‘aa’ //不带通配符的话就是完全匹配
[root@localhost ~]# find ~ -name ‘aa*’
/root/aaa
[root@localhost ~]# find ~ -name ‘a
/root/data.txt
/root/aaa,aaa是目录
/root/a.txt
而且不止是一级目录,下层的二级三级也会被查到

查询文件内容
cat 文件名
-n 加行号
ps H -eo pid,tid,%cpu,%mem | cat -n
#翻页查看:
more 文件名。按enter键向下滚动一行,空格向下滚动一页,且只能向下
less 文件名
查找:/字符串。重复前一个查询:n,反向重复前一个查询:N
pageUp:向上翻页。pageDown:向下翻页
离开:q #head、tail显示文件前20行
head -n 20 文件
head -n -100 文件 //后100行不打印
tail -n 20 文件
tail -n +100 文件 // 前100行不打印
tail -f 文件 // 持续检测文件输出内容,ctrl + c离开vim
进入一般模式
vi test.txt
按i进入编辑模式
按Esc回到一般模式

离开vi
在一般模式下 :wq 保存后离开vi
:q! 强制离开不保存
一般模式下的操作
/str //向下寻找一个名称为str的字符串
?str // 向上寻找,n重复前一个动作,N反向重复
显示行号: :set number
dd //删除所在的一行
5dd //删除5行

  yy  //复制光标所在一行
  6yy // 复制6行,p向下粘贴,P向上粘贴

  u  // 倒退;复原前一个操作
 ctrl + r // 前进,重做一次多文件编辑
  vim  a b //打开两个文件
  :n    // 编辑下一个文件*      :N   //编辑上一个文件
  :files //列出所有打开的文件多窗口
  vim a
  :sp b
  ctrl + w + ↑  //移动光标
  ctrl + w + ↓重定向流

ll / > ~/a.txt #覆盖
ll / >> ~/a.txt #累加管道命令
echo $PATH | cut -d ‘:’ -f 3,5 //根据 :隔开 取出第3和第5列

cat a.txt | grep ‘abc’
cat a.txt | grep -n ‘abc’ (-n 显示行号)
cat a.txt | grep -v ‘abc’[root@localhost ~]# grep ‘abc’ a.txt
abc+345
[root@localhost ~]# cat a.txt
aaa+999
abc+345
xyz+123
压缩
gzip
压缩:gzip b.txt (只能压缩文件,不能目录)

 解压:gunzip b.txt.gz

zip
zip -r myhello.zip /root/hello
将/root/hello这个目录压缩成myhello.zip
unzip -d /root/hello/a myhello.zip
-d后面指定解压后的目录 tar
tar -zcvf xx.tar.gz a b.txt (将a文件夹和b.txt一起压缩成xx.tar.gz)
tar -zxvf xx.tar.gz (解压到当前目录)
tar -xvf xx.tar (解压到当前目录)
tar -zxvf xx.tar.gz -C /…/目录 (解压到指定目录)进程服务
• Windows任务管理器的使用
• 查看进程信息(CPU、内存、父进程、状态、command);进程有哪些状态
• 查看进程下有哪些线程
ps
命令执行会产生进程,例如cd、ll 转瞬即逝。常驻内存的进程就是服务,需要对外通信的会配一个端口
每个进程可能以两种方式存在:前台进程和后台进程
一般系统服务都是以后台进程存在,常驻系统,关机才结束

• 查看系统进程
user:进程是哪个用户产生的
PID:进程id号
%cpu:占用CPU百分比
%mem:占用内存百分比
VSZ:占用虚拟内存大小
RSS:占用实际内存大小
TTY:由哪个终端产生,从1~6,7是图形终端,pst是虚拟终端。?代表由系统内核产生, 不由任何终端
stat:进程状态,R运行,S睡眠,T停止,s包含子进程,+位于后台,<高优先级,I是Idle kernel thread,N是 low-priority (nice to other users)
start:启动时间
Time:占用CPU的运算时间
command:例如ps aux这种命令ps aux | more :a(显示当前终端所有进程信息),u(以用户的格式显示进程信息),x(显示后台进程运行的参数)ps -elf :e(显示所有进程),f(全格式,可以看到父进程id),l(Long format) -H Show process hierarchy (forest)
H Show threads as if they were processes
//注意这里
To see every process on the system using BSD syntax:
ps ax
ps axu

To print a process tree:
ps -ejH
ps axjf
//注意这里
To get info about threads:
ps -eLf
ps axms

To get security info:
ps -eo euser,ruser,suser,fuser,f,comm,label
ps axZ
ps -eM

To see every process running as root (real & effective ID) in user format:
ps -U root -u root u

To see every process with a user-defined format:
ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
ps -Ao pid,tt,user,fname,tmout,f,wchan

Print only the process IDs of syslogd:
ps -C syslogd -o pid=

Print only the name of PID 42:
ps -q 42 -o comm=

ps jax --sort=uid,-ppid,+pidSIMPLE PROCESS SELECTION
a Lift the BSD-style “only yourself” restriction, which is imposed upon the set of all processes when some BSD-style (without “-”) options are used or when the ps personality setting is BSD-like.
The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes when used together with the x option.
-A Select all processes. Identical to -e.
-a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.
-d Select all processes except session leaders.
–deselect
Select all processes except those that fulfill the specified conditions (negates the selection). Identical to -N.
-e Select all processes. Identical to -A.
g Really all, even session leaders. This flag is obsolete and may be discontinued in a future release. It is normally implied by the a flag,
and is only useful when operating in the sunos4 personality.
-N Select all processes except those that fulfill the specified conditions (negates the selection). Identical to --deselect.
T Select all processes associated with this terminal. Identical to the t option without any argument.
r Restrict the selection to only running processes.
x Lift the BSD-style “must have a tty” restriction, which is imposed upon the set of all processes when some BSD-style (without “-”) options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.
PROCESS SELECTION BY LIST
These options accept a single argument in the form of a blank-separated or comma-separated list. They can be used multiple times. For example:
ps -p “1 2” -p 3,4
-123 Identical to --pid 123.
123 Identical to --pid 123.
-C cmdlist
Select by command name. This selects the processes whose executable name is given in cmdlist.
-G grplist
Select by real group ID (RGID) or name. This selects the processes whose real group name or ID is in the grplist list. The real group ID
identifies the group of the user who created the process, see getgid(2).
-g grplist
Select by session OR by effective group name. Selection by session is specified by many standards, but selection by effective group is the
logical behavior that several other operating systems use. This ps will select by session when the list is completely numeric (as sessions
are). Group ID numbers will work only when some group names are also specified. See the -s and --group options.
–Group grplist
Select by real group ID (RGID) or name. Identical to -G.
–group grplist
Select by effective group ID (EGID) or name. This selects the processes whose effective group name or ID is in grplist. The effective
group ID describes the group whose file access permissions are used by the process (see getegid(2)). The -g option is often an alternative
to --group.
p pidlist
Select by process ID. Identical to -p and --pid.
-p pidlist
Select by PID. This selects the processes whose process ID numbers appear in pidlist. Identical to p and --pid.
–pid pidlist
Select by process ID. Identical to -p and p.
–ppid pidlist
Select by parent process ID. This selects the processes with a parent process ID in pidlist. That is, it selects processes that are
children of those listed in pidlist.
q pidlist
Select by process ID (quick mode). Identical to -q and --quick-pid.
-q pidlist
Select by PID (quick mode). This selects the processes whose process ID numbers appear in pidlist. With this option ps reads the necessary
info only for the pids listed in the pidlist and doesn’t apply additional filtering rules. The order of pids is unsorted and preserved. No
additional selection options, sorting and forest type listings are allowed in this mode. Identical to q and --quick-pid.
–quick-pid pidlist
Select by process ID (quick mode). Identical to -q and q.
-s sesslist
Select by session ID. This selects the processes with a session ID specified in sesslist.
–sid sesslist
Select by session ID. Identical to -s.
t ttylist
Select by tty. Nearly identical to -t and --tty, but can also be used with an empty ttylist to indicate the terminal associated with ps.
Using the T option is considered cleaner than using t with an empty ttylist.
-t ttylist
Select by tty. This selects the processes associated with the terminals given in ttylist. Terminals (ttys, or screens for text output) can
be specified in several forms: /dev/ttyS1, ttyS1, S1. A plain “-” may be used to select processes not attached to any terminal.
–tty ttylist
Select by terminal. Identical to -t and t.
U userlist
Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist. The effective user
ID describes the user whose file access permissions are used by the process (see geteuid(2)). Identical to -u and --user.
-U userlist
Select by real user ID (RUID) or name. It selects the processes whose real user name or ID is in the userlist list. The real user ID
identifies the user who created the process, see getuid(2).
-u userlist
Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist.
The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)). Identical to U and --user.
–User userlist
Select by real user ID (RUID) or name. Identical to -U.
–user userlist
Select by effective user ID (EUID) or name. Identical to -u and U.OUTPUT FORMAT CONTROL
These options are used to choose the information displayed by ps. The output may differ by personality.
-c Show different scheduler information for the -l option.
–context
Display security context format (for SELinux).
-f Do full-format listing. This option can be combined with many other UNIX-style options to add additional columns. It also causes the
command arguments to be printed. When used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be added. See the c
option, the format keyword args, and the format keyword comm.
-F Extra full format. See the -f option, which -F implies.
–format format
user-defined format. Identical to -o and o.
j BSD job control format.
-j Jobs format.
l Display BSD long format.
-l Long format. The -y option is often useful with this.
-M Add a column of security data. Identical to Z (for SELinux).
O format
is preloaded o (overloaded). The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be
used to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the desired behavior is obtained
(sorting or formatting), specify the option in some other way (e.g. with -O or --sort). When used as a formatting option, it is identical
to -O, with the BSD personality.
-O format
Like -o, but preloaded with some default columns. Identical to -o pid,format,state,tname,time,command or -o pid,format,tname,time,cmd, see
-o below.
o format
Specify user-defined format. Identical to -o and --format.
-o format
User-defined format. format is a single argument in the form of a blank-separated or comma-separated list, which offers a way to specify
individual output columns. The recognized keywords are described in the STANDARD FORMAT SPECIFIERS section below. Headers may be renamed
(ps -o pid,ruser=RealUser -o comm=Command) as desired. If all column headers are empty (ps -o pid= -o comm=) then the header line will not
be output. Column width will increase as needed for wide headers; this may be used to widen up columns such as WCHAN (ps -o pid,wchan=WIDE-
WCHAN-COLUMN -o comm). Explicit width control (ps opid,wchan:42,cmd) is offered too. The behavior of ps -o pid=X,comm=Y varies with
personality; output may be one column named “X,comm=Y” or two columns named “X” and “Y”. Use multiple -o options when in doubt. Use the
PS_FORMAT environment variable to specify a default as desired; DefSysV and DefBSD are macros that may be used to choose the default UNIX or
BSD columns.
s Display signal format.
u Display user-oriented format.
v Display virtual memory format.
X Register format.
-y Do not show flags; show rss in place of addr. This option can only be used with -l.
Z Add a column of security data. Identical to -M (for SELinux).OUTPUT MODIFIERS
c Show the true command name. This is derived from the name of the executable file, rather than from the argv value. Command arguments and
any modifications to them are thus not shown. This option effectively turns the args format keyword into the comm format keyword; it is
useful with the -f format option and with the various BSD-style format options, which all normally display the command arguments. See the
-f option, the format keyword args, and the format keyword comm.
–cols n
Set screen width.
–columns n
Set screen width.
–cumulative
Include some dead child process data (as a sum with the parent).
e Show the environment after the command.
f ASCII art process hierarchy (forest).
–forest
ASCII art process tree.
h No header. (or, one header per screen in the BSD personality). The h option is problematic. Standard BSD ps uses this option to print a
header on each page of output, but older Linux ps uses this option to totally disable the header. This version of ps follows the Linux
usage of not printing the header unless the BSD personality has been selected, in which case it prints a header on each page of output.
Regardless of the current personality, you can use the long options --headers and --no-headers to enable printing headers each page or
disable headers entirely, respectively.
-H Show process hierarchy (forest).
–headers
Repeat header lines, one per page of output.
k spec Specify sorting order. Sorting syntax is [+|-]key[,[+|-]key[,…]]. Choose a multi-letter key from the STANDARD FORMAT SPECIFIERS section.
The “+” is optional since default direction is increasing numerical or lexicographic order. Identical to --sort.
Examples:
ps jaxkuid,-ppid,+pid
ps axk comm o comm,args
ps kstart_time -ef
–lines n
Set screen height.
n Numeric output for WCHAN and USER (including all types of UID and GID).
–no-headers
Print no header line at all. --no-heading is an alias for this option.
O order
Sorting order (overloaded). The BSD O option can act like -O (user-defined output format with some common fields predefined) or can be used
to specify sort order. Heuristics are used to determine the behavior of this option. To ensure that the desired behavior is obtained
(sorting or formatting), specify the option in some other way (e.g. with -O or --sort).
For sorting, obsol

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值