What is a command? How do commands work? Why do commands not work?
Most importantly, what does command not found mean and how do I fix it?Console Output: Select all
$ filebot -version
filebot: command not found
$ java -version
java: command not found
$ node -v
node: command not found
...1. The $PATH
When you call a command such as filebot then the shell will check each folder that is in the $PATH for an executable (or symlink to an executable) with exactly that name.Let's have a look at the $PATH:
Console Output: Select all
$ echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/binThe which command can tell us which executable is executed for a given command:
Console Output: Select all
$ which filebot
/usr/local/bin/filebotThe ls -l command can further tell us if this executable is a symlink and where that symlinks points to:
Console Output: Select all
$ ls -l `which filebot`
lrwxrwxrwx 1 root root 37 Jul 21 15:48 /usr/local/bin/filebot -> /var/packages/filebot/target/bin/filebot.sh2. How to symlink an executable into the $PATH?
Let's say we have command that does not work:Console Output: Select all
$ filebot -version
filebot: command not foundand an executable that does work:
Console Output: Select all
$ /var/packages/filebot/target/bin/filebot.sh -version
FileBot 4.8.2 (r5728) / Java(TM) SE Runtime Environment 1.8.0_181 / Linux 3.2.40 (arm)We can easily make this work by symlinking our filebot executable into the $PATH:
Shell: Select all
ln -sf /var/packages/filebot/target/bin/filebot.sh /usr/local/bin/filebotLet's test our new symlink first:
Console Output: Select all
$ /usr/local/bin/filebot -version
FileBot 4.8.2 (r5728) / Java(TM) SE Runtime Environment 1.8.0_181 / Linux 3.2.40 (arm)Finally, confirm that the filebot command can now be found:
Console Output: Select all
$ filebot -version
FileBot 4.8.2 (r5728) / Java(TM) SE Runtime Environment 1.8.0_181 / Linux 3.2.40 (arm)Shell: Select all
export PATH="/var/packages/filebot/target/bin:$PATH"
filebot.sh -version3. How do I find an executable?
Let's say we're unfamiliar with the device we're using. We know that we have downloaded or installed some package somewhere, but we don't know where exactly. The find command can help us find out.e.g. search the entire filesystem for a file called java:
Shell: Select all
find / -type f -name "java" 2> /dev/null