Advanced
Searching inSummaries
How to search
  • Words find lesson titles, text and code. Filter by type (guides, courses, programs, books) or stay in this book.
  • book:rhcsa and ch:8 narrow the search; #code finds a word only in commands of the lessons.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

Chapter 3Name in the book: Exploring the System

Look around the system

Now that you can move around, it is time to look. This chapter uses more options of ls, reads the long listing, finds out what kind of file something is with file, reads text with less, and takes a tour of the most important system directories. It ends with links: symbolic and hard.

  • 9 Lessons
  • 7 Commands
  • 1 Labs

$ run as a normal user# run as root (or with sudo)

3.1

Use options and arguments

Most commands look like this: command -options arguments. Options change how the command works; arguments say what it works on.

ls -lt
ls -lt --reverse
ls -lh /var/log

Commands in this lesson

3.2

Know the most useful ls options

A few options of ls are used every day.

OptionLong formWhat it does
-a--allAlso show hidden files (names with a dot)
-A--almost-allLike -a, but without . and ..
-d--directoryShow the directory itself, not its contents (use with -l)
-F--classifyAdd a sign: / for a directory, * for a program
-h--human-readableSizes as K, M, G (with -l)
-lLong format: one file per line with details
-r--reverseReverse the order
-SSort by size
-tSort by time of the last change
ls -ld /etc
drwxr-xr-x. 142 root root 8192 Nov  8 03:10 /etc
ls -lS /usr/bin | head -4

3.3

Read the long format

Each line of ls -l has the same columns: type and rights, links, owner, group, size, date, name.

ls -l report.txt
-rw-r--r--. 1 me me 3576 Nov  6 10:15 report.txt
ColumnExampleMeaning
1-rw-r--r--Type (- file, d directory, l link) + access rights
21Number of hard links
3meOwner of the file
4meGroup of the file
53576Size in bytes
6Nov 6 10:15Date and time of the last change
7report.txtName

The rights are explained in Permissions and users.

Commands in this lesson

3.4

Find out the file type with file

The name does not say what a file really is. file looks inside and tells you.

file picture.jpg
picture.jpg: JPEG image data, JFIF standard 1.01
file /bin/ls
/bin/ls: ELF 64-bit LSB pie executable, x86-64, dynamically linked
file /etc/passwd
/etc/passwd: ASCII text

Remember

"Everything is a file" in Unix. Pictures, programs, devices and settings are all files. Many of them are plain text you can read.

Commands in this lesson

3.5

Read text files with less

less shows a text file one screen at a time. You can scroll and search. Press q to quit.

less /etc/passwd
KeyAction
Page Up / bOne page back
Page Down / SpaceOne page forward
Up / DownOne line
GGo to the end
g or 1GGo to the start
/textSearch forward for "text"
nNext match
hHelp
qQuit
  • Text means plain characters (ASCII or UTF-8): settings files, scripts and logs are text. Word files are not plain text.
  • less is a better version of the old program more ("less is more"): it can also go back.

3.6

Take a tour of the system directories

Linux follows the Filesystem Hierarchy Standard (FHS). The same folders have the same job on almost every distribution.

DirectoryWhat is in it
/The root of the tree
/bin, /sbinPrograms; on new systems links to /usr/bin and /usr/sbin
/bootThe kernel and the boot loader files
/devDevice files (disks, terminals …)
/etcSettings of the whole system, all plain text
/homeOne home directory per user
/lib, /lib64Shared libraries; on new systems links into /usr
/lost+foundPieces saved by a disk check after a crash
/media, /mntMount points for USB sticks, DVDs and other disks
/optExtra software, often from vendors
/proc, /sysVirtual files: live information from the kernel
/rootHome directory of the superuser
/runRuntime data since the last boot
/tmpTemporary files, often emptied at reboot
/usrPrograms, libraries and data of the system; /usr/local for your own installs
/varData that changes: logs in /var/log, mail, databases, caches
cat /proc/cpuinfo | head -5
ls /etc | wc -l
less /etc/os-release

At work

When something goes wrong on a server, look in /var/log first. Settings are in /etc.

3.9

Summary of the chapter

ls -l shows details, file shows the type, less reads text, and the FHS tells you where things live.

1Which command shows the details of the directory /etc itself (not what is inside)?
2Where are the settings of the whole system?

In /etc. They are plain text files.

3How do you search for the word "root" inside less?

Type /root and press Enter; n goes to the next match.

Practice

All commands in this chapter