Search Engine



RedhatEnterpriseLinux Blog

How to Find Commands

If you know a command exists on the system but keep getting the error message command not found, check to make sure you are typing the command correctly. Otherwise, it might not be in your PATH environment variable. To view the value of your PATH, execute the command echo $PATH from the command line. As you can see, your PATH is a list of directories. When you execute a command without providing its full path, it must be in one of the directories listed in your PATH. Otherwise, the command not found error is displayed. You can provide the full path to the command if you know it, such as /sbin/lspci to execute the command to list the PCI devices. If you use the command often, but it is not in your PATH, you can add the directory to your PATH.

To add a directory to your path, modify the .bashrc file in your home directory. if you don’t know how to modify a text file. For example, to add the /usr/sbin/ and /sbin/ directories to your PATH, add the following line to the .bashrc file in your home directory:

export PATH=:$PATH:/usr/sbin:/sbin

It is not recommended that you add the dot (.) character to your path so that it includes whatever the current working directory is. Although this might be tempting when writing and testing your own scripts, it is a security risk because an authorized or  nonauthorized user can place a different version of common commands in a directory you are likely to be in while executing them such as the /tmp/ directory, which is writable by all users. For example, if someone places a different version of the command ls in the /tmp/ directory and (which represents the current working directory) is listed before /bin in your PATH, you will be executing a different version of ls, which could contain code to do something harmful to your data or the system. If you need to execute a command in the current working directory, precede it by ./ such as ./ or provide its full path when executing it.


Post a Comment

Powered by Blogger.


Copyright © Redhat Enterprise linux. Original Concept and Design by My Blogger Themes
My name is Abdul Razaq but people call me Raziq. Here is my home page: I live in Quetta, Pakistan and work as an IT-Engineer.