File paths in linux
Home directory in Linux
the home directory is a directory on a computer that is designated for the user’s personal files, directories, and configuration files. It is usually stored under the /home
directory on the system and is identified by the user’s username. For example, if the user’s username is “john”, the home directory would be /home/john
.
The home directory is often used to store the user’s documents, pictures, music, and other personal files. It is also used to store configuration files for the user’s applications and the operating system.
The home directory is usually set as the default directory when the user logs in to the system, so the user can easily access their personal files and configuration files. The user can also navigate to their home directory at any time by using the cd
command and specifying their username as the directory, like this:
cd ~
This will take the user to their home directory, regardless of their current location on the system.
Main Folders in Linux file System
there are several main folders that are used to store system files, configuration files, and user files. These folders are typically organized in a hierarchical structure, with the root directory (/
) at the top.
Here are some of the main folders in Linux:
Directory | Description |
---|---|
/ |
The root directory, which is the top-level directory in the file system |
/bin |
The bin directory, which contains executables that are available to all users |
/sbin |
The sbin directory, which contains executables that are used for system maintenance and are typically only available to the root user |
/etc |
The etc directory, which contains configuration files for the system and installed programs |
/lib |
The lib directory, which contains libraries (i.e., shared object files) that are used by executables in the /bin and /sbin directories |
/dev |
The dev directory, which contains special files that represent devices on the system |
/var |
The var directory, which contains files that are expected to change frequently, such as log files and spool directories |
/tmp |
The tmp directory, which is a place to store temporary files that are needed by programs |
/home |
The home directory, which contains the home directories of all users |
/usr |
The usr directory, which contains files that are shared among users, such as executables, libraries, documentation, and other data |
/opt |
The opt directory contains optional software packages that are installed by the system administrator. |
Paths in Linux
In Linux, a path is a string that specifies the location of a file or directory. There are two types of paths:
Absolute paths: An absolute path is a path that specifies the exact location of a file or directory, starting from the root directory (/). For example, /home/user/documents/file.txt
is an absolute path that specifies the location of the file file.txt
in the documents
directory inside the home
directory of the user
account.
Relative paths: A relative path is a path that specifies the location of a file or directory relative to the current working directory. For example, documents/file.txt
is a relative path that specifies the location of the file file.txt
in the documents
directory inside the current working directory.
To navigate to a different directory in Linux, you can use the cd
command followed by the path of the directory:
cd /home/user/documents
This will change the current working directory to the documents
directory inside the home
directory of the user
account.
You can use the pwd
command to print the current working directory:
pwd
This will output the absolute path of the current working directory.
Absolute paths in Linux
In Linux, an absolute path is a path that specifies the exact location of a file or directory, starting from the root directory (/). An absolute path always begins with a / character, which represents the root directory.
Here are some examples of absolute paths:
/
: The root directory
/home
: The home
directory, which contains the home directories of all users
/usr/bin
: The bin
directory inside the usr
directory, which contains executables that are available to all users
/var/log
: The log
directory inside the var
directory, which contains system log files
/etc/fstab
: The file fstab
inside the etc
directory, which contains information about the file systems that are mounted at boot time
To navigate to a directory using an absolute path, you can use the cd
command followed by the path:
cd /usr/bin
This will change the current working directory to the usr/bin
directory.
You can also use absolute paths to specify the location of a file or directory when running a command. For example:
ls /etc/fstab cat /var/log/syslog
For more information on absolute paths and navigating the file system in Linux, you can consult the bash
man page (man bash
).
Relative paths in file addresses
In Linux, a relative path is a path that specifies the location of a file or directory relative to the current working directory. A relative path does not begin with a / character, so it specifies the location of the file or directory relative to the current directory.
Here are some examples of relative paths:
Path | Description |
---|---|
. |
The current directory |
.. |
The parent directory of the current directory |
file.txt |
The file file.txt in the current directory |
documents/file.txt |
The file file.txt in the documents directory inside the current directory |
../file.txt |
The file file.txt in the parent directory of the current directory |
To navigate to a directory using a relative path, you can use the cd
command followed by the path:
cd documents
This will change the current working directory to the documents
directory inside the current directory.
You can also use relative paths to specify the location of a file or directory when running a command. For example:
ls file.txt cat ../file.txt