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

1. 前言
在运维的过程中,有时我们想列出本服务器上的Linux系统所支持的所有命令,即列出所有可执行的命令(包括bash shell里的别名和功能)。如果你有这样的需求,请试试compgen
命令。本文主要介绍compgen
命令的作用和使用
2. compgen
的使用案例
输出结果
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
的命令
findfs
btrfs-find-root
find
oldfind
nl-link-ifindex2name
nl-link-name2ifindex
findmnt
find2perl
这里只展示部分
查看本系统目前有多少命令可执行
1288
查看本用户有权限执行的命令数量
输出结果,
root user can run 1288 commands on CentOS7.linuxrumen.com.
表示本用户root可以运行1288个命令。
查看有多少别名命令,即使用了aliases
定义了别名
cp
egrep
fgrep
grep
l.
ll
ls
mv
rm
which
查看内嵌命令
.
:
[
alias
bg
bind
break
builtin
caller
cd
command
compgen
complete
查看bash关键字
if
then
else
elif
fi
case
esac
for
select
while
until
do
done
in
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
命令用于修改文件或者目录的权限,包括本用户的权限,同组用户的权限,其它用户的权限。