Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 在Linux中查找命令的内置文件和可执行文件路径_C_Linux_Bash_Shell - Fatal编程技术网

C 在Linux中查找命令的内置文件和可执行文件路径

C 在Linux中查找命令的内置文件和可执行文件路径,c,linux,bash,shell,C,Linux,Bash,Shell,我试图在C中实现whereis命令,但我能够部分实现它。当我在Linux shell中尝试“Where is”时,让我们说一下Where is ls。。我得到以下结果 $ whereis ls /bin/ls /usr/share/man/man1p/ls.1p.gz /usr/share/man/man1/ls.1.gz 我可以使用path env.variable获得第一条路径。但是我不知道如何找到另外两条路。任何指向如何找到这些路径的指针。在Linux上(但不是在所有系统上,例如Mac

我试图在C中实现whereis命令,但我能够部分实现它。当我在Linux shell中尝试“Where is”时,让我们说一下Where is ls。。我得到以下结果

$ whereis ls
/bin/ls
/usr/share/man/man1p/ls.1p.gz
/usr/share/man/man1/ls.1.gz
我可以使用path env.variable获得第一条路径。但是我不知道如何找到另外两条路。任何指向如何找到这些路径的指针。

在Linux上(但不是在所有系统上,例如Mac OS上),
Where is
$MANPATH
(或一些其他默认位置)中搜索匹配的文件,ls的文件如下所示:

$MANPATH/man(.+)/ls\.\1(\.gz)?
如果您确实需要知道whereis的工作原理,只需查看它的源代码….

在Linux上(但不是在所有系统上,例如Mac OS上),
whereis
$MANPATH
(或其他一些默认位置)中搜索匹配的文件,对于ls,这些文件如下所示:

$MANPATH/man(.+)/ls\.\1(\.gz)?
如果您确实需要知道whereis的工作原理,只需查看它的源代码….

在Linux上(但不是在所有系统上,例如Mac OS上),
whereis
$MANPATH
(或其他一些默认位置)中搜索匹配的文件,对于ls,这些文件如下所示:

$MANPATH/man(.+)/ls\.\1(\.gz)?
如果您确实需要知道whereis的工作原理,只需查看它的源代码….

在Linux上(但不是在所有系统上,例如Mac OS上),
whereis
$MANPATH
(或其他一些默认位置)中搜索匹配的文件,对于ls,这些文件如下所示:

$MANPATH/man(.+)/ls\.\1(\.gz)?
如果你真的需要知道
whereis
是如何工作的,你只需看看它的源代码就可以了。

manwhereis
(Ubuntu 11.04)提到了以下路径:

/{bin,sbin,etc} /usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs} /{bin、sbin等} /usr/{lib,bin,old,new,local,games,include等,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man等,bin,games,emacs}
manwhereis
(Ubuntu 11.04)提到了以下路径:

/{bin,sbin,etc} /usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs} /{bin、sbin等} /usr/{lib,bin,old,new,local,games,include等,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man等,bin,games,emacs}
manwhereis
(Ubuntu 11.04)提到了以下路径:

/{bin,sbin,etc} /usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs} /{bin、sbin等} /usr/{lib,bin,old,new,local,games,include等,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man等,bin,games,emacs}
manwhereis
(Ubuntu 11.04)提到了以下路径:

/{bin,sbin,etc} /usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs} /{bin、sbin等} /usr/{lib,bin,old,new,local,games,include等,src,man,sbin,X386,TeX,g++-include} /usr/local/{X386,TeX,X11,include,lib,man等,bin,games,emacs}
另一个通常可用的选项是
,它
。它将返回可执行文件的完全限定路径和可执行文件名。例如:

$ which ls
/usr/bin/ls
它可以帮助您实现
where is
文件,并且对于脚本的可移植性也很有用,可以在不同发行版的不同位置设置可执行文件:

my_ls=$(which ls 2>/dev/null)
[ -x "$my_ls" ] || {
    echo "ls not found"
    exit 1
}

另一个通常可用的选项是
,它
。它将返回可执行文件的完全限定路径和可执行文件名。例如:

$ which ls
/usr/bin/ls
它可以帮助您实现
where is
文件,并且对于脚本的可移植性也很有用,可以在不同发行版的不同位置设置可执行文件:

my_ls=$(which ls 2>/dev/null)
[ -x "$my_ls" ] || {
    echo "ls not found"
    exit 1
}

另一个通常可用的选项是
,它
。它将返回可执行文件的完全限定路径和可执行文件名。例如:

$ which ls
/usr/bin/ls
它可以帮助您实现
where is
文件,并且对于脚本的可移植性也很有用,可以在不同发行版的不同位置设置可执行文件:

my_ls=$(which ls 2>/dev/null)
[ -x "$my_ls" ] || {
    echo "ls not found"
    exit 1
}

另一个通常可用的选项是
,它
。它将返回可执行文件的完全限定路径和可执行文件名。例如:

$ which ls
/usr/bin/ls
它可以帮助您实现
where is
文件,并且对于脚本的可移植性也很有用,可以在不同发行版的不同位置设置可执行文件:

my_ls=$(which ls 2>/dev/null)
[ -x "$my_ls" ] || {
    echo "ls not found"
    exit 1
}