Navigating the File System
Everything in Linux lives in one tree that starts at /, called the root. There are no drive letters like C:. A USB stick or a second disk is attached ("mounted") somewhere inside that tree.
The folders you will meet most
| Path | What lives there |
|---|---|
/home/<user> |
your files (shortcut: ~) |
/etc |
system configuration files |
/var/log |
log files |
/var/www |
websites, by convention |
/usr/bin, /bin |
installed programs |
/tmp |
temporary files, cleared on reboot |
/opt |
optional, self-contained software |
/root |
the root user's home |
Absolute vs relative paths
- An absolute path starts with
/and works from anywhere:/home/panda/projects/app. - A relative path starts from where you are:
projects/app. .means "this folder" and..means "the parent folder".~means your home folder,-(withcd) means "the folder I was just in".
pwd # /home/panda
cd projects/app # relative
cd .. # up one level -> /home/panda/projects
cd /var/log # absolute
cd - # back to /home/panda/projects
cd # no argument -> home
Seeing what is there
ls # names only
ls -l # long: permissions, owner, size, date
ls -lh # human-readable sizes (4.0K, 12M)
ls -a # include hidden files (names starting with .)
ls -lt # newest first
tree -L 2 # folder tree two levels deep (if installed)
Hidden files are just files whose names start with a dot, like .bashrc or .env. They are hidden to keep listings tidy, not for security.
Names with spaces
The shell splits words on spaces, so cd My Projects tries to enter My with an extra argument. Quote it or escape the space:
cd "My Projects"
cd My\ Projects
Better still: avoid spaces in file names. Use my-projects or my_projects.
Worked example
You need the Nginx error log on a server you have never seen:
cd /var/log
ls -lt | head # most recently changed files first
cd nginx
ls -lh
You found it without knowing the path in advance, just by knowing the convention that logs live in /var/log.
Practice
In the Practice Terminal: cd projects, pwd, ls -la, cd .., cd -. Then complete the Find your way mission.
Check yourself
- You are in
/home/panda/projects/app. Where doescd ../..take you? - Why does
lsnot show.env, and how do you see it? - Which folder would you check first for a program's configuration?
ההתקדמות שלכם נשמרת בדפדפן הזה בלבד.
שליחה לבדיקה (10 נקודות)