| The Linux Filesystem Hierarchy: Understanding /, /home, /etc, /var, /bin, and More | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Root (/)
Linux has no concept of drives and Windows/macOS file systemseverything on the system is in a tree top of the tree is the root standard sudirectories of root
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Absolute vs. Relative Paths | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Absolute Path
full and complete path starting a the /rootunambiguous always starts with a forward slash (/) The Relative Path
never starts with a forward slash (/)if the folder is /home/anna with a subfolder named Documents, get to Documents folder using cd Documentspath is relative to current position in the tree |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Essential Navigation Commands: ls, cd, pwd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Where Am I (pwd)
provides current folder as an absolute path
Look Around (ls)
lists contents of current directory
Change Directory (cd)
to move down from /home/anna to Documents subfolder
cd Documentspwd command returns /home/anna/Documentsto move to the root cd /pwd command returns / |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Understanding Directory Structure and Organization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Linux hierarchy is defined by the FHS (Filesystem Hierarchy Standard) standard ensures consistency regardless of distribution the configuration files are always in /etc and the logs are always in /var/log structure allows for
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Special Directories: . (current), .. (parent), ~ (home) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Tilde (~)
represents user's home folderto get to home folder use command cd ~just entering cd does the same thing The Dot (.)
represents the current directoryto run a script in the current folder use the command ./<script name>.sh The Double Dot (..)
represents the current folder's parent folder
The Dash (-)
to return to the previous directory use the command
cd - |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Listing Files and Directories: Options for ls (-l, -a, -h) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Seeing the Details
-l flag stands for long listingoutput will be similar to drwxr-xr-x 2 anna anna 4096 Oct 27 10:00 Documents
Seeing Hidden Files (-a)
in Linux a file is hidden simply if its name starts with a dot (.)a home directory is full of hidden configuration files which store settings for apps to include hidden files and folders use the command ls -afiles like .bashrc, .profile, or folders like .config will be included in the listing deleting hidden files can reset the user's settings Human Readable Sizes (-h)
by default file sizes a presented as bytes58392012 bytes is not very useful the -h flag stands for Human Readable converts bytes to
using the command ls -lhwill show the file size as 4.0K or 56M Sorting Ouput
by default the output is sort alphabeticallyto sort by Time (newest first) use -t to reverse sort order use -r command combination is ls -lrtlong format (-l), reversed (-r), by time (-t) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Reading File Contents: cat, less, more, head, tail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
use in a terminal
cat
to view a filedumps content to the screen cat /etc/hostnameworks well with small files less
allows paging through file contents
less /etc/adduser.conf
head
displays the first 10 lines of a file
head /etc/adduser.confto display a different number of lines use the -n flag to show the first five lines head -n 5 /etc/adduser.conf tail
displays the last 10 lines of a fileuseful for log files where newest entry is at the end of the file tail /etc/adduser.conf tail -f
-f flag stands for followtail -f displays additional lines as they are added to the file tail -f /var/log/auth.log |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Summary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Linux uses a single tree absolute path starts with forward slash (/) relative path does not start with forward slash (/) cd .. moves up to parent folder cd ~ moves to user's home folder ls -l lists files with details ls -a include hidden files in list less best tool for reading large files tail -f follows a file in real time |