Not able to execute standard commands on centos 7 server

I am not able to run basic commands on my centos 7 server. The PATH variable looks correct I think. I have not seen this before and not sure what to do next. Thank you :).

# cd /usr/bin
# ls
bash: ls: command not found...
Similar command is: 'lz'
nano ~/.bashrc
bash: nano: command not found...
# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/sbin:/root/bin:/root/bin

Hmmmm.......the first thing to do is to find out whether the 'ls' command executable exists or whether your O/S installation is damaged.

Ask the system for the location of the 'ls' command by either:

# which ls

or

# find / -name ls -print

If either of those comes out with a pathname then try to execute:

# <full pathname of ls command as output>

to see if it works.

If you cannot find where 'ls' is located with the above, then the installation has been damaged resulting in the command 'ls' no longer existing.

The above assumes that you have root access to the system.

1 Like

On many UNIX, Linux, and BSD systems, one would expect the standard commands to be located in /bin or /usr/bin (neither of which are included in the directories in your PATH setting).

1 Like

Since the commands didn't return anything @hicksd8, the $PATH variable may need to be edited to include /usr/bin where ls and nano reside.

I seem to have issues setting $PATH , so if I do:

sudo /usr/bino/nano ~/.bashrc

and edit

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/sbin:/root/bin:/root/bin (current PATH)

to include /usr/bin

/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/usr/sbin:/root/bin:/root/bin

Is that the correct place and why are some lines duplicated? Thank you :).

Check /etc/profile and /etc/environment files for the statement that sets the PATH variable. Be sure /bin and /usr/bin are included.

Otherwise, if whatever went wrong may have originated there, it will cause more problems on reboot.

1 Like

You have /usr/sbin in your PATH setting twice. Having any directory in PATH more than once will slow down access to any utilities found in any directory after the second occurrence of that directory.

Unless you have some utility that appears in more than one of the directories in PATH , you want the directory that contains the most frequently used utilities first in your PATH and the directory containing the utilities that are the least frequently used last in your PATH . Under usual circumstances, you'll want to put /usr/bin first in PATH (and get rid of one of the /usr/sbin entries and one of the /root/bin entries) like:

/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/root/bin

Given the naming conventions used on the directories in your PATH , is there also a /root/sbin directory containing utilities that you sometimes want to find? And, as Jim suggested, if your system has /bin and /usr/bin as distinct directories, be sure that both of them are included in PATH .

1 Like

Thank you all for your help :).