For Legend look here
Directory Structure
In Unix systems the complete directory structure begins at
/
the root directory.
_(Hint: Do not confuse with the MARKDOWN_HASH887904812217cca9bc2b9adb875daf42MARKDOWNHASH
that is the Home-Directory of the
root user. And it is often also called the root-directory)
Special Directories
Also Unix system have two additional special directory entries:
- Pseudo directory that is the same as the current directory
.
- Pseudo directory that is the same as the parent directory
..
Files
In Unix files do not necessarily need a filetype extension like .exe
or
.jpg
. The type of a file is determined by accessing the header of a file.
Unix also has a special meaning of files that start with a .
, these files are
considered "hidden".
Directory and File Addressing (Path)
And there are two ways to specify a path to a destination directory:
-
Absolute Path
Absolute Paths start from always from the root of the directory structure.
Example:
/home/zasher # Is the path to the **Home-Directory** of user
zasher
-
Relative Path
A relative path is always in relation to the current directory we are working
inExample:
# Current Working Directory is /home # Then: zasher # is the path to the **Home-Directory** of user
zasher
Common Locations on Linux
Most Distributions of Linux have a common directory structure,
-
Personal Directories of users are located under:
/home
with additional seperation by user name.
-
Executable programs are located under several locations:
# Normal programs /bin /usr/bin /usr/local/bin # Super-User related programs /sbin /usr/sbin /usr/local/sbin
-
System-wide Configurations are located under:
/etc
-
System Log Files (Events happening in the System or Applications):
/var/log
Locations in Home Directory
Some directories in the home directory of users have also special purposes.
They are defined by the Freedesktop XDG Base Directory
Specification
There should be special environment variables that lead to the corresponding
location.
Unfortunately not all applications, shell and distributions honor this.
-
User Configurations should reside in:
# Location /home/
/.config # Variable $XDG_CONFIG_HOME unfortunately not all applications honor this.
-
Application-User specific files:
# Location /home/
/.local/share # Variable $XDG_DATA_HOME -
User Caching Directory
# Location /home/
/.cache # Variable $XDG_CACHE_HOME
Working with directories
We assume that the user is in /home/zasher
if not stated otherwise.
-
Finding the current directory:
pwd # /home/zasher
-
List all of files
-
In current directory:
ls
-
In current directory but with more informations:
ls -l
-
In a different directory:
ls
-
-
Change the current directory to an other directory
-
To a direct subdirectory of
pwd
:
cdExample:
pwd # /home/zasher cd projects pwd # /home/zasher/projects
-
To a subdirectory of a subdirectory of
pwd
:cd
/ Example:
pwd # /home/zasher/ cd projects/code pwd # /home/zasher/projects/code
-
To a directory in absolute path:
cd /
Example:
pwd # /home/zasher/projects cd /home/zasher pwd # /home/zasher
-
Change to parent directory:
cd ..
Example:
pwd # /home/zasher/projects cd .. pwd # /home/zasher
-
Change to parent of parent directory:
cd ../..
Example:
pwd # /home/zasher/projects/code cd ../.. pwd # /home/zasher
-
-
Create Directory
-
Single subdirectory:
mkdir
Example:
pwd # /home/zasher mkdir testdrive ls # list contents with
testdrive
in the list -
Subdirectory structure:
mkdir -p
/ Here the
-p
is maybe needed to tell the command to create parent
directory of<SUBDIRECTORY>
if it does not exist.Example:
pwd # /home/zasher mkdir -p testdrive/some_folder ls -R testdrive # should list the direcory structure under
testdrive
-
-
Delete a Directory
In general, unix system do not have a trashcan, so all delete operations are
inherently permanent.-
Empty subdirectory of
pwd
:rm -r
-
Non-Empty subdirectory of
pwd
:# ⚠⚠⚠ Be Aware, this will also delete all contents of
without question. rm -rf -
Delete contents of a directory:
# ⚠⚠⚠ Be Aware, this will delete all contents of
without question. rm -rf /*
-