Table of Content
Weight: 2
Description: Candidates should be thoroughly familiar with the Filesystem Hierarchy Standard (FHS), including typical file locations and directory classifications.
Key Knowledge Areas:
- Understand the correct locations of files under the FHS
- Find files and commands on a Linux system
- Know the location and purpose of important file and directories as defined in the FHS
Terms and Utilities:
find locate updatedb whereis which type /etc/updatedb.conf
FHS
Filesystem Hierarchy Standard (FHS). This new standard is based on FSSTND but extends it substantially
path
[root@dclab-centos7 ~]# echo $PATH /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
which
which command shows you the first occurrence of a command in your path
[oldhorse@dclab-centos7 ~]$ which awk /usr/bin/awk [root@dclab-centos7 ~]# echo $(which -a awk) /bin/awk /usr/bin/awk [root@dclab-centos7 ~]# ls -l $(which -a awk) lrwxrwxrwx. 1 root root 4 Sep 19 14:00 /bin/awk -> gawk lrwxrwxrwx. 1 root root 4 Sep 19 14:00 /usr/bin/awk -> gawk
whereis
find more information than just the location of a program
[oldhorse@dclab-centos7 ~]$ whereis awk awk: /usr/bin/awk /usr/libexec/awk /usr/share/awk /usr/share/man/man1/awk.1.gz
type
The typecommand is a builtin that will tell you how a given command string will be evaluated for execution
[oldhorse@dclab-centos7 ~]$ type awk
awk is /usr/bin/awk
[root@dclab-centos7 ~]# which ls
alias ls='ls --color=auto'
/bin/ls
[root@dclab-centos7 ~]# type ls
ls is aliased to `ls --color=auto'
find
# find /home -name ā*.cā find /home/oldhorse/ -user oldhorse [root@dclab-centos7 ~]# find /tmp -iregex ".*unix*." /tmp/.X11-unix /tmp/.ICE-unix /tmp/.XIM-unix /tmp/.font-unix /tmp/.Test-unix [root@dclab-centos7 ~]# find /tmp -iregex ".*unix*." -type d /tmp/.X11-unix /tmp/.ICE-unix /tmp/.XIM-unix /tmp/.font-unix /tmp/.Test-unix [root@dclab-centos7 ~]# find /tmp -perm -o=rwt /tmp /tmp/.X11-unix /tmp/.ICE-unix /tmp/.XIM-unix /tmp/.font-unix /tmp/.Test-unix
locate
The locate command matches against any part of a path name, not just the file name.
root@dclab-u1504s:~# ls -l $(which -a locate)
lrwxrwxrwx 1 root root 24 Sep 20 06:33 /usr/bin/locate -> /etc/alternatives/locate
root@dclab-u1504s:~# type locate
locate is hashed (/usr/bin/locate)
oldhorse@dclab-u1504s:~$ locate /bin/ls
/bin/ls
/bin/lsblk
/bin/lsmod
/usr/bin/lsattr
/usr/bin/lsb_release
/usr/bin/lscpu
/usr/bin/lshw
/usr/bin/lsinitramfs
/usr/bin/lslocks
/usr/bin/lsof
/usr/bin/lspci
/usr/bin/lspgpot
/usr/bin/lsusb
/usr/lib/klibc/bin/ls
root@dclab-u1504s:~# locate -S
Database /var/lib/mlocate/mlocate.db:
8,944 directories
69,989 files
3,582,563 bytes in file names
1,534,796 bytes used to store database
locatedb updated by updatedb command
To enable daily updates, the root user needs to edit /etc/updatedb.conf and set DAILY_UPDATE=yes. To create the database immediately, run the updatedb command as root.
root@dclab-u1504s:~# less /etc/updatedb.conf
PRUNE_BIND_MOUNTS="yes"
# PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs /var/lib/schroot"
PRUNEFS="NFS nfs nfs4 rpc_pipefs afs binfmt_misc proc smbfs autofs iso9660 ncpfs coda devpts ftpfs devfs mfs shfs sysfs cifs lustre tmpfs usbfs udf fuse.glusterfs fuse.sshfs curlftpfs ecryptfs fusesmb devtmpfs"
ls -l /usr/bin/{slocate,locate,updatedb}
ls: cannot access /usr/bin/slocate: No such file or directory
lrwxrwxrwx 1 root root 24 Sep 20 06:33 /usr/bin/locate -> /etc/alternatives/locate
lrwxrwxrwx 1 root root 26 Sep 20 06:33 /usr/bin/updatedb -> /etc/alternatives/updatedb
Quiz questions
1. What is the distinction between /usr/bin and /bin? 2. What determines whether an executable is in /usr/bin or /usr/sbin? 3. When should files appear in /usr/local? 4. Why is /lib separate from /usr/lib? 5. What is the relationship between the which command and the PATH environment variable? Answers to quiz questions 1. /bin contains files which are essential for booting when /usr may not be available. 2. The contents of /bin is standardised, but anything can appear in /usr/bin. 3. When the files have been prepared for local conditions, e.g. customised programs, etc. 4. boot time vs run time when /usr is available. 5. which searches the directories in the PATH variable.