0% found this document useful (0 votes)
102 views

Linux Fundamentals: Chapter 3: The Command Line

This document outlines lessons about using the Linux command line, including: - Using man pages to get help on commands, configuration files, daemons and more - Navigating directories with commands like pwd, cd, ls - Getting information on files and folders with commands such as ls, mkdir, rmdir

Uploaded by

dyake04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

Linux Fundamentals: Chapter 3: The Command Line

This document outlines lessons about using the Linux command line, including: - Using man pages to get help on commands, configuration files, daemons and more - Navigating directories with commands like pwd, cd, ls - Getting information on files and folders with commands such as ls, mkdir, rmdir

Uploaded by

dyake04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 126

LINUX

FUNDAMENTALS

Chapter 3: THE COMMAND LINE


COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• man Pages
• Working with Directories
• Working with Files
• Working with File Contents
• The Linux File Tree
COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• man pages
 man $command
 man $configfile
 man $daemon
 man -k (apropos)
 whatis
 whereis
 man sections
 man $section $file
 man man
 mandb
Chapter 3: THE COMMAND LINE
 man Pages
o man $command

 Type man followed by a command (for which you want help) and start
reading. Press q to quit the manpage
 Some man pages contain examples (near the end).
root@gkcollege:~$ man whois
Reformatting whois(1), please wait...

o man $configfile

 Most configuration files have their own manual


root@gkcollege:~$ man syslog.conf
Reformatting syslog.conf(5), please wait...
Chapter 3: THE COMMAND LINE
 man Pages
o man -k (apropos)

 man -k (or apropos) shows a list of man pages containing a string


root@gkcollege:~$ man -k syslog
Reformatting syslogd(8), please wait...
lm-syslog-setup (8) - configure laptop mode to switch syslog.conf ...
logger (1) - a shell command interface to the syslog(3) ...
syslog-facility (8) - Setup and remove LOCALx facility for sysklogd
syslog.conf (5) - syslogd(8) configuration file
syslogd (8) - Linux system logging utilities.
syslogd-listfiles (8) - list system logfiles
Chapter 3: THE COMMAND LINE
 man Pages
o whatis

 To see the description of a manual page, use whatis + string


root@gkcollege:~$ whatis route
route (8) - show / manipulate the IP routing table

o whereis

 The location of a manpage can be revealed with whereis


root@gkcollege:~$ whereis -m whois
whois: /usr/share/man/man1/whois.1.gz
This file is directly readable by man.
root@laika:~$ man /usr/share/man/man1/whois.1.gz
Chapter 3: THE COMMAND LINE
 man Pages
o man $daemon
 This is also true for most daemons (background programs) on your system
root@gkcollege:~$ man syslogd
Reformatting syslogd(8), please wait...

o man $section $file

 When referring to the man page of the passwd command, you will see it
written as passwd(1)
 When referring to the passwd file, you will see it written as passwd(5)
[root@gkcollege ~]$ man passwd # opens the first manual found
[root@gkcollege ~]$ man 5 passwd # opens a page from section 5
Chapter 3: THE COMMAND LINE
 man Pages
o man man

 To know more about man, then Read The Fantastic Manual (RTFM)
 Unfortunately, manual pages do not have the answer to everything
root@gkcollege:~$ man woman
No manual entry for woman
Chapter 3: THE COMMAND LINE
 man Pages
o mandb

 Should you be convinced that a man page exists, but you can't access it,
then try running mandb on Debian/Mint
root@gkcollege:~$ whatis route
route (8) - show / manipulate the IP routing table
root@gkcollege:~$ mandb
man subdirectories contained newer manual pages
manual pages were added
stray cats were added
old database entries were purged
Chapter 3: THE COMMAND LINE
 man Pages
o mandb

 Or run makewhatis on CentOS/Redhat


[root@gkcollege ~]# apropos scsi
scsi: nothing appropriate
[root@gkcollege ~]# makewhatis
[root@gkcollege ~]# apropos scsi
hpsa (4) - HP Smart Array SCSI driver
lsscsi (8) - list SCSI devices (or hosts) and their attributes
sd (4) - Driver for SCSI Disk Drives
st (4) - SCSI tape device
COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• Working with Directories
 pwd
 cd
 absolute and relative paths
 path completion
 ls
 mkdir
 rmdir
Chapter 3: THE COMMAND LINE
 Working with Directories
o pwd

 The “you are here” sign can be displayed with the pwd command
 Print Working Directory
root@gkcollege:~$ pwd
/root
Chapter 3: THE COMMAND LINE
 Working with Directories
o cd ~

 Change your current directory with the cd command (Change Directory)


root@gkcollege$ cd /etc
root@gkcollege$ pwd
/etc
root@gkcollege$ cd /bin
root@gkcollege$ pwd
/bin
root@gkcollege$ cd /home/user1/
root@gkcollege$ pwd
/home/user1
Chapter 3: THE COMMAND LINE
 Working with Directories
o cd ~

 The cd is also a shortcut to get back into your home directory


 Type cd without a target directory, will put you in your home directory
 Type cd ~ has the same effect.
root@gkcollege$ cd /etc
root@gkcollege$ pwd
/etc
root@gkcollege$ cd
root@gkcollege$ pwd
/home/user1
root@gkcollege$ cd ~
root@gkcollege$ pwd
/home/user1
Chapter 3: THE COMMAND LINE
 Working with Directories
o cd ..

 To go to the parent directory (the one just above your current directory
in the directory tree), type cd ..
root@gkcollege$ pwd
/usr/share/games
root@gkcollege$ cd ..
root@gkcollege$ pwd
/usr/share

 To stay in the current directory, type cd


 We will see useful use of the “.” character representing the current
directory
Chapter 3: THE COMMAND LINE
 Working with Directories
o cd -
 Just type cd - to go to the previous directory
root@gkcollege$ pwd
/home/root
root@gkcollege$ cd /etc
root@gkcollege$ pwd
/etc
root@gkcollege$ cd -
/home/root
root@gkcollege$ cd -
/etc
Chapter 3: THE COMMAND LINE
 Working with Directories
o absolute and relative paths
 Type a path starting with a slash (/), then the root of the file tree is
assumed
root@gkcollege$ pwd
/home/root
root@gkcollege$ cd home
bash: cd: home: No such file or directory
root@gkcollege$ cd /home
root@gkcollege$ pwd
/home
Chapter 3: THE COMMAND LINE
 Working with Directories
o absolute and relative paths
 When inside /home, you have to type cd root instead of cd /root to
enter the subdirectory root of the current directory /home
root@gkcollege$ pwd
/home
root@gkcollege$ cd /root
bash: cd: /user1: No such file or directory
root@gkcollege$ cd root
root@gkcollege$ pwd
/home/root
Chapter 3: THE COMMAND LINE
 Working with Directories
o absolute and relative paths
 In case your current directory is the root directory /, then both cd /home
and cd home will get you in the /home directory
root@gkcollege$ pwd
/
root@gkcollege$ cd home
root@gkcollege$ pwd
/home
root@gkcollege$ cd /
root@gkcollege$ cd /home
root@gkcollege$ pwd
/home
Chapter 3: THE COMMAND LINE
 Working with Directories
o path completion
 The tab key can help you in typing a path without errors
 Type cd /et followed by the tab key will expand the command line to cd
/etc/
 When typing cd /Et followed by the tab key, nothing will happen
because you typed the wrong path (upper case E)
 You need fewer key strokes and you will be sure your typed path is
correct when using the tab key
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls

 You can list the contents of a directory with ls


root@gkcollege:~$ ls
allfiles.txt dmesg.txt services stuff summer.txt
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls -a
 A frequently used option with ls is -a to show all files
 Showing all files means including the hidden files
 When a file name on a Linux file system starts with a dot (.), it is
considered a hidden file and it doesn't show up in regular file listings
root@gkcollege:~$ ls
allfiles.txt dmesg.txt services stuff summer.txt
root@gkcollege:~$ ls -a
. allfiles.txt .bash_profile dmesg.txt .lesshst stuff
.. .bash_history .bashrc services .ssh summer.txt
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls -l

 Many times you will be using options with ls to display the contents of
the directory in different formats or to display different parts of the
directory
 Typing just ls gives you a list of files in the directory
 Typing ls -l (that is a letter L, not the number 1) gives you a long listing
root@gkcollege:~$ ls -l
total 17296
-rw-r--r-- 1 user1 user1 17584442 Sep 17 00:03 allfiles.txt
-rw-r--r-- 1 user1 user1 96650 Sep 17 00:03 dmesg.txt
-rw-r--r-- 1 user1 user1 19558 Sep 17 00:04 services
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:04 stuff
-rw-r--r-- 1 user1 user1 0 Sep 17 00:04 summer.txt
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls -lh

 Another frequently used ls option is –h


 It shows the numbers (file sizes) in a more human readable format
 Also shown below is some variation in the way you can give the options
to ls
root@gkcollege:~$ ls -l -h
total 17M
-rw-r--r-- 1 user1 user1 17M Sep 17 00:03 allfiles.txt
-rw-r--r-- 1 user1 user1 95K Sep 17 00:03 dmesg.txt
-rw-r--r-- 1 user1 user1 20K Sep 17 00:04 services
drwxr-xr-x 2 user1 user1 4.0K Sep 17 00:04 stuff
-rw-r--r-- 1 user1 user1 0 Sep 17 00:04 summer.txt
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls -lh
root@gkcollege:~$ ls -lh
total 17M
-rw-r--r-- 1 user1 user1 17M Sep 17 00:03 allfiles.txt
-rw-r--r-- 1 user1 user1 95K Sep 17 00:03 dmesg.txt
-rw-r--r-- 1 user1 user1 20K Sep 17 00:04 services
drwxr-xr-x 2 user1 user1 4.0K Sep 17 00:04 stuff
-rw-r--r-- 1 user1 user1 0 Sep 17 00:04 summer.txt

o ls -hl
root@gkcollege:~$ ls -hl
total 17M
-rw-r--r-- 1 user1 user1 17M Sep 17 00:03 allfiles.txt
-rw-r--r-- 1 user1 user1 95K Sep 17 00:03 dmesg.txt
-rw-r--r-- 1 user1 user1 20K Sep 17 00:04 services
drwxr-xr-x 2 user1 user1 4.0K Sep 17 00:04 stuff
-rw-r--r-- 1 user1 user1 0 Sep 17 00:04 summer.txt
Chapter 3: THE COMMAND LINE
 Working with Directories
o ls –l -h
root@gkcollege:~$ ls -h -l
total 17M
-rw-r--r-- 1 user1 user1 17M Sep 17 00:03 allfiles.txt
-rw-r--r-- 1 user1 user1 95K Sep 17 00:03 dmesg.txt
-rw-r--r-- 1 user1 user1 20K Sep 17 00:04 services
drwxr-xr-x 2 user1 user1 4.0K Sep 17 00:04 stuff
-rw-r--r-- 1 user1 user1 0 Sep 17 00:04 summer.txt
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Directories
o mkdir

 Create directories with mkdir


 Give at least one parameter to mkdir, the name of the new directory to
be created
 Think before typing a leading /
Chapter 3: THE COMMAND LINE
 Working with Directories
o mkdir
root@gkcollege:~$ mkdir mydir
root@gkcollege:~$ cd mydir
root@gkcollege:~/mydir$ ls -al
total 8
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:07 .
drwxr-xr-x 48 user1 user1 4096 Sep 17 00:07 ..
root@gkcollege:~/mydir$ mkdir stuff
root@gkcollege:~/mydir$ mkdir otherstuff
root@gkcollege:~/mydir$ ls -l
total 8
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:08 otherstuff
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:08 stuff
root@gkcollege:~/mydir$
Chapter 3: THE COMMAND LINE
 Working with Directories
o mkdir -p

 The following command will fail, because the parent directory of


threedirsdeep does not exist

root@gkcollege:~$ mkdir mydir2/mysubdir2/threedirsdeep


mkdir: cannot create directory ‘mydir2/mysubdir2/threedirsdeep’: No such fi
le or directory
When given the option -p, then mkdir will create parent directories as needed.
root@gkcollege:~$ mkdir -p mydir2/mysubdir2/threedirsdeep
Chapter 3: THE COMMAND LINE
 Working with Directories
o rmdir

 When a directory is empty, you can use rmdir to remove the directory
root@gkcollege:~/mydir$ ls -l
total 8
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:08 otherstuff
drwxr-xr-x 2 user1 user1 4096 Sep 17 00:08 stuff
root@gkcollege:~/mydir$ rmdir otherstuff
root@gkcollege:~/mydir$ cd ..
root@gkcollege:~$ rmdir mydir
rmdir: failed to remove ‘mydir’: Directory not empty
root@gkcollege:~$ rmdir mydir/stuff
root@gkcollege:~$ rmdir mydir
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Directories
o rmdir -p

 recursively remove directories


root@gkcollege:~$ mkdir -p test42/subdir
root@gkcollege:~$ rmdir -p test42/subdir
root@gkcollege:~$
COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• Working with Files
 all files are case sensitive
 everything is a file
 file
 touch
 rm
 cp
 mv
 rename
Chapter 3: THE COMMAND LINE
 Working with Files
o All files are case sensitive

 Files on Linux (or any Unix) are case sensitive


 FILE1 is not = file1, /etc/hosts is not = /etc/Hosts
root@gkcollege:~/Linux$ ls
winter.txt Winter.txt
root@gkcollege:~/Linux$ cat winter.txt
It is cold.
root@gkcollege:~/Linux$ cat Winter.txt
It is very cold!
Chapter 3: THE COMMAND LINE
 Working with Files
o Everything is a file

 A directory is a special kind of file


 It is still a (case sensitive!) file
 Each terminal window (for example /dev/pts/4), any hard disk or
partition (for example /dev/sdb1) and any process are all represented
somewhere in the file system as a file
Chapter 3: THE COMMAND LINE
 Working with Files
o file

 The file utility determines the file type


 Linux does not use extensions to determine the file type
 The command line does not care whether a file ends in .txt or .pdf
 As a SYSAD, use the file command to determine the file type
root@gkcollege:~$ file pic33.png
pic33.png: PNG image data, 3840 x 1200, 8-bit/color RGBA, non-interlaced
root@gkcollege:~$ file /etc/passwd
/etc/passwd: ASCII text
root@gkcollege:~$ file HelloWorld.c
HelloWorld.c: ASCII C program text
Chapter 3: THE COMMAND LINE
 Working with Files
o file

 The file command uses a magic file that contains patterns to recognize
file types
 The magic file is located in /usr/share/file/magic
 Type man 5 magic for more information
 It is interesting to point out file -s for special files like those in /dev
and /proc
Chapter 3: THE COMMAND LINE
 Working with Files
o file

root@gkcollege~# file /dev/sda


/dev/sda: block special
root@gkcollege~# file -s /dev/sda
/dev/sda: x86 boot sector; partition 1: ID=0x83, active, starthead...
root@gkcollege~# file /proc/cpuinfo
/proc/cpuinfo: empty
root@gkcollege~# file -s /proc/cpuinfo
/proc/cpuinfo: ASCII C++ program text
Chapter 3: THE COMMAND LINE
 Working with Files
o touch

 Create an empty file using touch


 Starting with an empty directory, create two files with touch and lists
those files
root@gkcollege:~$ ls -l
total 0
root@gkcollege:~$ touch file42
root@gkcollege:~$ touch file33
root@gkcollege:~$ ls -l
total 0
-rw-r--r-- 1 user1 user1 0 Oct 15 08:57 file33
-rw-r--r-- 1 user1 user1 0 Oct 15 08:56 file42
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o touch -t

 Set the timestamp when creating an empty file


root@gkcollege:~$ touch -t 200505050000 SinkoDeMayo
root@gkcollege:~$ touch -t 130207111630 BigBattle.txt
root@gkcollege:~$ ls -l
total 0
-rw-r--r-- 1 user1 user1 0 Jul 11 1302 BigBattle.txt
-rw-r--r-- 1 user1 user1 0 Oct 15 08:57 file33
-rw-r--r-- 1 user1 user1 0 Oct 15 08:56 file42
-rw-r--r-- 1 user1 user1 0 May 5 2005 SinkoDeMayo
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o rm

 Use rm to remove or delete a file


 When you remove or delete a file, the file is gone forever
 Be careful when removing files!
root@gkcollege:~$ ls
BigBattle.txt file33 file42 SinkoDeMayo
root@gkcollege:~$ rm BigBattle.txt
root@gkcollege:~$ ls
file33 file42 SinkoDeMayo
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o rm -i

 Prevent accidental removal of a file


root@gkcollege:~$ ls
file33 file42 SinkoDeMayo
root@gkcollege:~$ rm -i file33
rm: remove regular empty file `file33'? yes
root@gkcollege:~$ rm -i SinkoDeMayo
rm: remove regular empty file `SinkoDeMayo'? n
root@gkcollege:~$ ls
file42 SinkoDeMayo
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o rm -rf

 By default, rm -r will not remove non-empty directories


 rm accepts several options that will allow you to remove any directory
 The rm -rf statement is famous because it will erase anything
(providing that you have the permissions to do so)
 When you are logged on as root, BE VERY CAREFUL with rm -rf
 the f means force and the r means recursive, since being root implies
that permissions don't apply to you
 You can literally erase your entire file system by accident
Chapter 3: THE COMMAND LINE
 Working with Files
o rm -rf
root@gkcollege:~$ mkdir test
root@gkcollege:~$ rm test
rm: cannot remove `test': Is a directory
root@gkcollege:~$ rm -rf test
root@gkcollege:~$ ls test
ls: cannot access test: No such file or directory
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o cp

 To copy a file, use cp with a source and a target argument


root@gkcollege:~$ ls
file42 SinkoDeMayo
root@gkcollege:~$ cp file42 file42.copy
root@gkcollege:~$ ls
file42 file42.copy SinkoDeMayo

 To copy to another directory


root@gkcollege:~$ mkdir dir42
root@gkcollege:~$ cp SinkoDeMayo dir42
root@gkcollege:~$ ls dir42/
SinkoDeMayo
Chapter 3: THE COMMAND LINE
 Working with Files
o cp

 To copy multiple files into a directory


 The last argument (a.k.a. the target) must be a directory
root@gkcollege:~$ cp file42 file42.copy SinkoDeMayo dir42/
root@gkcollege:~$ ls dir42/
file42 file42.copy SinkoDeMayo
Chapter 3: THE COMMAND LINE
 Working with Files
o cp -r

 To copy complete directories, use cp -r (the -r option forces recursive


copying of all files in all subdirectories)
root@gkcollege:~$ ls
dir42 file42 file42.copy SinkoDeMayo
root@gkcollege:~$ cp -r dir42/ dir33
root@gkcollege:~$ ls
dir33 dir42 file42 file42.copy SinkoDeMayo
root@gkcollege:~$ ls dir33/
SinkoDeMayo
Chapter 3: THE COMMAND LINE
 Working with Files
o cp -i

 To prevent cp from overwriting existing files, use the -i (for interactive)


option
root@gkcollege:~$ cp SinkoDeMayo file42
root@gkcollege:~$ cp SinkoDeMayo file42
root@gkcollege:~$ cp -i SinkoDeMayo file42
cp: overwrite `file42'? n
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o mv

 rename files with mv


o Use mv to rename a file or to move the file to another directory
o When you need to rename only one file then mv is the preferred
command to use
root@gkcollege:~$ ls
dir33 dir42 file42 file42.copy SinkoDeMayo
root@gkcollege:~$ mv file42 file33
root@gkcollege:~$ ls
dir33 dir42 file33 file42.copy SinkoDeMayo
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o mv

 rename directories with mv


- The same mv command can be used to rename directories
root@gkcollege:~$ ls -l
total 8
drwxr-xr-x 2 root root 4096 Oct 15 09:36 dir33
drwxr-xr-x 2 root root 4096 Oct 15 09:36 dir42
root@gkcollege:~$ mv dir33 backup
root@gkcollege:~$ ls -l
total 8
drwxr-xr-x 2 root root 4096 Oct 15 09:36 backup
drwxr-xr-x 2 root root 4096 Oct 15 09:36 dir42
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o mv -i

 The command mv also has a -i switch similar to cp and rm


root@gkcollege:~$ mv -i file33 SinkoDeMayo
mv: overwrite `SinkoDeMayo'? no
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with Files
o About rename

 The rename command is one of the rare occasions where the Linux
Fundamentals books has to make a distinction between Linux
distributions
 Almost every command in the Fundamentals part of this book works on
almost every Linux computer
 But rename is different
 Use mv whenever you need to rename only a couple of files
Chapter 3: THE COMMAND LINE
 Working with Files
o rename on Debian/Ubuntu

 The rename command on Debian uses regular expressions (regular


expression or shor regex are explained in a later chapter) to rename
many files at once
 Below a rename example that switches all occurrences of txt to png for all
file names ending in .txt.
root@gkcollege:~/test42$ ls
abc.txt file33.txt file42.txt
root@gkcollege:~/test42$ rename 's/\.txt/\.png/' *.txt
root@gkcollege:~/test42$ ls
abc.png file33.png file42.png
Chapter 3: THE COMMAND LINE
 Working with Files
o rename on Debian/Ubuntu

 This second example switches all (first) occurrences of file into


document for all file names ending in .png.
root@gkcollege:~/test42$ ls
abc.png file33.png file42.png
root@gkcollege:~/test42$ rename 's/file/document/' *.png
root@gkcollege:~/test42$ ls
abc.png document33.png document42.png
root@gkcollege:~/test42$
Chapter 3: THE COMMAND LINE
 Working with Files
o rename on CentOS/RHEL/Fedora

 On Red Hat Enterprise Linux, the syntax of rename is a bit different


 The first example below renames all *.conf files replacing any
occurrence of .conf with .backup.
[root@centos7 ~]$ touch one.conf two.conf three.conf
[root@centos7 ~]$ rename .conf .backup *.conf
[root@centos7 ~]$ ls
one.backup three.backup two.backup
[root@centos7 ~]$
Chapter 3: THE COMMAND LINE
 Working with Files
o rename on CentOS/RHEL/Fedora

 The second example renames all (*) files replacing one with ONE
[root@centos7 ~]$ ls
one.backup three.backup two.backup
[root@centos7 ~]$ rename one ONE *
[root@centos7 ~]$ ls
ONE.backup three.backup two.backup
[root@centos7 ~]$
COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• Working with File Contents
 head
 tail
 cat
 tac
 more and less
 strings
Chapter 3: THE COMMAND LINE
 Working with File Contents
o head

 use head to display the first ten lines of a file


root@gkcollege~$ head /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
root@gkcollege~#
Chapter 3: THE COMMAND LINE
 Working with File Contents
o head

 use head to display the first n lines of a file


root@gkcollege~$ head -4 /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
root@gkcollege~$

 use head to display the first n bytes


root@gkcollege~$ head -c14 /etc/passwd
root:x:0:0:rooroot@gkcollege~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o tail

 Similar to head, the tail command will display the last ten lines of a file
root@gkcollege~$ tail /etc/services
vboxd 20012/udp
binkp 24554/tcp # binkp fidonet protocol
asp 27374/tcp # Address Search Protocol
asp 27374/udp
csync2 30865/tcp # cluster synchronization tool
dircproxy 57000/tcp # Detachable IRC Proxy
tfido 60177/tcp # fidonet EMSI over telnet
fido 60179/tcp # fidonet EMSI over TCP
# Local services
root@gkcollege~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o tail

 You can give tail the number of lines you want to see
root@gkcollege~$ tail -3 /etc/services
fido 60179/tcp # fidonet EMSI over TCP
# Local services
root@gkcollege~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat

 one of the most universal tools


 yet all it does is copy standard input to standard output
 In combination with the shell this can be very powerful and diverse
 Use cat to display a file on the screen
 If the file is longer than the screen, it will scroll to the end
root@gkcollege:~$ cat /etc/resolv.conf
domain linux-training.be
search linux-training.be
nameserver 192.168.1.42
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat

 The command cat is short for concatenate


 One of the basic uses of cat is to concatenate files into a bigger (or
complete) file
root@gkcollege:~$ echo one >part1
root@gkcollege:~$ echo two >part2
root@gkcollege:~$ echo three >part3
root@gkcollege:~$ cat part1
one
root@gkcollege:~$ cat part2
two
root@gkcollege:~$ cat part3
three
root@gkcollege:~$ cat part1 part2 part3
Chapter 3: THE COMMAND LINE
 Working with File Contents
o concatenate
one
one
two
three
root@gkcollege:~$ cat part1 part2 part3 >all
root@gkcollege:~$ cat all
one
two
three
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat

 Create files
 Use cat to create flat text files
 Type cat > winter.txt
 Then type one or more lines, finishing each line with the enter key. After
the last line, type and hold the Control (Ctrl) key and press d
 The Ctrl + d key combination will send an EOF (End of File) to the
running process ending the cat command
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat
root@gkcollege:~$ cat > winter.txt
It is very cold today!
root@gkcollege:~$ cat winter.txt
It is very cold today!
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat

 custom end marker


 You can choose an end marker for cat with << as is shown in this
screenshot
 This construction is called a here directive and will end the cat command
root@gkcollege:~$ cat > hot.txt <<stop
> It is hot today!
> Yes it is summer.
> stop
root@gkcollege:~$ cat hot.txt
It is hot today!
Yes it is summer.
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o cat

 Copy files
root@gkcollege:~$ cat winter.txt
It is very cold today!
root@gkcollege:~$ cat winter.txt > cold.txt
root@gkcollege:~$ cat cold.txt
It is very cold today!
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 Working with File Contents
o tac

 Executes cat backwards


root@gkcollege:~$ cat count
one
two
three
four
root@gkcollege:~$ tac count
four
three
two
one
Chapter 3: THE COMMAND LINE
 Working with File Contents
o more and less

 The more command is useful for displaying files that take up more than
one screen
 more will allow you to see the contents of the file page by page
 Use the space bar to see the next page, or q to quit
 Some people prefer the less command to more
Chapter 3: THE COMMAND LINE
 Working with File Contents
o strings

 The strings command can display readable ascii strings found in (binary)
files
 locates the ls binary then display readable strings in the binary file
(output is truncated)
root@gkcollege:~$ which ls
/bin/ls
root@gkcollege:~$ strings /bin/ls
/lib/ld-linux.so.2
librt.so.1
__gmon_start__
_Jv_RegisterClasses
clock_gettime
libacl.so.1
...
COURSE OUTLINE
Chapter 3: THE COMMAND LINE

Lessons
• The Linux File Tree
 filesystem hierarchy standard
 man hier
 the root directory / binary directories
 configuration directories
 data directories
 in memory directories 109
 /usr Unix System Resources
 /var variable data
Chapter 3: THE COMMAND LINE
 filesystem hierarchy standard
o Many Linux distributions partially follow the Filesystem Hierarchy Standard
o The FHS may help make more Unix/Linux file system trees conform better in
the future
o The FHS is available online at http://www.pathname.com/fhs/ :

"The filesystem hierarchy standard has been designed to be used by Unix


distribution developers, package developers, and system implementers.
However, it is primarily intended to be a reference and is not a tutorial on
how to manage a Unix filesystem or directory hierarchy."
Chapter 3: THE COMMAND LINE
 man hier
o There are some differences in the filesystems between Linux distributions
o Enter man hier to find information about the file system hierarchy
o This manual will explain the directory structure on your machine
Chapter 3: THE COMMAND LINE
 the root directory / binary directories
o All Linux systems have a directory structure that starts at the root directory
o The root directory is represented by a forward slash, like this: /
o Everything that exists on a Linux system can be found below this root (/)
directory

[root@gkcollege ~]$ ls /
bin dev home media mnt proc sbin srv tftpboot usr
boot etc lib misc opt root selinux sys tmp var
Chapter 3: THE COMMAND LINE
 the root directory / binary directories
o binary directories

 Binaries are files that contain compiled source code (or machine code)
 Binaries can be executed on the computer
 Sometimes binaries are called executables
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o bin

 The /bin directory contains binaries for use by all users


 According to the FHS the /bin directory should contain /bin/cat and /bin/date
(among others)
 you see common Unix/Linux commands like cat, cp, cpio, date, dd, echo, grep, and
so on
Chapter 3: THE COMMAND LINE
 the root directory / binary directories
root@gkcollege:~$ ls /bin
archdetect egrep mt setupcon
autopartition false mt-gnu sh
bash fgconsole mv sh.distrib
bunzip2 fgrep nano sleep
bzcat fuser nc stralign
bzcmp fusermount nc.traditional stty
bzdiff get_mountoptions netcat su
bzegrep grep netstat sync
bzexe gunzip ntfs-3g sysfs
bzfgrep gzexe ntfs-3g.probe tailf
bzgrep gzip parted_devices tar
bzip2 hostname parted_server tempfile
bzip2recover hw-detect partman touch
bzless ip partman-commit true
bzmore kbd_mode perform_recipe ulockmgr
cat kill pidof umount
...
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o Other bin directories

 You can find a /bin subdirectory in many other directories


 A user named serena could put her own programs in /home/serena/bin
 Some applications, often when installed directly from source will put themselves in
/opt
 A samba server installation can use /opt/samba/bin to store its binaries
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o /sbin

 /sbin contains binaries to configure the operating system


 Many of the system binaries require root privilege to perform certain tasks
 Below a screenshot containing system binaries to change the ip address, partition a
disk and create an ext4 file system

root@ubu1010:~$ ls -l /sbin/ifconfig /sbin/fdisk /sbin/mkfs.ext4


-rwxr-xr-x 1 root root 97172 2011-02-02 09:56 /sbin/fdisk
-rwxr-xr-x 1 root root 65708 2010-07-02 09:27 /sbin/ifconfig
-rwxr-xr-x 5 root root 55140 2010-08-18 18:01 /sbin/mkfs.ext4
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o /lib

 Binaries found in /bin and /sbin often use shared libraries located in /lib. Below is a
sample of the partial contents of /lib

root@gkcollege:~$ ls /lib/libc*
/lib/libc-2.5.so /lib/libcfont.so.0.0.0 /lib/libcom_err.so.2.1
/lib/libcap.so.1 /lib/libcidn-2.5.so /lib/libconsole.so.0
/lib/libcap.so.1.10 /lib/libcidn.so.1 /lib/libconsole.so.0.0.0
/lib/libcfont.so.0 /lib/libcom_err.so.2 /lib/libcrypt-2.5.so
/lib/modules

 Typically, the Linux kernel loads kernel modules from


/lib/modules/$kernel-version/
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o /lib
 /lib32 and /lib64

- We currently are in a transition between 32-bit and 64-bit systems


- Therefore, you may encounter directories named /lib32 and /lib64 which
clarify the register size used during compilation time of the libraries
- A 64-bit computer may have some 32-bit binaries and libraries for compatibility
with legacy applications
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o /lib

 /lib32 and /lib64

root@gkcollege:~$ file /lib32/libc-2.5.so


/lib32/libc-2.5.so: ELF 32-bit LSB shared object, Intel 80386, \
version 1 (SYSV), for GNU/Linux 2.6.0, stripped
root@gkcollege:~$ file /lib64/libcap.so.1.10
/lib64/libcap.so.1.10: ELF 64-bit LSB shared object, AMD x86-64, \
version 1 (SYSV), stripped

 The ELF (Executable and Linkable Format) is used in almost every Unix-like operating
system since System V
Chapter 3: THE COMMAND LINE
 the root directory / binary directories

o /opt
 The purpose of /opt is to store optional software
 In many cases this is software from outside the distribution repository
 You may find an empty /opt directory on many systems
 A large package can install all its files in /bin, /lib, /etc subdirectories within
/opt/$packagename/
 If for example the package is called wp, then it installs in /opt/wp, putting binaries in
/opt/wp/bin and manpages in /opt/wp/man
Chapter 3: THE COMMAND LINE
 configuration directories

o /boot
 The /boot directory contains all files needed to boot the computer
 On Linux systems you typically find the /boot/grub directory here
 /boot/grub contains /boot/grub/grub.cfg (older systems may still have
/boot/grub/grub.conf) which defines the boot menu that is displayed before the
kernel starts
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc

 All of the machine-specific configuration files should be located in /etc


 Historically /etc = etcetera
 Nowadays, /etc = Editable Text Configuration
 Usually, the name of a configuration file is the same as the application, daemon, or
protocol with .conf added as the extension
 There is much more to be found in /etc
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc
root@gkcollege:~$ ls /etc/*.conf
/etc/adduser.conf /etc/ld.so.conf /etc/scrollkeeper.conf
/etc/brltty.conf /etc/lftp.conf /etc/sysctl.conf
/etc/ccertificates.conf /etc/libao.conf /etc/syslog.conf
/etc/cvs-cron.conf /etc/logrotate.conf /etc/ucf.conf
/etc/ddclient.conf /etc/ltrace.conf /etc/uniconf.conf
/etc/debconf.conf /etc/mke2fs.conf /etc/updatedb.conf
/etc/deluser.conf /etc/netscsid.conf /etc/usplash.conf
/etc/fdmount.conf /etc/nsswitch.conf /etc/uswsusp.conf
/etc/hdparm.conf /etc/pam.conf /etc/vnc.conf
/etc/host.conf /etc/pnm2ppa.conf /etc/wodim.conf
/etc/inetd.conf /etc/povray.conf /etc/wvdial.conf
/etc/kernel-img.conf /etc/resolv.conf
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc

 /etc/init.d/

- Directory that contains scripts to start and stop daemons


- This directory COULD disappear as Linux migrates to systems that replace the old
init way of starting all daemons

 /etc/X11/

- Graphical display (aka X Window System or just X) from the X.org foundation
- The configuration file for your graphical display is /etc/X11/xorg.conf
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc
 /etc/skel/

- The skeleton directory /etc/skel is copied to the home directory of a newly


created user
- It usually contains hidden files like a .bashrc script

 /etc/sysconfig/

- This directory, not mentioned in the FHS, contains a lot of RHEL config files
- The example below is the /etc/sysconfig directory from RHELv4u4 with
everything installed
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc
root@gkcollege:~$ ls /etc/sysconfig/
apmd firstboot irda network saslauthd
apm-scripts grub irqbalance networking selinux
authconfig hidd keyboard ntpd spamassassin
autofs httpd kudzu openib.conf squid
bluetooth hwconf lm_sensors pand syslog
clock i18n mouse pcmcia sys-config-sec
console init mouse.B pgsql sys-config-users
crond installinfo named prelink sys-logviewer
desktop ipmi netdump rawdevices tux
diskdump iptables netdump_id_dsa rhn vncservers
dund iptables-cfg netdump_id_dsa.p samba xinetd
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc

 /etc/sysconfig/

- The file /etc/sysconfig/firstboot tells the Red Hat Setup Agent not to run at
boot time
- To run the Red Hat Setup Agent at the next reboot, simply remove this file, and
run chkconfig --level 5 firstboot on
- The Red Hat Setup Agent allows installation of the latest updates, create a user
account, join the Red Hat Network and more
- It will then create the /etc/sysconfig/firstboot file again
root@gkcollege:~$ cat /etc/sysconfig/firstboot
RUN_FIRSTBOOT=NO
Chapter 3: THE COMMAND LINE
 configuration directories

o /etc

 /etc/sysconfig/

- The /etc/sysconfig/harddisks file contains some parameters to tune the hard


disks
- You can see hardware detected by kudzu in /etc/sysconfig/hwconf
- Kudzu is software from Red Hat for automatic discovery and configuration of
hardware
- The keyboard type and keymap table are set in the /etc/sysconfig/keyboard
file
- Check the manual pages of keymaps(5), dumpkeys(1), loadkeys(1) and the
directory /lib/kbd/keymaps/
Chapter 3: THE COMMAND LINE
 data directories
o /home

 Users can store personal or project data under /home


 It is common (but not mandatory by the FHS) practice to name the users
home directory after the user name in the format /home/$USERNAME

root@gkcollege:~$ ls /home

 also serves as a location to store the user profile


root@gkcollege:~$ ls -d /home/root/.*.
Chapter 3: THE COMMAND LINE
 data directories
o /root

 default location for personal data and profile of the root user
 If it does not exist by default, then some administrators create it

o /srv

 Use /srv for data that is served by your system


 The FHS allows locating cvs, rsync, ftp and www data in this location. The
FHS also approves administrative naming in /
 srv, like /srv/project55/ftp and /srv/sales/www
 On Sun Solaris (or Oracle Solaris) /export is used for this purpose
Chapter 3: THE COMMAND LINE
 data directories
o /media

 The /media directory serves as a mount point for removable media


devices such as CDROM's, digital cameras, and various usb-attached
devices
 Since /media is rather new in the Unix world, you could very well
encounter systems running without this directory
 Solaris 9 does not have it, Solaris 10 does
 Most Linux distributions today mount all removable media in /media

 root@gkcollege:~$ ls /media/
 cdrom cdrom0 usbdisk
Chapter 3: THE COMMAND LINE
 data directories
o /mnt

 The /mnt directory should be empty and should only be used for
temporary mount points (according to the FHS)
 Unix and Linux administrators used to create many directories here, like
/mnt/something/
 You likely will encounter many systems with more than one directory
created and/or mounted inside /mnt to be used for various local and
remote filesystems
Chapter 3: THE COMMAND LINE
 data directories
o /tmp

 Applications and users should use /tmp to store temporary data when
needed
 Data stored in /tmp may use either disk space or RAM. Both of which are
managed by the operating system
 Never use /tmp to store data that is important or which you wish to
archive
Chapter 3: THE COMMAND LINE
 in memory directories
o /dev

 Device files in /dev appear to be ordinary files, but are not actually
located on the hard disk
 The /dev directory is populated with files as the kernel is recognizing
hardware

- Common Physical Devices


 Common hardware such as HDD devices are represented by
device files in /dev
 Besides representing physical hardware, some device files are
special
Chapter 3: THE COMMAND LINE
 in memory directories
o /dev

 These special devices can be very useful


#
# SATA or SCSI or USB
#
root@gkcollege:~$ ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sda3 /dev/sdb /dev/sdb1 /dev/sdb2
#
# IDE or ATAPI
#
root@gkcollege:~$ ls /dev/hd*
/dev/hda /dev/hda1 /dev/hda2 /dev/hdb /dev/hdb1 /dev/hdb2 /dev/hdc
Chapter 3: THE COMMAND LINE
 in memory directories
o /dev

- /dev/tty and /dev/pts


 /dev/tty1 represents a terminal or console attached to the
system
 When typing commands in a terminal that is part of a graphical
interface like Gnome or KDE, then your terminal will be
represented as /dev/pts/1
Chapter 3: THE COMMAND LINE
 in memory directories
o /dev

- /dev/null
 can be considered a black hole
 has unlimited storage, but nothing can be retrieved from it
 Technically speaking, anything written to /dev/null will be
discarded
 /dev/null can be useful to discard unwanted output from
commands
 /dev/null is not a good location to store your backups
Chapter 3: THE COMMAND LINE
 in memory directories
o /proc conversation with the kernel

 another special directory, appearing to be ordinary files, but not


taking up disk space
 It is actually a view of the kernel, or better, what the kernel manages,
and is a means to interact with it directly
 The directory /proc is a proc filesystem
root@gkcollege:~$ mount -t proc
none on /proc type proc (rw)

 When listing the /proc directory you will see many numbers (on any
Unix) and some interesting files (on Linux)
Chapter 3: THE COMMAND LINE
 in memory directories
root@gkcollege:~$ ls /proc
1 2339 4724 5418 6587 7201 cmdline mounts
10175 2523 4729 5421 6596 7204 cpuinfo mtrr
10211 2783 4741 5658 6599 7206 crypto net
10239 2975 4873 5661 6638 7214 devices pagetypeinfo
141 29775 4874 5665 6652 7216 diskstats partitions
15045 29792 4878 5927 6719 7218 dma sched_debug
1519 2997 4879 6 6736 7223 driver scsi
1548 3 4881 6032 6737 7224 execdomains self
1551 30228 4882 6033 6755 7227 fb slabinfo
1554 3069 5 6145 6762 7260 filesystems stat
1557 31422 5073 6298 6774 7267 fs swaps
1606 3149 5147 6414 6816 7275 ide sys
180 31507 5203 6418 6991 7282 interrupts sysrq-trigger
181 3189 5206 6419 6993 7298 iomem sysvipc
182 3193 5228 6420 6996 7319 ioports timer_list
18898 3246 5272 6421 7157 7330 irq timer_stats
19799 3248 5291 6422 7163 7345 kallsyms tty
Chapter 3: THE COMMAND LINE
 in memory directories
19803 3253 5294 6423 7164 7513 kcore uptime
19804 3372 5356 6424 7171 7525 key-users version
1987 4 5370 6425 7175 7529 kmsg version_signature
1989 42 5379 6426 7188 9964 loadavg vmcore
2 45 5380 6430 7189 acpi locks vmnet
20845 4542 5412 6450 7191 asound meminfo vmstat
221 46 5414 6551 7192 buddyinfo misc zoneinfo
2338 4704 5416 6568 7199 bus modules
Chapter 3: THE COMMAND LINE
 in memory directories
 Investigating the file properties inside /proc
 Looking at the date and time will display the current date and time
showing the files are constantly updated (a view on the kernel)
root@gkcollege:~$ date
Mon Jan 29 18:06:32 EST 2007
root@gkcollege:~$ ls -al /proc/cpuinfo
-r--r--r-- 1 root root 0 Jan 29 18:06 /proc/cpuinfo
root@gkcollege:~$
root@gkcollege:~$ ...time passes...
root@gkcollege:~$
root@gkcollege:~$ date
Mon Jan 29 18:10:00 EST 2007
root@gkcollege:~$ ls -al /proc/cpuinfo
-r--r--r-- 1 root root 0 Jan 29 18:10 /proc/cpuinfo
Chapter 3: THE COMMAND LINE
 in memory directories
 Most files in /proc are 0 bytes, yet they contain data--sometimes a lot
of data
 Try executing cat on files like /proc/cpuinfo, which contains
information about the CPU
root@gkcollege:~$ file /proc/cpuinfo
/proc/cpuinfo: empty
root@gkcollege:~$ cat /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 15
model name : AMD Athlon(tm) 64 X2 Dual Core Processor 4600+
stepping : 1
cpu MHz : 2398.628
cache size : 512 KB
Chapter 3: THE COMMAND LINE
 in memory directories
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 1
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic mtrr pge...
bogomips : 4803.54
Chapter 3: THE COMMAND LINE
 in memory directories
 Most of the files in /proc are read only, some require root privileges,
some files are writable and many files in /proc/sys are writable
- /proc/interrupts
 On the x86 architecture, /proc/interrupts displays the
interrupts
root@gkcollege:~$ cat /proc/interrupts
CPU0
0: 13876877 IO-APIC-edge timer
1: 15 IO-APIC-edge i8042
8: 1 IO-APIC-edge rtc
9: 0 IO-APIC-level acpi
12: 67 IO-APIC-edge i8042
14: 128 IO-APIC-edge ide0
Chapter 3: THE COMMAND LINE
 in memory directories
15: 124320 IO-APIC-edge ide1
169: 111993 IO-APIC-level ioc0
177: 2428 IO-APIC-level eth0
NMI: 0
LOC: 13878037
ERR: 0
MIS: 0
Chapter 3: THE COMMAND LINE
 in memory directories
 On a machine with two CPU's, the file looks like this
root@gkcollege:~$ cat /proc/interrupts
CPU0 CPU1
0: 860013 0 IO-APIC-edge timer
1: 4533 0 IO-APIC-edge i8042
7: 0 0 IO-APIC-edge parport0
8: 6588227 0 IO-APIC-edge rtc
10: 2314 0 IO-APIC-fasteoi acpi
12: 133 0 IO-APIC-edge i8042
14: 0 0 IO-APIC-edge libata
15: 72269 0 IO-APIC-edge libata
18: 1 0 IO-APIC-fasteoi yenta
19: 115036 0 IO-APIC-fasteoi eth0
20: 126871 0 IO-APIC-fasteoi libata, ohci1394
21: 30204 0 IO-APIC-fasteoi ehci_hcd:usb1, uhci_hcd:usb2
Chapter 3: THE COMMAND LINE
 in memory directories
 On a machine with two CPU's, the file looks like this
root@gkcollege:~$ cat /proc/interrupts
22: 1334 0 IO-APIC-fasteoi saa7133[0], saa7133[0]
24: 234739 0 IO-APIC-fasteoi nvidia
NMI: 72 42
LOC: 860000 859994
ERR: 0
Chapter 3: THE COMMAND LINE
 in memory directories
 On a machine with two CPU's, the file looks like this

- /proc/kcore

 The physical memory is represented in /proc/kcore


 Do not try to cat this file, instead use a debugger
 The size of /proc/kcore is the same as your physical memory,
plus four bytes
root@gkcollege:~$ ls -lh /proc/kcore
-r-------- 1 root root 2.0G 2007-01-30 08:57 /proc/kcore
root@gkcollege:~$
Chapter 3: THE COMMAND LINE
 in memory directories
o /sys Linux 2.6 hot plugging

 The /sys directory was created for the Linux 2.6 kernel
 Since 2.6, Linux uses sysfs to support usb and IEEE 1394 (FireWire)
hot plug devices
 See the manual pages of udev(8) (the successor of devfs) and
hotplug(8)
 for more info http://linuxhotplug.sourceforge.net/
 Basically the /sys directory contains kernel information about
hardware
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o Although /usr is pronounced like user, remember that it stands for Unix
System Resources
o The /usr hierarchy should contain shareable, read only data
o Some people choose to mount /usr as read only
o This can be done from its own partition or from a read only NFS share
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/bin

 The /usr/bin directory contains a lot of commands

root@gkcollege:~$ ls /usr/bin | wc -l
1395
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/include

 The /usr/include directory contains general use include files for C

root@gkcollege:~$ ls /usr/include/
aalib.h expat_config.h math.h search.h
af_vfs.h expat_external.h mcheck.h semaphore.h
aio.h expat.h memory.h setjmp.h
AL fcntl.h menu.h sgtty.h
aliases.h features.h mntent.h shadow.h
...
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/lib

 The /usr/include directory libraries that are not directly executed by


users or scripts
root@gkcollege:~$ ls /usr/lib | head -7
4Suite
ao
apt
arj
aspell
avahi
bonobo
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/local

 The /usr/local directory can be used by an administrator to install


software locally
root@gkcollege:~$ ls /usr/local/
bin etc games include lib man sbin share src
paul@deb508:~$ du -sh /usr/local/
128K /usr/local/
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/share

 The /usr/local directory contains architecture independent data, this is


a fairly large directory
root@gkcollege:~$ ls /usr/share/ | wc -l
263
root@gkcollege:~$ du -sh /usr/share/
1.3G /usr/share/
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/share

 The /usr/local directory contains architecture independent data, this is


a fairly large directory
root@gkcollege:~$ ls /usr/share/ | wc -l
263
root@gkcollege:~$ du -sh /usr/share/
1.3G /usr/share/

 This directory typically contains /usr/share/man for manual pages


root@gkcollege:~$ ls /usr/share/man
cs fr hu it.UTF-8 man2 man6 pl.ISO8859-2 sv
de fr.ISO8859-1 id ja man3 man7 pl.UTF-8 tr
es fr.UTF-8 it ko man4 man8 pt_BR zh_CN
Chapter 3: THE COMMAND LINE
 /usr Unix System Resources
o /usr/src

 The /usr/local directory is the recommended location for kernel source


files
root@gkcollege:~$ ls -l /usr/src/
total 12
drwxr-xr-x 4 root root 4096 2011-02-01 14:43 linux-headers-2.6.26-2-686
drwxr-xr-x 18 root root 4096 2011-02-01 14:43 linux-headers-2.6.26-2-common
drwxr-xr-x 3 root root 4096 2009-10-28 16:01 linux-kbuild-2.6.26
Chapter 3: THE COMMAND LINE
 /var variable data
o Files that are unpredictable in size, such as log, cache and spool files, should
be located in /var
Chapter 3: THE COMMAND LINE
 /var variable data
o /var/log

 The /usr/local directory serves as a central point to contain all log files
root@gkcollege:~$ ls /var/log
acpid cron.2 maillog.2 quagga secure.4
amanda cron.3 maillog.3 radius spooler
anaconda.log cron.4 maillog.4 rpmpkgs spooler.1
anaconda.syslog cups mailman rpmpkgs.1 spooler.2
anaconda.xlog dmesg messages rpmpkgs.2 spooler.3
audit exim messages.1 rpmpkgs.3 spooler.4
boot.log gdm messages.2 rpmpkgs.4 squid
boot.log.1 httpd messages.3 sa uucp
boot.log.2 iiim messages.4 samba vbox
boot.log.3 iptraf mysqld.log scrollkeeper.log vmware-tools-guestd
boot.log.4 lastlog news secure wtmp
canna mail pgsql secure.1 wtmp.1
cron maillog ppp secure.2 Xorg.0.log
cron.1 maillog.1 prelink.log secure.3 Xorg.0.log.old
Chapter 3: THE COMMAND LINE
 /var variable data
o /var/log/messages

 A typical first file to check when troubleshooting on Red Hat (and


derivatives) is the /var/log/messages file
 By default this file will contain information on what just happened to the
system
 The file is called /var/log/syslog on Debian and Ubuntu
[root@gkcollege ~]# tail /var/log/messages
Jul 30 05:13:56 anacron: anacron startup succeeded
Jul 30 05:13:56 atd: atd startup succeeded
Jul 30 05:13:57 cups-config-daemon: cups-config-daemon startup succeeded
Jul 30 05:14:01 fstab-sync[3646]: added mount point /media/floppy for...
Jul 30 05:16:46 sshd(pam_unix)[3662]: session opened for user root by...
Jul 30 06:06:37 su(pam_unix)[3904]: session opened for user root
Chapter 3: THE COMMAND LINE
 /var variable data
o /var/cache

 The /var/cache directory can contain cache data for several applications
root@gkcollege:~$ ls /var/cache/
apt dictionaries-common gdm man software-center
binfmts flashplugin-installer hald pm-utils
cups fontconfig jockey pppconfig
debconf fonts ldconfig samba
Chapter 3: THE COMMAND LINE
 /var variable data
o /var/spool

 The /var/spool directory typically contains spool directories for mail and
cron
 Also serves as a parent directory for other spool files (for example print
spool files)

o /var/lib

 The /var/lib directory contains application state information


 Red Hat Enterprise Linux for example keeps files pertaining to rpm in
/var/lib/rpm/
Chapter 3: THE COMMAND LINE
 /var variable data
o /var/…

 The /var also contains Process ID files in /var/run (soon to be replaced


with /run)
 temporary files that survive a reboot in /var/tmp
 Information about file locks in /var/lock

You might also like