What does it mean that the path (PATH) is valid?

table of contents
I'm Nakagawa from the infrastructure team
This article is about how commands work.
We'll take a fresh look at how commands return various execution results, such as logging in to a server and viewing logs, viewing file contents, and checking the server status
When I check why the command can be executed, I find that it
is because the path is set So what does "because the path is set" mean?
What is a path?
- The path to the destination directory
- The location of the file that executes the command
The command is placed as a program in "2.", and is recognized and executed as a command.
In other words, if the path is set, the program in the target directory is set as a command .
Let's check it out
Let's take the ls command as an example
- Use the which command to find the program that executes the ls command
- Run the ls command to list the contents of the /bin/ directory
- Run /bin/ls to list the contents of the /bin/ directory

The execution results are the same!
However, it is time-consuming to search for a program in a directory and specify the full path.
Also, the ls command is set to display different colors for each file type, making it easy to see.
You can check the directory currently set in the path using the echo command

Commands entered on the command line are executed by searching for them in a specific directory.
The path to search for executable files at that time is called the command search path
The directories set in the PATH environment variable in the image above are the command search path.
In this case, the following directories are relevant:
- /usr/local/sbin
- /usr/local/bin
- /sbin
- /bin
- /usr/sbin
- /usr/bin
- /opt/aws/bin
- /root/bin
When you enter a command from the command line, the corresponding file is searched for in the command search path and
the execution result is returned, which means that the path is valid .
At the end
I often search for commands and options that suit my purpose, but I
didn't really understand how they work.
Learning commands is a learning experience, but learning how they work
has led to greater interest and understanding.
That's all about how the path works.
Thank you for reading!
2