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/bin
![Idea :idea:](./images/smilies/icon_idea.gif)
The which command can tell us which executable is executed for a given command:
Console Output: Select all
$ which filebot
/usr/local/bin/filebot
The 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.sh
2. 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 found
and 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/filebot
Let'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)
![Idea :idea:](./images/smilies/icon_idea.gif)
Shell: Select all
export PATH="/var/packages/filebot/target/bin:$PATH"
filebot.sh -version
3. 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
![Idea :idea:](./images/smilies/icon_idea.gif)
4. Read the Shell Scripting Tutorial
Learning basic shell scripting will take a few days. However, it's an extremely useful skill that will serve you well for the rest of your live. You don't need to be a mathematician to find basic math useful in daily life. You don't need to be a programmer to find basic shell scripting useful in daily life.![Wink ;)](./images/smilies/icon_e_wink.gif)
![Arrow :arrow:](./images/smilies/icon_arrow.gif)