【学了一招】解决搜索路径的问题 (Command not found)

BabbleDay posted @ 2013年9月06日 14:06 in 不折腾会死 , 779 阅读

 

系统管理指南:高级管理  link

解决搜索路径的问题 (Command not found)

Command not found 消息表示存在以下情况之一:

  • 命令在系统中不可用。

  • 命令目录不在搜索路径中。

要解决搜索路径问题,您需要知道存储命令的目录的路径名。

如果找到了该命令的错误版本,则一个包含同名命令的目录会出现在搜索路径中。在这种情况下,正确的目录可能稍后会出现在搜索路径中,或者根本不会出现。

使用 echo $PATH 命令可以显示当前的搜索路径。例如:

$ echo $PATH 
/home/kryten/bin:/sbin:/usr/sbin:/usr/bin:/usr/dt:/usr/dist/exe

使用 which 命令可以确定您所运行的命令是否是一个错误版本。例如:

$ which acroread 
/usr/doctools/bin/acroread

注 - which 命令在 .cshrc 文件中查找路径信息。如果从 Bourne 或 Korn shell 中执行 which 命令,并且有一个 .cshrc 文件中包含 which 命令的别名,则该命令可能会提供误导性的结果。为确保结果的准确性,请在 C shell 中使用 which 命令,或在 Korn shell 中使用 whence 命令。


如何诊断和更正搜索路径问题

  1. 显示当前搜索路径,以验证命令的目录是否不在路径中,或验证该路径是否有拼写错误。
    $ echo $PATH 
  2. 检查以下各项:
    • 搜索路径是否正确?

    • 该搜索路径是否在找到了该命令另一个版本的其他搜索路径之前列出?

    • 命令是否位于其中一个搜索路径中?

    如果需要更正路径,请转到步骤 3。否则,请转到步骤 4。

  3. 将路径添加到相应文件,如下表所示。
    Shell
    文件
    语法
    说明
    Bourne 和 Korn
    $HOME/.profile
    $ PATH=$HOME/bin:/sbin:/usr/local /bin ...

    $ export PATH

    用冒号分隔路径名。
    C
    $HOME/.cshrc

    $HOME/.login

    hostname% set path=( ~bin /sbin /usr/local/bin ...)
    用空格分隔路径名。
  4. 按以下方式激活新路径:
    Shell
    路径所在的文件
    激活路径的命令
    Bourne 和 Korn
    .profile
    $ . ./.profile
    C
    .cshrc
    hostname% source .cshrc
     
    .login
    hostnamesource .login
  5. 验证新路径。
    $ which command

示例 19-1 诊断和更正搜索路径问题

此示例显示执行 which 命令后发现,mytool 可执行文件并不存在于搜索路径中的任何目录内。

venus% mytool
mytool: Command not found
venus% which mytool
no mytool in /sbin /usr/sbin /usr/bin /etc /home/ignatz/bin  .
venus% echo $PATH
/sbin /usr/sbin /usr/bin /etc /home/ignatz/bin
venus% vi ~/.cshrc
(Add appropriate command directory to the search path)
venus% source .cshrc
venus% mytool

如果找不到某一命令,请在手册页中查看其目录路径。例如,如果找不到 lpsched 命令(lp 打印机守护进程),lpsched(1M) 手册页会告知您路径是 /usr/lib/lp/lpsched

Avatar_small
Reading details 说:
2022年8月05日 02:09

Tamil Nadu Electricity Board is the only source of power distribution in Tamil Nadu state. It does provide electricity to every consumer at affordable prices. The electricity processing is quick, and it gets install within short of consumers register with their department. Tamil Nadu Electricity Board is the only source of power distribution in Tamil Nadu state. Reading details It does provide electricity to every consumer at affordable prices.Tamil Nadu Generation and Distribution Corporation Limited is under the TamilNadu government, decide the unit rate applied on electricity usage. This price is the same for everyone around the state and the meter billing is all considered to be similar.

Avatar_small
Karnataka 9th Model 说:
2022年9月20日 23:09

KSEEB Question Paper 2023 Pdf Download for Karnataka 6th, 7th, 8th, 9th Class Model Paper 2023 Pdf with Answer Solutions for Kannada Medium, English Medium General and Vocational Course Mathematics, Science, Social Science (EVS), English, Kannada, Hindi and etc. Karnataka State Board High School Education Class 6th, 7th, 8th and 9th Standard Kannada Medium, English Medium Question Paper with answer solutions download for theory, Karnataka 9th Model Paper objective type multiple choice questions (MCQ) for KSEEB conducted general and vocational course SA, FA, Unit Tests, Quarterly, Half-yearly, Pre- Final and annual final public examination tests to the academic year of 2023.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter