Linux Directory Structure
In Linux, most of the operations are performed on files, for example, text files or images. Directories (folders) are used to help you organize your files. Think of directories like folders in a file cabinet. They have names, just like files, but their function is to contain other files, and other directories. In this way, you can keep the files on your system separate and sorted according to their function or purpose.
File Names in Linux are case sensitive. Hence, "File1" and "file1" would represent different files.
File names that begin with a period (".file1") are hidden.
Don’t use spaces.
Limit punctuation to periods, dashes, and underscores.
The directory at the highest level of hierarchy in a file system is called the root directory. The root directory contains all other folders and files. Every directory, except the root directory, lies beneath another directory. The directory containing the current directory is called the parent directory, and the directory located within the current directory is called a subdirectory. Subdirectories branch off the root of the directory tree. Unlike a real tree, directory trees are upside down. Hence, the root is at the top and the branches reach down. When you move into a subdirectory, you are moving down the tree. When you move into a directory’s parent directory, you are moving up the tree.
By default, when you open a terminal and begin using the command line, you are placed in your home directory.
It’s the path that indicates the position of a file or directory with respect to the root directory. The absolute path of the root directory is a forward slash ( / ). It starts at the root directory ( / ) and works down. To check the absolute path of any directory, open a terminal and type the pwd command. When the command is invoked, the completed path of the current working directory gets printed. The below example shows the absolute path of the home directory.
Consider that the home directory contains the following files and subdirectories.
If you want to open test.txt from the home directory, simply type the following command.
On the other hand, if your current working directory isn’t the home directory and you want to open the test.txt file, then you need to specify the absolute path to the file to display it.
It’s the path which is related to the current working directory. It starts at your current directory and never starts with a /. Consider the following example.
In the image above, the absolute path for a
python directory will be,
/home/<username>/sample-scripts/python. Consider that you’re already in the
sample-scripts directory and hence the relative path will be
Two cryptic symbols are used with relative paths.
. (a single dot)
to represent the current working directory.
.. (two dots)
to represent the parent directory and move up the file hierarchy.
The above symbols can be better understood with the following examples. Consider that you are inside the
cd .. helps to go one level up in the file hierarchy.
cd .. pwd /home/username/sample-scripts
cd . indicates the current working directory and doesn’t move up.
cd . pwd /home/username/sample-scripts/python