您的位置:首页 > 运维架构 > Linux

40个系统管理员中级命令详解(linux)

2016-10-14 13:59 204 查看

1. id命令=查看账号的id号:选项-u为用户id、-g为组id、-G为所有组

# id tecmint_test
uid=501(tecmint_test) gid=502(tecmint_test) groups=502(tecmint_test)
2. which 在PATH变量指定的路径中搜索某个系统命令的位置并且返回第一个搜索结果

# which pwd
/bin/pwd

3. chage命令:-l列出过去信息、-d最后口令改变日期、-e设置账号终止日期

# chage -l tecmint
Last password change					: Nov 02, 2014
Password expires					: never
Password inactive					: never
Account expires						:
Minimum number of days between password change		: 0
Maximum number of days between password change		: 99999
Number of days of warning before password expires	: 7

4. man命令:显示系统手册信息,重要命令。以下为显示id命令信息

# man id



5. info命令:显示更完整的最新的GNU工具信息

# ibfo  id



6.chkconfig 命令列出所有服务以及/etc/rd.d/init中的服务的开始和结束

[root@tecmint ~]# chkconfig --list
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
...

列出指定指定服务的状态,例子为:HTTP服务在所有运行模式下的状态为:off
[root@tecmint ~]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
在运行模式3和5下,开启HTTP服务。 level为运行模式或级别
[root@tecmint ~]# chkconfig --level 35 httpd on
显示结果
[root@tecmint ~]# chkconfig --list | grep httpd
httpd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
查看服务开和关,以下为在运行模式5为开的服务
[root@tecmint ~]# chkconfig --list | grep 5:on
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
abrt-ccpp       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrt-oops       0:off   1:off   2:off   3:on    4:off   5:on    6:off
abrtd           0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid           0:off   1:off   2:on    3:on    4:on    5:on    6:off
...
以下列出运行模式5为关的服务
[root@tecmint ~]# chkconfig --list | grep 5:off
dnsmasq         0:off   1:off   2:off   3:off   4:off   5:off   6:off
dovecot         0:off   1:off   2:off   3:off   4:off   5:off   6:off
firstboot       0:off   1:off   2:off   3:off   4:off   5:off   6:off
kdump           0:off   1:off   2:off   3:off   4:off   5:off   6:off
mysqld          0:off   1:off   2:off   3:off   4:off   5:off   6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
nfs             0:off   1:off   2:off   3:off   4:off   5:off   6:off
...
停止特定的服务,
[root@tecmint ~]# chkconfig --level 3 postfix off

[root@tecmint ~]# chkconfig --level 2345 postfix off

7.touch命令:创建和修改文件时间戳。当新文件时,直接创建新文件

-a, 仅改变访问时间

-c, 如果文件不存在,创建它

-d, 升级访问和修改时间

-m, 仅改变修改时间

-r, 使用文件的访问和修改时间

-t, 使用一个特定时间创建文件

创建一个空文件
# touch sheena
创建多个空文件
# touch sheena meena leena
改变文件访问和修改时间
# touch -a leena
注意:用-c避免创建新文件
# touch -c leena
改变文件修改时间
# touch -m leena
设置访问修改的终止时间
# touch -c -t YYDDHHMM leena
# touch -c -t 16101730 leena
# ls -l
total 2
-rw-r--r--.  1 root    root   0 Dec 10 17:30 leena
使用另一个文件的时间戳
# touch -r leena meena
创建一个特定时间文件
# touch -t YYMMDDHHMM.SS tecmint
# touch -t 201212101830.55 tecmint


8. lsblk命令:linux块设备信息

tecmint@tecmint ~ $
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0 931.5G  0 disk
├─sda1    8:1    0  1000M  0 part
├─sda2    8:2    0   260M  0 part /boot/efi
├─sda3    8:3    0  1000M  0 part
├─sda4    8:4    0   128M  0 part
├─sda5    8:5    0 557.1G  0 part
├─sda6    8:6    0    25G  0 part
├─sda7    8:7    0  14.7G  0 part
├─sda8    8:8    0     1M  0 part
├─sda9    8:9    0 324.5G  0 part /
└─sda10   8:10   0   7.9G  0 part [SWAP]
sr0      11:0    1  1024M  0 rom
-a选项看所有的块设备
9. lscpu显示cpu信息,在 sysfs 和proc/cpuinfo.中
tecmint@tecmint ~ $
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    2
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 69
Stepping:              1
CPU MHz:               768.000
BogoMIPS:              4788.72
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K
NUMA node0 CPU(s):     0-3

10. lsusb命令显示USB 控制信息

tecmint@tecmint ~ $
Bus 001 Device 002: ID 8087:8000 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 005: ID 0bda:b728 Realtek Semiconductor Corp.
Bus 002 Device 004: ID 5986:0249 Acer, Inc
Bus 002 Device 003: ID 0bda:0129 Realtek Semiconductor Corp. RTS5129 Card Reader Controller
Bus 002 Device 002: ID 045e:00cb Microsoft Corp. Basic Optical Mouse v2.0
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

11.lspci 命令显示PCI 设备信息

tecmint@tecmint ~ $
00:00.0 Host bridge: Intel Corporation Haswell-ULT DRAM Controller (rev 0b)
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
00:03.0 Audio device: Intel Corporation Haswell-ULT HD Audio Controller (rev 0b)
00:14.0 USB controller: Intel Corporation Lynx Point-LP USB xHCI HC (rev 04)
00:16.0 Communication controller: Intel Corporation Lynx Point-LP HECI #0 (rev 04)
00:1b.0 Audio device: Intel Corporation Lynx Point-LP HD Audio Controller (rev 04)
00:1c.0 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 3 (rev e4)
00:1c.3 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 4 (rev e4)
00:1c.4 PCI bridge: Intel Corporation Lynx Point-LP PCI Express Root Port 5 (rev e4)
00:1d.0 USB controller: Intel Corporation Lynx Point-LP USB EHCI #1 (rev 04)
00:1f.0 ISA bridge: Intel Corporation Lynx Point-LP LPC Controller (rev 04)
00:1f.2 SATA controller: Intel Corporation Lynx Point-LP SATA Controller 1 [AHCI mode] (rev 04)
00:1f.3 SMBus: Intel Corporation Lynx Point-LP SMBus Controller (rev 04)
01:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 10)
02:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723BE PCIe Wireless Network Adapter
03:00.0 3D controller: NVIDIA Corporation GM108M [GeForce 840M] (rev a2)
-t 选项以树形方式输出, -v 选项每个链接设备的详细信息

12. lsscsi 显示 SCSI 设备信息

首先需要安装设备
$ sudo apt-get install lsscsi        [on Debian derivatives]
# yum install lsscsi                 [On RedHat based systems]
# dnf install lsscsi                 [On Fedora 21+ Onwards]

tecmint@tecmint ~ $
[0:0:0:0]    disk    ATA      ST1000LM024 HN-M 2BA3  /dev/sda
[1:0:0:0]    cd/dvd  PLDS     DVD-RW DA8A5SH   RL61  /dev/sr0
[4:0:0:0]    disk    Generic- xD/SD/M.S.       1.00  /dev/sdb
选项 -s 显示设备大小

tecmint@tecmint ~ $ lsscsi -s
[0:0:0:0]    disk    ATA      ST1000LM024 HN-M 2BA3  /dev/sda   1.00TB
[1:0:0:0]    cd/dvd  PLDS     DVD-RW DA8A5SH   RL61  /dev/sr0        -
[4:0:0:0]    disk    Generic- xD/SD/M.S.       1.00  /dev/sdb        -

13.md5sum命令:效验文件MD5值

root@tecmint:~# md5sum teamviewer_linux.deb

47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

14. dd命令转换和拷贝一个文件,多数情况是将ISO转换到usb上

root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync
if------输入设备;of------输出设备

15. uname命令 :显示系统信息

没有选项,显示使用系统
tecmint@tecmint ~ $
Linux
选项-n显示网络主机名
tecmint@tecmint ~ $ uname -n
tecmint.com
选项-v显示操作系统版本
tecmint@tecmint ~ $ uname -v
#64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014
选项-r显示内核版本号
tecmint@tecmint ~ $ uname -r
3.13.0-37-generic
-m 选项;机器硬件名
tecmint@tecmint ~ $ uname -m
x86_64
选项 -a 显示所有
tecmint@tecmint ~ $ uname -a
Linux tecmint.com 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
16. cal 命令用于显示日历,无选项显示当前日历

root@tecmint:~# cal
May 2013
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
显示已经过去的月份,1835年2月
root@tecmint:~# cal 02 1835
February 1835
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
显示未来的月份,2145年7月

root@tecmint:~# cal 07 2145
July 2145
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

17. date 命令显示当前日期,设置日期用--set选项

root@tecmint:~# date
Fri May 17 14:13:29 IST 2013
root@tecmint:~# date --set='14 may 2013 13:57'
Mon May 13 13:57:00 IST 2013
18.history 命令:列出最后执行的命令
[narad@tecmint ~]$ history
1  PS1='\e[1;35m[\u@\h \w]\$ \e[m '
2  PS1="\e[0;32m[\u@\h \W]\$ \e[m "
3  PS1="\u@\h:\w [\j]\$ "
4  ping google.com
5  echo $PS1
6   tail -f /var/log/messages
7  tail -f /var/log/messages
8  exit
9  clear
10  history
11  clear
12  history
删除历史记录使用选项 -c
搜索历史使用:history | grep pwd

[narad@tecmint ~]$ history | grep pwd
113  2013-06-09 10:40:12     pwd
141  2013-06-09 10:40:12     pwd
198  2013-06-09 15:46:23     history | grep pwd
202  2013-06-09 15:47:39     history | grep pwd

19.chmod修改文件权限命令,通常使用权限的数字格式

完整权限
root@tecmint:~# chmod 777 abc.sh
读和写权限
root@tecmint:~# chmod 666 abc.sh
自己读写、执行;组执行;其他执行
root@tecmint:~# chmod 711 abc.sh

20. chown 改变文件拥有者和组,首先用 ls -l查看

root@tecmint:~# ls -l
drwxr-xr-x 3 server root 4096 May 10 11:14 Binary
drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
root@tecmint:~# chown server:server Binary
drwxr-xr-x 3 server server 4096 May 10 11:14 Binary
drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
更改用户每一个给定的文件到新的拥有者或将现有的用户的文件到存在的组的所有权。

21. diff 命令:比较两个文件的不同

# man diff


重要命令常常用于系统分析

22. hostname命令:显示系统主机名、域名或节点



23 useradd/adduser命令:创建新用户



更多详细: centos7系统命令useradd/adduser.

24 userdel/deluser:删除用户命令
# userdel tecmint
-f 强制删除、r移除home目录、-R目录到chroot入口、-Z移除SElinux映射
chroot------一个系统调用,将home改到此,可以禁止用户使用home目录,另外用于调试程序
25 usermod命令:改变用户
设置用户SUID属性
#chmod u+s a.txt
取消用户SUID属性
#chmod u-s a.txt
设置组SGID属性
# chmod g+s a.txt
设置目录Sticky Bit属性
# chmod o+t /opt/
更多详细: centos7系统命令usermod.
26 killall命令给所有用户进程发送信号,以下是句法、用法样例

# killall [signal or option] Process Name
# killall mysqld
# service mysql status
# pgrep mysql
# ps -aux | grep mysql
27.whereis命令:锁定二进制源和手册
root@tecmint:~# whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
root@tecmint:~# whereis kill
kill: /bin/kill /usr/share/man/man2/kill.2.gz /usr/share/man/man1/kill.1.gz

28. df 命令:显示文件系统

root@tecmint:~# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda1       47929224 7811908  37675948  18% /
none                   4       0         4   0% /sys/fs/cgroup
udev             1005916       4   1005912   1% /dev
tmpfs             202824     816    202008   1% /run
none                5120       0      5120   0% /run/lock
none             1014120     628   1013492   1% /run/shm
none              102400      44    102356   1% /run/user
/dev/sda5         184307   79852     94727  46% /boot
/dev/sda7       95989516   61104  91045676   1% /data
/dev/sda8       91953192   57032  87218528   1% /personal

30. 命令评估文件的使用,以递归方式列车文件使用情况

root@tecmint:~# du
8       ./Daily Pics/wp-polls/images/default_gradient
8       ./Daily Pics/wp-polls/images/default
32      ./Daily Pics/wp-polls/images
8       ./Daily Pics/wp-polls/tinymce/plugins/polls/langs
8       ./Daily Pics/wp-polls/tinymce/plugins/polls/img
28      ./Daily Pics/wp-polls/tinymce/plugins/polls
32      ./Daily Pics/wp-polls/tinymce/plugins
36      ./Daily Pics/wp-polls/tinymce
580     ./Daily Pics/wp-polls
1456    ./Daily Pics
36      ./Plugins/wordpress-author-box
16180   ./Plugins
12      ./May Articles 2013/Xtreme Download Manager
4632    ./May Articles 2013/XCache

31. echo命令:显示文本内容

root@tecmint:~# echo "Tecmint.com is a very good website"
Tecmint.com is a very good website
创建一个交互脚本
#!/bin/bash
echo "Please enter your name:"
read name
echo "Welcome to Linux $name"

root@tecmint:~# chmod 777 interactive_shell.sh
root@tecmint:~# ./interactive_shell.sh
Please enter your name:
Ravi Saive
Welcome to Linux Ravi Saive

32. lpr 打印文件

root@tecmint:~# lpr -P deskjet-4620-series 1-final.pdf
现在可以看一个pdf文件了
33. cmp命令:比较两个文件
root@tecmint:~# cmp file1.txt file2.txt
file1.txt file2.txt differ: byte 15, line 1

34. wget 命令从web下载包文件,以下为:使用wget下载ffmpeg

root@tecmint:~# wget http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 --2013-05-22 18:54:52--  http://downloads.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.34.181.59
Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 [following]
--2013-05-22 18:54:54--  http://kaz.dl.sourceforge.net/project/ffmpeg-php/ffmpeg-php/0.6.0/ffmpeg-php-0.6.0.tbz2 Resolving kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)... 92.46.53.163
Connecting to kaz.dl.sourceforge.net (kaz.dl.sourceforge.net)|92.46.53.163|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 275557 (269K) [application/octet-stream]
Saving to: ‘ffmpeg-php-0.6.0.tbz2’
100%[===========================================================================>] 2,75,557    67.8KB/s   in 4.0s
2013-05-22 18:55:00 (67.8 KB/s) - ‘ffmpeg-php-0.6.0.tbz2’ saved [275557/275557]

35. mount命令:安装文件系统

root@tecmint:~# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk
├─sda1   8:1    0 923.6G  0 part /
├─sda2   8:2    0     1K  0 part
└─sda5   8:5    0   7.9G  0 part [SWAP]
sr0     11:0    1  1024M  0 rom
sdb      8:16   1   3.7G  0 disk
└─sdb1   8:17   1   3.7G  0 part
root@tecmint:~# su
Password:
root@tecmint:~# cd /dev
root@tecmint:~# mkdir usb
现在安装文件系统到usb
root@tecmint:~# mount /dev/sdb1 /dev/usb
装入一个ISO文件系统

# mount -t iso9660 -o loop /home/tecmint/Fedora-18-i386-DVD.iso /mnt/iso/

36. umount命令:卸载文件系统

选项 -a 卸载所有文件系统、-A卸载给定设备、-f强制卸载、-l惰性协助同时删除later

-R 递归卸载指定设备的所有的子设备、 -t按文件类型卸载
# umount /mnt/iso
OR
$ sudo umount /mnt/iso
37.su – 用户开关命令: – 选项返回根用户提示输入口令,用户名-进入用户
38. sodu命令:执行根命令--又称超级管理员命令
我们能运行‘/usr/sbin/visudo‘ 目录下的命令
$ sudo /usr/sbin/visudo
注意:唯有root可以编辑‘/usr/sbin/visudo‘ 文件

root ALL=(ALL) ALL
adam ALL=(ALL) ALL
tom ALL=(ALL) ALL
mark ALL=(ALL) ALL
参数说明

User_name: ‘sudo‘ 用户的名字

Machine_name: 主机名

(Effective_user): 允许执行系统命令的用户

Command: 用户运行的命令和命令集

增加可以使用sudo的用户
adduser bob sudo
39. Yum命令:自动包安装、升级、搜索,以下为升级内核

# yum  update kernel
更多详细: 20个yum命令使用详解centos7.
40.zip文件被广泛使用,必须学习zip命令

# yum install zip
创建一个加密zip文件

$ zip --password mypassword tecmint.zip tecmint.txt tecmint1.1txt tecmint2.txt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 系统