What does it mean that the path (PATH) is valid?
table of contents
My name is Nakagawa from the infrastructure team.
This article is about how commands work.
I took another look at the mechanism of commands that return various execution results, such as logging into a server and viewing logs, viewing file contents, and checking server status
When I look into the reason why the command can be executed, it says
that the path is present So, what does "because the pass is available" mean?
What is a path?
- Path/route to the target directory.
- The location of the file that executes the command.
The command is placed as a program at "2." and is recognized and executed as a command.
In other words, the path is passing = the program in the target directory is set as a command .
I'll check it out
Let's check using the ls command as an example.
- Find a program that executes the ls command with the which 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 located in a directory and then specify it using the full path.
Also, in the case of the ls command, it is easy to see because it is set to display files in different colors for each file type.
You can check the directory to which the path is currently set using the echo command.
Commands that you enter on the command line are searched for and executed in specific directories.
The path used to search for the executable file is called the command search path
The command search path is set in the directory in the environment variable PATH in the image above.
In this case, the following directory would be 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 path is passed because it searches for the corresponding file from the command search path and returns the execution result .
At the end
I often search for commands and options that suit my purpose, but
I didn't have a deep understanding of how the execution results were returned.
Memorizing the commands is a learning experience, but once I learned how it works,
I became more interested and understood.
That's all about how the path works.
Thank you for reading!