一 .在Linux中,一般命令的通用语法格式如下:
command [options...] [ARGUMENTS...]
1.command:命令,表示可以执行的命令。常见的命令有二进制格式文件,或者脚本程序文件(本身是一定格式的文本文件,但需要由解释器解释才能运行)。
2.options:即选项,可以用来调整命令的运行特性。
选项分为三种风格:
(1).UNIX风格选项:用一个短横线开始,后面跟一个字母,有称短选项,支持多个选项进行组合。如:
[root@CentOS7 ~]# echo -e ‘I\flove\fyou‘ I love you [root@CentOS7 ~]# 上面的echo命令中的-e就是短选项
[root@CentOS7 ~]# echo "我的当前时间是:`date +‘%F %T‘`" 我的当前时间是:2021-01-31 22:20:33
[root@CentOS7 ~]# echo "一天前的时间是:`date -d ‘-1 day‘ +‘%F %T‘`" 一天前的时间是:2021-01-30 22:21:32
[root@CentOS7 ~]# 上面的date命令选项-d就是短选项
(2).GNU分割选项:用两个短横线开始,后面跟一个单词,一般不支持多个选项组合,又称长选项,如--all,--verbose,--help
[root@CentOS7 ~]# cp --archive --verbose /etc/hostname /data
‘/etc/hostname’ -> ‘/data/hostname’
[root@CentOS7 ~]#上面命令是将/etc的hostname这个文件包括属性信息都复制到/data下,并显示执行的过程
(3).BSD风格选项:一个字母,但前面的不加短横线,支持多个选项组合,支持此风格的命令相对上面两种风格来说不太多。如a,aux
[root@CentOS7 ~]# ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.3 128280 6936 ? Ss 21:27 0:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 22 root 2 0.0 0.0 0 0 ? S 21:27 0:00 [kthreadd] root 4 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/0:0H] root 5 0.0 0.0 0 0 ? S 21:27 0:00 [kworker/u256:0] root 6 0.0 0.0 0 0 ? S 21:27 0:00 [ksoftirqd/0] root 7 0.0 0.0 0 0 ? S 21:27 0:00 [migration/0] root 8 0.0 0.0 0 0 ? S 21:27 0:00 [rcu_bh] root 9 0.0 0.0 0 0 ? S 21:27 0:00 [rcu_sched] root 10 0.0 0.0 0 0 ? S< 21:27 0:00 [lru-add-drain] root 11 0.0 0.0 0 0 ? S 21:27 0:00 [watchdog/0] root 12 0.0 0.0 0 0 ? S 21:27 0:00 [watchdog/1] root 13 0.0 0.0 0 0 ? S 21:27 0:00 [migration/1] root 14 0.0 0.0 0 0 ? S 21:27 0:00 [ksoftirqd/1] root 16 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/1:0H] root 18 0.0 0.0 0 0 ? S 21:27 0:00 [kdevtmpfs] root 19 0.0 0.0 0 0 ? S< 21:27 0:00 [netns] root 20 0.0 0.0 0 0 ? S 21:27 0:00 [khungtaskd] root 21 0.0 0.0 0 0 ? S< 21:27 0:00 [writeback] root 22 0.0 0.0 0 0 ? S< 21:27 0:00 [kintegrityd] root 23 0.0 0.0 0 0 ? S< 21:27 0:00 [bioset] root 24 0.0 0.0 0 0 ? S< 21:27 0:00 [bioset] root 25 0.0 0.0 0 0 ? S< 21:27 0:00 [bioset] root 26 0.0 0.0 0 0 ? S< 21:27 0:00 [kblockd] root 27 0.0 0.0 0 0 ? S< 21:27 0:00 [md] root 28 0.0 0.0 0 0 ? S< 21:27 0:00 [edac-poller] root 29 0.0 0.0 0 0 ? S< 21:27 0:00 [watchdogd] root 30 0.0 0.0 0 0 ? S 21:27 0:01 [kworker/0:1] root 35 0.0 0.0 0 0 ? S 21:27 0:00 [kswapd0] root 36 0.0 0.0 0 0 ? SN 21:27 0:00 [ksmd] root 37 0.0 0.0 0 0 ? SN 21:27 0:00 [khugepaged] root 38 0.0 0.0 0 0 ? S< 21:27 0:00 [crypto] root 46 0.0 0.0 0 0 ? S< 21:27 0:00 [kthrotld] root 49 0.0 0.0 0 0 ? S< 21:27 0:00 [kmpath_rdacd] root 50 0.0 0.0 0 0 ? S< 21:27 0:00 [kaluad] root 51 0.0 0.0 0 0 ? S< 21:27 0:00 [kpsmoused] root 53 0.0 0.0 0 0 ? S< 21:27 0:00 [ipv6_addrconf] root 66 0.0 0.0 0 0 ? S< 21:27 0:00 [deferwq] root 101 0.0 0.0 0 0 ? S 21:27 0:00 [kauditd] root 246 0.0 0.0 0 0 ? S< 21:27 0:00 [ata_sff] root 247 0.0 0.0 0 0 ? S 21:27 0:00 [scsi_eh_0] root 249 0.0 0.0 0 0 ? S< 21:27 0:00 [scsi_tmf_0] root 250 0.0 0.0 0 0 ? S 21:27 0:00 [scsi_eh_1] root 251 0.0 0.0 0 0 ? S< 21:27 0:00 [scsi_tmf_1] root 254 0.0 0.0 0 0 ? S< 21:27 0:00 [mpt_poll_0] root 255 0.0 0.0 0 0 ? S< 21:27 0:00 [nfit] root 256 0.0 0.0 0 0 ? S< 21:27 0:00 [mpt/0] root 264 0.0 0.0 0 0 ? S 21:27 0:00 [scsi_eh_2] root 265 0.0 0.0 0 0 ? S< 21:27 0:00 [scsi_tmf_2] root 267 0.0 0.0 0 0 ? S 21:27 0:00 [irq/16-vmwgfx] root 268 0.0 0.0 0 0 ? S< 21:27 0:00 [ttm_swap] root 292 0.0 0.0 0 0 ? S< 21:27 0:00 [bioset] root 293 0.0 0.0 0 0 ? S< 21:27 0:00 [xfsalloc] root 294 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs_mru_cache] root 295 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-buf/sda2] root 296 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-data/sda2] root 297 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-conv/sda2] root 298 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-cil/sda2] root 299 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-reclaim/sda] root 300 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-log/sda2] root 301 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-eofblocks/s] root 302 0.0 0.0 0 0 ? S 21:27 0:01 [xfsaild/sda2] root 303 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/1:1H] root 386 0.0 0.1 39312 3588 ? Ss 21:27 0:00 /usr/lib/systemd/systemd-journald root 406 0.0 0.2 119180 5344 ? Ss 21:27 0:00 /usr/sbin/lvmetad -f root 415 0.0 0.3 50084 6468 ? Ss 21:27 0:00 /usr/lib/systemd/systemd-udevd root 490 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-buf/sda3] root 492 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-buf/sda1] root 494 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/u257:0] root 496 0.0 0.0 0 0 ? S< 21:27 0:00 [hci0] root 497 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-data/sda3] root 498 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-data/sda1] root 500 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-conv/sda1] root 502 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-cil/sda1] root 504 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-reclaim/sda] root 506 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-log/sda1] root 508 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-eofblocks/s] root 513 0.0 0.0 0 0 ? S 21:27 0:00 [xfsaild/sda1] root 517 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-conv/sda3] root 520 0.0 0.0 0 0 ? S< 21:27 0:00 [hci0] root 523 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-cil/sda3] root 526 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-reclaim/sda] root 527 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/u257:2] root 528 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-log/sda3] root 529 0.0 0.0 0 0 ? S< 21:27 0:00 [xfs-eofblocks/s] root 530 0.0 0.0 0 0 ? S 21:27 0:00 [xfsaild/sda3] root 572 0.0 0.1 55532 2896 ? S<sl 21:27 0:00 /sbin/auditd root 574 0.0 0.0 84556 816 ? S<sl 21:27 0:00 /sbin/audispd root 576 0.0 0.0 55620 1384 ? S< 21:27 0:00 /usr/sbin/sedispatch root 578 0.0 0.0 0 0 ? S< 21:27 0:00 [rpciod] root 579 0.0 0.0 0 0 ? S< 21:27 0:00 [xprtiod] rpc 600 0.0 0.0 69256 1008 ? Ss 21:27 0:00 /sbin/rpcbind -w root 601 0.0 0.0 26384 1820 ? Ss 21:27 0:00 /usr/lib/systemd/systemd-logind dbus 602 0.0 0.1 69776 3528 ? Ssl 21:27 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activ root 604 0.0 0.0 16900 1372 ? SNs 21:27 0:00 /usr/sbin/alsactl -s -n 19 -c -E ALSA_CONFIG_PATH=/etc/alsa/alsactl.conf --initfile=/ root 606 0.0 0.0 21684 1308 ? Ss 21:27 0:00 /usr/sbin/irqbalance --foreground root 608 0.0 0.4 430628 7548 ? Ssl 21:27 0:00 /usr/sbin/ModemManager root 609 0.0 0.2 168148 5024 ? Ss 21:27 0:00 /usr/bin/VGAuthService -s root 610 0.0 0.2 221644 5156 ? Ssl 21:27 0:02 /usr/bin/vmtoolsd root 611 0.0 0.1 52792 2732 ? Ss 21:27 0:00 /usr/sbin/smartd -n -q never polkitd 612 0.0 0.8 616396 14856 ? Ssl 21:27 0:00 /usr/lib/polkit-1/polkitd --no-debug libstor+ 613 0.0 0.0 8580 824 ? Ss 21:27 0:00 /usr/bin/lsmd -d root 615 0.0 0.1 90568 3180 ? Ss 21:27 0:00 /sbin/rngd -f root 617 0.0 0.2 396444 4052 ? Ssl 21:27 0:00 /usr/libexec/accounts-daemon root 618 0.0 0.1 57504 2556 ? Ss 21:27 0:00 /usr/libexec/bluetooth/bluetoothd rtkit 619 0.0 0.0 198784 1776 ? SNsl 21:27 0:00 /usr/libexec/rtkit-daemon root 620 0.0 0.3 228176 5636 ? Ss 21:27 0:00 /usr/sbin/abrtd -d -s root 622 0.0 0.2 225840 4812 ? Ss 21:27 0:00 /usr/bin/abrt-watch-log -F BUG: WARNING: at WARNING: CPU: INFO: possible recursive lo root 626 0.0 0.2 225840 4812 ? Ss 21:27 0:00 /usr/bin/abrt-watch-log -F Backtrace /var/log/Xorg.0.log -- /usr/bin/abrt-dump-xorg - root 631 0.0 0.3 451332 6440 ? Ssl 21:27 0:00 /usr/libexec/udisks2/udisksd avahi 635 0.0 0.1 62264 2256 ? Ss 21:27 0:00 avahi-daemon: running [CentOS7.local] root 661 0.0 0.0 201428 1260 ? Ssl 21:27 0:00 /usr/sbin/gssproxy -D avahi 665 0.0 0.0 62140 396 ? S 21:27 0:00 avahi-daemon: chroot helper root 687 0.0 0.0 6612 296 ? Ss 21:27 0:00 /usr/sbin/mcelog --ignorenodev --daemon --syslog root 691 0.0 1.6 358840 29564 ? Ssl 21:27 0:00 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid root 699 0.0 0.0 115408 948 ? S 21:27 0:00 /bin/bash /usr/sbin/ksmtuned root 733 0.0 0.0 0 0 ? S< 21:27 0:00 [kworker/0:1H] root 737 0.0 0.6 626180 11244 ? Ssl 21:27 0:00 /usr/sbin/NetworkManager --no-daemon root 883 0.0 0.2 102904 5496 ? S 21:27 0:00 /sbin/dhclient -d -q -sf /usr/libexec/nm-dhcp-helper -pf /var/run/dhclient-ens33.pid root 1070 0.0 0.9 574284 17468 ? Ssl 21:27 0:00 /usr/bin/python2 -Es /usr/sbin/tuned -l -P root 1071 0.0 0.2 216400 4340 ? Ssl 21:27 0:00 /usr/sbin/rsyslogd -n root 1073 0.0 0.2 198072 4264 ? Ss 21:27 0:00 /usr/sbin/cupsd -f root 1075 0.0 0.2 112900 4312 ? Ss 21:27 0:00 /usr/sbin/sshd -D root 1081 0.0 1.0 1006580 18524 ? Ssl 21:27 0:00 /usr/sbin/libvirtd root 1087 0.0 0.0 25908 928 ? Ss 21:27 0:00 /usr/sbin/atd -f root 1088 0.0 0.0 126388 1676 ? Ss 21:27 0:00 /usr/sbin/crond -n root 1089 0.0 0.2 481416 4596 ? Ssl 21:27 0:00 /usr/sbin/gdm nobody 1302 0.0 0.0 53876 1084 ? S 21:27 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro -- root 1304 0.0 0.0 53848 380 ? S 21:27 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro -- root 1609 0.0 1.4 299836 26212 tty1 Ssl+ 21:27 0:00 /usr/bin/X :0 -background none -noreset -audit 4 -verbose -auth /run/gdm/auth-for-gdm root 1621 0.0 0.2 363124 4732 ? Sl 21:27 0:00 gdm-session-worker [pam/gdm-launch-environment] gdm 1625 0.0 0.5 818724 11012 ? Ssl 21:27 0:00 /usr/libexec/gnome-session-binary --autostart /usr/share/gdm/greeter/autostart gdm 1631 0.0 0.0 59016 960 ? S 21:27 0:00 dbus-launch --exit-with-session /usr/libexec/gnome-session-binary --autostart /usr/sh gdm 1632 0.0 0.1 68728 2024 ? Ssl 21:27 0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session gdm 1638 0.0 0.2 346780 3684 ? Sl 21:27 0:00 /usr/libexec/at-spi-bus-launcher gdm 1643 0.0 0.1 68392 2412 ? Sl 21:27 0:00 /usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --n gdm 1647 0.0 0.2 233104 3936 ? Sl 21:27 0:00 /usr/libexec/at-spi2-registryd --use-gnome-session gdm 1671 0.0 7.1 3221196 131096 ? Sl 21:27 0:02 /usr/bin/gnome-shell root 1679 0.0 0.3 430372 7212 ? Ssl 21:27 0:00 /usr/libexec/upowerd gdm 1699 0.0 0.3 1252160 6316 ? S<l 21:27 0:00 /usr/bin/pulseaudio --start --log-target=syslog gdm 1718 0.0 0.2 526848 5392 ? Sl 21:27 0:00 ibus-daemon --xim --panel disable gdm 1721 0.0 0.2 375984 5484 ? Sl 21:27 0:00 /usr/libexec/ibus-dconf gdm 1723 0.0 0.8 464824 15648 ? Sl 21:27 0:00 /usr/libexec/ibus-x11 --kill-daemon gdm 1729 0.0 0.1 375964 3344 ? Sl 21:27 0:00 /usr/libexec/ibus-portal gdm 1739 0.0 0.1 364704 2604 ? Sl 21:27 0:00 /usr/libexec/xdg-permission-store root 1746 0.0 0.2 398680 3980 ? Ssl 21:27 0:00 /usr/libexec/boltd root 1753 0.0 0.1 78660 3348 ? Ss 21:27 0:00 /usr/sbin/wpa_supplicant -u -f /var/log/wpa_supplicant.log -c /etc/wpa_supplicant/wpa root 1757 0.0 0.2 410656 5288 ? Ssl 21:27 0:00 /usr/libexec/packagekitd gdm 1762 0.0 0.8 615188 14848 ? Sl 21:27 0:00 /usr/libexec/gsd-xsettings gdm 1764 0.0 0.2 376452 5272 ? Sl 21:27 0:00 /usr/libexec/gsd-a11y-settings gdm 1768 0.0 0.7 464436 13420 ? Sl 21:27 0:00 /usr/libexec/gsd-clipboard gdm 1771 0.0 0.7 714088 14532 ? Sl 21:27 0:00 /usr/libexec/gsd-color gdm 1774 0.0 0.4 465484 7968 ? Sl 21:27 0:00 /usr/libexec/gsd-datetime gdm 1775 0.0 0.1 380716 3088 ? Sl 21:27 0:00 /usr/libexec/gsd-housekeeping gdm 1779 0.0 0.7 614184 13612 ? Sl 21:27 0:00 /usr/libexec/gsd-keyboard gdm 1784 0.0 0.9 1012016 17692 ? Sl 21:27 0:00 /usr/libexec/gsd-media-keys gdm 1789 0.0 0.1 300448 2844 ? Sl 21:27 0:00 /usr/libexec/gsd-mouse gdm 1795 0.0 0.9 639912 16684 ? Sl 21:27 0:00 /usr/libexec/gsd-power gdm 1797 0.0 0.2 363176 4524 ? Sl 21:27 0:00 /usr/libexec/gsd-print-notifications gdm 1802 0.0 0.1 317676 3088 ? Sl 21:27 0:00 /usr/libexec/gsd-rfkill gdm 1807 0.0 0.1 374184 2952 ? Sl 21:27 0:00 /usr/libexec/gsd-screensaver-proxy gdm 1811 0.0 0.2 411460 4140 ? Sl 21:27 0:00 /usr/libexec/gsd-sharing gdm 1815 0.0 0.2 472188 4984 ? Sl 21:27 0:00 /usr/libexec/gsd-smartcard gdm 1818 0.0 0.3 454952 6756 ? Sl 21:27 0:00 /usr/libexec/gsd-sound gdm 1822 0.0 0.8 557452 16168 ? Sl 21:27 0:00 /usr/libexec/gsd-wacom colord 1841 0.0 0.3 419600 6228 ? Ssl 21:27 0:00 /usr/libexec/colord gdm 1866 0.0 0.1 302168 3296 ? Sl 21:27 0:00 /usr/libexec/ibus-engine-simple root 2209 0.0 0.0 0 0 ? S 21:50 0:00 [kworker/u256:1] root 2356 0.0 0.0 123360 764 ? Ss 22:01 0:00 /usr/sbin/anacron -s root 2497 0.0 0.3 160988 5636 ? Ss 22:10 0:00 sshd: root@pts/0 root 2503 0.0 0.1 116324 2880 pts/0 Ss 22:10 0:00 -bash root 2571 0.0 0.0 0 0 ? S 22:13 0:00 [kworker/1:0] root 2747 0.0 0.0 0 0 ? S 22:24 0:00 [kworker/1:1] root 2774 0.0 0.0 0 0 ? S 22:27 0:00 [kworker/0:0] root 2816 0.0 0.0 0 0 ? R 22:29 0:00 [kworker/1:2] root 2853 0.0 0.0 108052 352 ? S 22:32 0:00 sleep 60 root 2854 0.0 0.0 0 0 ? S 22:32 0:00 [kworker/0:2] root 2855 0.0 0.1 155448 1852 pts/0 R+ 22:32 0:00 ps aux [root@CentOS7 ~]#上面的aux就是此风格,显示左右的后台进程。
3.ARGUMENTS:参数,表示命令的作用对象,比如文件名,用户名,网卡名等,有的命令支持多个参数,参数见使用空白字符分隔。
[root@CentOS7 ~]# cp --archive --verbose /etc/hostname /data ‘/etc/hostname’ -> ‘/data/hostname’ [root@CentOS7 ~]#上面命令的/etc/hostname和/data都是参数
二.命令格式中的符号含义。
在Linux中,命令的选项和参数所表示的符号也有相应的含义:
[]:表示方框里面的内容是可选的。
<>:表示尖括号里面的内容是必须提供。
a|b:二选一,或多选一。
...:前面的内容可重复出现多次。
原文:https://www.cnblogs.com/2021Linux/p/14354509.html