查看所有linux command执行命令和数量

1. 前言

在运维的过程中,有时我们想列出本服务器上的Linux系统所支持的所有命令,即列出所有可执行的命令(包括bash shell里的别名和功能)。如果你有这样的需求,请试试compgen命令。本文主要介绍compgen命令的作用和使用

查看Linux所有可以执行的命令

2. compgen的使用案例

[root@zcwyou ~]# compgen -c
Bash

输出结果
cp
egrep
fgrep
grep
l.
ll
ls
mv
rm
which
if
then
else
elif
fi
case
esac
for
select
while
until
do
done
in
function
time
{
}
!
还有更多未展示

查看关键字find的命令

[root@zcwyou ~]# compgen -c |grep find
Bash

findfs
btrfs-find-root
find
oldfind
nl-link-ifindex2name
nl-link-name2ifindex
findmnt
find2perl
这里只展示部分

查看本系统目前有多少命令可执行

[root@zcwyou ~]# compgen -c | wc -l
Bash

1288

查看本系统目前有多少命令可执行

查看本用户有权限执行的命令数量

[root@zcwyou ~]# echo "USER user can run(compgen -c | wc -l) commands on $HOSTNAME."
Bash

查看本用户有权限执行的命令数量

输出结果,
root user can run 1288 commands on CentOS7.linuxrumen.com.
表示本用户root可以运行1288个命令。

查看有多少别名命令,即使用了aliases定义了别名

[root@zcwyou ~]# compgen -a
Bash

cp
egrep
fgrep
grep
l.
ll
ls
mv
rm
which

查看内嵌命令

[root@zcwyou ~]# compgen -b
Bash

.
:
[
alias
bg
bind
break
builtin
caller
cd
command
compgen
complete

查看bash关键字

[root@zcwyou ~]# compgen -k
Bash

if
then
else
elif
fi
case
esac
for
select
while
until
do
done
in
function

查看bash所有的功能

[root@zcwyou ~]# compgen -A function
Bash

3. Linux几个常用命令

顺便介绍几个常用命令:

ls [option(s)] [file(s)]
ls命令用于列出目标目录的文件和子目录的内容,默认情况下,只显示目录和文件名,以最简单形式显示。

cp [option(s)] sourcefile targetfile
cp命令用于复制目录或者文件到特定目录。

mv [option(s)] sourcefile targetfile
mv命令用于移动或重命名文件

rm [option(s)] file(s)
rm命令用于删除文件或目录,可一次删除多个目录或者文件

ln [option(s)] sourcefile targetfile
ln命令以不同的名称创建从源文件到目标文件的内部链接。通常,这样的链接直接指向同一个文件系统上的源文件。但是,如果使用-s选项执行ln,则会创建一个仅指向源文件所在目录的符号链接,从而启用跨文件系统的链接.

cd [options(s)] [directory]
cd命令用于切换当前的工作目录。

mkdir [option(s)] directoryname
mkdir创建目录

rmdir [option(s)] directoryname
rmdir用于删除一个空目录

chown [option(s)] username.group file(s)
chown用于修改文件或者的所有者。

chgrp [option(s)] groupname file(s)
chgrp命令将给定文件的组所有权转移到具有指定组名的组。如果现有组和新组的成员,则文件所有者只能更改组所有权。

chmod [options] mode file(s)
chmod命令用于修改文件或者目录的权限,包括本用户的权限,同组用户的权限,其它用户的权限。

未经允许不得转载:萌萌Apprentissage » 查看所有linux command执行命令和数量

赞 (1) 打赏

评论 0

Protected with IP Blacklist CloudIP Blacklist Cloud

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏