nerdexam
CompTIA

XK0-005 · Question #203

A systems administrator downloads an application's source files, compiles the application, and installs it per the application's installation instructions. When trying to run the application, the…

The correct answer is A. sudo ln -s /opt/occmd/bin/occmd /usr/local/bin/occmd B. echo "export PATH=$PATH:/opt/occmd/bin" >> ~/.bashrc. When a command is installed but not found by the shell, it's typically because its directory is not included in the system's PATH environment variable.

Troubleshooting

Question

A systems administrator downloads an application's source files, compiles the application, and installs it per the application's installation instructions. When trying to run the application, the system states:

$ occmd bash: occmd: command not found... Running the locate command shows it does exist in the following location:

/opt/occmd/bin/occmd Which of the following should the administrator do to allow the command to run properly? (Choose two.)

Options

  • Asudo ln -s /opt/occmd/bin/occmd /usr/local/bin/occmd
  • Becho "export PATH=$PATH:/opt/occmd/bin" >> ~/.bashrc
  • Cmv /opt/occmd ~/ && ln -s ~/occmd/bin/occmd ./occmd
  • Decho "#!/bin/bash \n ${which occmd}" > /usr/bin/occmd.sh
  • Esudo mv /opt/occmd/bin/occmd /etc/bin/
  • Fcd /opt/occmd/bin && chmod +x ./occmd && restorecon -rv *

How the community answered

(51 responses)
  • A
    71% (36)
  • C
    2% (1)
  • D
    4% (2)
  • E
    16% (8)
  • F
    8% (4)

Why each option

When a command is installed but not found by the shell, it's typically because its directory is not included in the system's PATH environment variable.

Asudo ln -s /opt/occmd/bin/occmd /usr/local/bin/occmdCorrect

Creating a symbolic link from the executable's location (`/opt/occmd/bin/occmd`) to a directory already in the system's PATH (such as `/usr/local/bin/`) allows the shell to find and execute the command by its name directly.

Becho "export PATH=$PATH:/opt/occmd/bin" >> ~/.bashrcCorrect

Modifying the `PATH` environment variable by adding `/opt/occmd/bin` to it ensures that the shell searches this directory when looking for commands, thus allowing `occmd` to be executed by name. This change is typically made persistent by adding it to `~/.bashrc`.

Cmv /opt/occmd ~/ && ln -s ~/occmd/bin/occmd ./occmd

Moving the application to the home directory is not a standard practice for system-wide applications, and the symlink created would only be local.

Decho "#!/bin/bash \n ${which occmd}" > /usr/bin/occmd.sh

This command attempts to create a shell script but uses incorrect syntax for executing and redirecting the output of `which occmd` and would not make `occmd` executable.

Esudo mv /opt/occmd/bin/occmd /etc/bin/

`/etc/bin/` is not a standard directory for executables; `/etc` is for configuration files.

Fcd /opt/occmd/bin && chmod +x ./occmd && restorecon -rv *

While `chmod +x` is necessary to make a file executable, and `restorecon` handles SELinux contexts, these actions do not solve the 'command not found' error if the executable's directory is not in the system's PATH.

Concept tested: Linux PATH variable and symbolic links for executables

Source: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/sect-setting-environment-variables

Topics

#PATH variable#Symbolic Links#Shell Configuration#Command Execution

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice