【centos】centos命令总结(持续更新)

时间:2023-03-09 16:16:57
【centos】centos命令总结(持续更新)

1、查看系统版本命令

转自:https://blog.csdn.net/networken/article/details/79771212

.查看内核版本
[root@localhost ~]# uname -sr
Linux 4.15.-.el7.elrepo.x86_64
[root@localhost ~]# uname -a
Linux localhost.localdomain 4.15.-.el7.elrepo.x86_64 # SMP Mon Mar :: EDT x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /proc/version
Linux version 4.15.-.el7.elrepo.x86_64 (mockbuild@Build64R7) (gcc version 4.8. (Red Hat 4.8.-) (GCC)) # SMP Mon Mar :: EDT .查看发行版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.4. (Core)
[root@localhost ~]# yum install -y redhat-lsb
[root@localhost
~]#  lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: CentOS
Description:    CentOS Linux release 7.4. (Core)
Release:        7.4.
Codename:       Core

 

2、更改文件/文件夹的拥有者(chown)以及所属组(chgrp)

转自:https://blog.csdn.net/hudashi/article/details/7797393

(1)chown来更改文件所属用户(也可以更改文件所属组)的用法

基本语法:
chown [-R] 用户名称 文件或目录
chown [-
R] 用户名称:用户组名称 文件或目录
参数:
-R : 进行递归( recursive )的持续更改,即连同子目录下的所有文件、目录
都更新成为这个用户组。常常用在更改某一目录的情况。
示例1:
[root@localhost home]# touch testfile //由 root 用户创建文件
[root@localhost home]# ls testfile –l
-rw--w--w- root root Jun : testfile //文件的拥有者及拥有者组均为 root
[root@localhost home]# chown xuelisheng testfile //修改文件拥有者为 xuelisheng
[root@localhost home]# ls testfile -l
-rw--w--w- xuelisheng root Jun : testfile //查看文件拥有者为 xuelisheng,但组仍为 root
示例2:
chown bin install.log
ls -l
-rw-r--r-- bin users Jun : install.log
chown root:root install.log // 更改了文件所属用户以及所属组
ls -l
-rw-r--r-- root root Jun : install.log

(2)chgrp来更改文件所属组的用法

需要注意的是要改变成为的用户组名称,必须在 /etc/group里存在,否则就会显示错误。
基本语法:
chgrp [-R] 用户组名称 dirname/filename ...

参数:
-R : 进行递归( recursive )的持续更改,即连同子目录下的所有文件、目录
都更新成为这个用户组。常常用在更改某一目录的情况。
示例3
[root@localhost home]# ls testfile -l
-rw--w--w- xuelisheng root Jun : testfile //查看文件拥有者为 xuelisheng,组为 root
[root@localhost home]# chgrp xuelisheng testfile //修改拥有者组为 xuelisheng
[root@localhost home]# ls testfile -l
-rw--w--w- xuelisheng xuelisheng Jun : testfile
[root@localhost home]# chown root:root testfile // 使用 chown 一次性修改拥有者及组
[root@localhost home]# ls testfile -l
-rw--w--w- root root Jun : testfile
示例4
[root@linux ~]# chgrp users install.log
[root@linux ~]# ls -l
-rw-r--r-- root users Jun : install.log
示例5
更改为一个 /etc/group里不存在的用户组
[root@linux ~]# chgrp testing install.log
chgrp: invalid group name `testing' <== 出现错误信息~找不到这个用户组名~

3、ps 命令

ps命令

  • 要对进程进行监测和控制,首先必须要了解当前进程的情况,也就是需要查看当前进程, 而ps命令(Process Status)就是最基本同时也是非常强大的进程查看命令。

  • 使用该命令可以确定有哪些进程正在运行和运行的状态、进程是否结束、进程有没有僵尸、哪些进程占用了过多的资源等等,总之大部分信息都可以通过执行该命令得到的。

ps与grep结合

  • 如果直接用ps命令,会显示所有进程的状态,通常结合grep命令查看某进程的状态。

  • grep (global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

【centos】centos命令总结(持续更新)

USER   PID %CPU %MEM VSZ RSS TTY   STAT START TIME  COMMAND

具体的解释:

USER:   进程拥有者
PID:      pid
%CPU:   占用的 CPU 使用率
%MEM:    进程使用的可用物理内存百分比
VSZ:    表示进程分配的虚拟内存
RSS:        该进程分配的内存大小
TTY:        终端的次要装置号码 (minor device number of tty)
STAT:      该进程的状态,linux的进程有5种状态:
D 不可中断 uninterruptible sleep (usually IO)
R 运行 runnable (on run queue)
S 中断 sleeping
T 停止 traced or stopped
Z 僵死 a defunct (”zombie”) process
注: 其它状态还包括W(无驻留页), <(高优先级进程), N(低优先级进程), L(内存锁页).
START:     进程开始时间
TIME:       执行的时间
COMMAND:  所执行的指令