Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 6Naam in de cursus: Navigating the File-system Hierarchy

Find your way in the file system

Linux has one tree of folders that starts at /. Disks, USB sticks and network shares do not get letters like C: — they are hung into this tree. This chapter shows what the main folders are for, how paths work, and how to move around fast.

  • 6 Lessen
  • 11 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Vaardigheden in dit hoofdstuk

  • Absolute en relatieve paden gebruiken

6.1

Know the main folders

Every RHEL system uses the same folder layout (the File-system Hierarchy Standard). Learn it once and you find things on every server.

FolderWhat is in it
/The root of the tree. Everything starts here.
/etcSystem configuration files (text). Back up this folder!
/homeThe home folders of normal users (/home/anna)
/rootThe home folder of the user root
/usrInstalled programs, libraries and docs. /usr/bin = commands, /usr/sbin = admin commands
/varData that changes: logs (/var/log), web sites (/var/www), databases, mail, caches
/tmpTemporary files for everybody. Files older than 10 days are cleaned up.
/runRuntime data since the last boot (PID files, sockets). Empty after a reboot.
/bootThe kernel, the initramfs and the boot loader files
/devDevice files: disks (/dev/vda, /dev/sda), terminals, /dev/null
/proc, /sysVirtual files made by the kernel: processes, hardware, kernel settings
/optExtra software from other vendors
/srvData served by this system (FTP, web), if you choose to put it here
ls /
afs  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
ls -ld /bin /sbin /lib
lrwxrwxrwx. 1 root root 7 Jun 24  2024 /bin -> usr/bin
lrwxrwxrwx. 1 root root 8 Jun 24  2024 /sbin -> usr/sbin
lrwxrwxrwx. 1 root root 7 Jun 24  2024 /lib -> usr/lib

Onthoud

/bin, /sbin and /lib are only links to folders in /usr. All programs live in /usr.

Op het werk

When a disk is full, look first in /var (logs, caches) and /home. du -sh /var/* | sort -h shows the biggest folders.

Commando's in deze les

6.2

Use absolute and relative paths

An absolute path starts with / and works from anywhere. A relative path starts from the folder you are in now.

pwd
/home/student
ls /etc/ssh/sshd_config
ls Documents/report.txt
ls ./Documents/report.txt
ls ../anna
ls ~/Documents
ls ~anna
SignMeaning
/ at the startThe root: an absolute path
.This folder
..The folder above (the parent)
~My home folder
~annaThe home folder of the user anna

Onthoud

In a script or a cron job, always use absolute paths. A script does not know which folder it starts in.

Commando's in deze les

6.3

Move between folders

cd changes the current folder. pwd prints it.

cd /var/log
pwd
/var/log
cd ..
pwd
/var
cd
pwd
/home/student
cd -
/var
cd ~/Documents
CommandWhere you go
cd /pathTo that folder
cd ..One level up
cd or cd ~Home
cd -Back to the folder before

Commando's in deze les

6.4

List the content of a folder

ls shows files. With options it shows sizes, owners, rights, hidden files and dates.

ls
ls -l
ls -la
ls -lh /var/log
ls -ltr /var/log
ls -ld /etc
ls -R /etc/sysconfig | head
OptionWhat it shows
-lLong list: type, rights, links, owner, group, size, date, name
-aAlso hidden files (names that start with .)
-hSizes like 4.0K, 12M (with -l)
-t / -rSort by time / reverse the order
-dThe folder itself, not what is inside
-RGo into sub-folders too
-ZThe SELinux context
-rw-r--r--. 1 root root  3667 Oct 20 10:12 sshd_config
drwxr-xr-x. 2 root root  4096 Oct 20 10:12 sshd_config.d

The first letter is the type: - file, d folder, l link. The rest is explained in Control access to files.

6.5

Use wildcards to pick many files

The shell turns wildcard patterns into a list of file names before the command runs (this is called globbing).

PatternMatches
*Any text, also nothing
?Exactly one character
[abc] / [0-9]One of these characters / one digit
[!0-9]One character that is not a digit
{a,b,c}Makes several words (brace expansion), files do not need to exist
ls /etc/*.conf
ls /var/log/messages-*
ls file?.txt
ls report[0-9][0-9].pdf
mkdir -p project/{src,docs,tests}
touch log{1..5}.txt
echo /etc/sys*

Let op

rm * in the wrong folder deletes everything there. Run ls PATTERN first to see what it matches, then use the same pattern with rm.

6.6

Understand tilde, variables and command substitution

Before a command runs, the shell also replaces ~, $VARIABLE and $(command) with their values.

echo ~
/home/student
echo $HOME $USER
/home/student student
echo "Today is $(date +%A)"
Today is Monday
tar czf /tmp/etc-$(date +%F).tar.gz /etc
echo '$HOME is not changed in single quotes'
echo "\$HOME is not changed here either"
QuotingEffect
"double"Keeps spaces together, but $VAR and $(cmd) still work
'single'Everything stays exactly as written
\Protects the next character only

More examples: Variables in the shell.

Oefenen

Alle commando's in dit hoofdstuk