Linux SysAdmin Topic 104.odp

You might also like

Download as odp, pdf, or txt
Download as odp, pdf, or txt
You are on page 1of 66

Linux SysAdmin

Topic 104
Devices, Linux Filesystems, Filesystem Hierarchy
Standard
104.1 Create partitions and filesystems
GPT vs. MBR

Globally Unique Identifiers Partition Table or GPT is the modern replacement for the
antique MS-DOS Master Boot Record (MBR). Some advantages of GPT:

- 64-bit disk pointers allows 264 total sectors, so a hard disk with 512-byte blocks can
be as large as 8 zebibytes. With 4096-byte sectors your maximum disk size is really
really large
- The default maximum number of partitions is 128, and if your operating system
supports it you can have more
104.1 Create partitions and filesystems
- No more CHS cruft or hacky primary-extended-logical partitioning scheme, which
falls down if you need Windows because Windows is inflexible and hogs primary
partitions
- GPT has fault-tolerance by keeping copies of the partition table in the first and last
sector on the disk
- GPT computes a cyclic redundancy check (CRC) checksum to verify its own
integrity, and of the partition table
- Unique IDs for disks and partitions.

More on GPT: https://www.linux.com/learn/using-New-GUID-Partition-Table-Linux-Goodbye-Ancient-MBR


104.1 Create partitions and filesystems
To get GUIDs we need the gdisk command:

# gdisk /dev/sda
104.1 Create partitions and filesystems
mkfs - Used to create a filesystem on a new partition. You may use mkfs or mke2fs.

Syntax: mkfs [ -V ] [ -t fstype ] [ fs-options ] filesys [ blocks ]

OPTIONS

-V Produce verbose output, including all file system-specific commands that are executed.
Specifying this option more than once inhibits execution of any file system-specific
commands. This is really only useful for testing.
104.1 Create partitions and filesystems
-t fstype Specifies the type of file system to be built. If not specified, the default file
system type is used.

fs-options File system-specific options to be passed to the real file system builder.
Although not guaranteed, the following options are supported by most file system
builders.

-c Check the device for bad blocks before building the file system.

-l filename Read the bad blocks list from filename

-v Produce verbose output.


104.1 Create partitions and filesystems
ext4

Supports huge individual file size and overall file system size.

Maximum individual file size can be from 16 GB to 16 TB

Overall maximum ext4 file system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1


PB = 1024 TB (terabyte).

Directory can contain a maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
104.1 Create partitions and filesystems
ext3

The main benefit of ext3 is that it allows journaling.

Journaling has a dedicated area in the file system, where all the changes are tracked.
When the system crashes, the possibility of file system corruption is less because of
journaling.

Maximum individual file size can be from 16 GB to 2 TB

Overall ext3 file system size can be from 2 TB to 32 TB


104.1 Create partitions and filesystems
xfs

XFS is a highly scalable, high-performance file journalling file system which was
originally designed at Silicon Graphics, Inc in 1993. Originally XFS was used on Silicon
Graphics Inc's own operating system Irix, however, it was later ported to the Linux kernel
in 2001. Today XFS is supported by most Linux distributions and has now become the
default filesystem on RHEL (Red Hat Enterprise Linux), Oracle Linux 7, CentOS 7 and
many other distributions. Originally XFS was created to support extremely large
filesystems with sizes of up to 16 exabytes and file sizes of up to 8 exabytes.
104.1 Create partitions and filesystems
btrfs (read as butter-FS)

btrfs is a modern copy on write (CoW) filesystem for Linux aimed at implementing advanced features
while also focusing on fault tolerance, repair and easy administration. Jointly developed at multiple
companies, btrfs is licensed under the GPL and open for contribution from anyone.

btrfs is not a successor to the default Ext4 file system used in most Linux distributions, but it can be
expected to replace Ext4 in the future. Theodore Ts’o, a maintainer for Ext3 and later, Ext4, has stated
that he sees Btrfs as a better way forward than continuing to rely on the ext* technology.

Max file size: 50 TB


104.1 Create partitions and filesystems
vfat, exfat

VFAT is an extension of the FAT file system and was introduced with Windows 95. VFAT
maintains backward compatibility with FAT but relaxes the rules. For example, VFAT
filenames can contain up to 255 characters, spaces, and multiple periods.

The exFAT file system is ideal for flash drives and SD cards. It’s like FAT32, but without
the 4 GB file size limit. You can use exFAT drives on Linux with full read-write support,
but you’ll need to install a few packages first.
104.1 Create partitions and filesystems
mkswap sets up a Linux swap area on a device or in a file

Syntax: mkswap [-c] [-vN] [-f] [-p PSZ] device [size]

After creating the swap area, you need the swapon command to start using it. Usually
swap areas are listed in /etc/fstab so that they can be taken into use at boot time by a
swapon -a command in some boot script.
104.1 Create partitions and filesystems
Options

-c Check the device (if it is a block device) for bad blocks before creating the swap area.

If any are found, the count is printed.

-f Force
-p PSZ Specify the page size to use.
-v0 Create an old style swap area.
-v1 Create a new style swap area.
104.2 Maintain the integrity of filesystems
du

The Linux “du” (Disk Usage) is a standard Unix/Linux command, used to check the information of
disk usage of files and directories on a machine.

Usage: du [options] [directory]

Options:
-h (human readable sizes)
-a (all including files)
-d level (with directory level)
-c (with total size at the last line)
-s (with summary of a grand total disk usage size of a directory)
-k (in kilobytes)
104.2 Maintain the integrity of filesystems
df ("disk free")

df is used to get full summary of available and used disk space usage of file system on Linux system.

Usage: df [options] [directory]

Options:
-a Show counts for all filesystems -t fs type Limit listing
to fs type
-h Print in human readable form -k Show size in Kilobytes
-m Display size in Megabytes -i Display inode
information
-l Limit listing to local filesystems -x fs type Exclude fs
type from listing
104.2 Maintain the integrity of filesystems
fsck - Check and repair a Linux file system

fsck will try to run filesystems on different physical drives in parallel to reduce total amount time to
check all of the filesystems.

fsck makes 5 passes on the filesystem:

– Pass 1: Check inodes, blocks & sizes


– Pass 2: Check directory structure
– Pass 3: Check directory connectivity
– Pass 4: Check reference counts
– Pass 5: Check group summary information
104.2 Maintain the integrity of filesystems
fsck options:

-p Automatically repair without prompting


-n Don’t make changes to filesystem
-y Assume yes to all questions
-f Force check even if fs is clean
-r Interactively prompt for changes
-v Be verbose
-A Check all filesystems in /etc/fstab
-C Display a progress bar
-N Don’t execute, show what would be done
104.2 Maintain the integrity of filesystems
fsck error codes

When fsck completes, it will return a value, as follows:

Code Meaning
0 No errors
1 Errors found & corrected
2 System should be rebooted
4 Filesystem error left uncorrected
8 Operational error
16 Usage or syntax error
128 Shared library error
104.2 Maintain the integrity of filesystems
e2fsck - check a Linux ext2/ext3/ext4 file system

e2fsck also supports ext2 filesystems containing a journal, which are also sometimes known as ext3
filesystems.

e2fsck operates in a similar manner to fsck (see man page)


104.2 Maintain the integrity of filesystems
mke2fs - Create a Linux ext2/ext3/ext4 filesystem

mke2fs takes a device special file as its argument.

mkfs.ext2 is the same as mke2fs

To make an ext3 filesystem, you first make an ext2 filesystem and then add a journal to it using
tune2fs or use the -j option to mke2fs.

Usage is:

mke2fs [options] device


104.2 Maintain the integrity of filesystems
mke2fs Options

Option

-t Filesystem type (ext2, ext3, ext4)


-V Be verbose
-b blocksize Make blocks blocksize bytes
-c Check for bad blocks on device
-i bytes per inode Create an inode for each bytes per inode
-j Create a journal (ext3)
-L label Set the volume label
-N inodes Create the fs with specified number of inodes
-n Show what would be done (don’t actually create fs)
104.2 Maintain the integrity of filesystems
tune2fs - Adjust filesystem parameters on ext2/ext3/ext4 filesystem

tune2fs adjusts tunable filesystem parameters on an ext2/ext3/ext4 filesystem.

tune2fs can be used to add a journal to an ext2 filesystem.

Usage is: tune2fs [options] device

Options:

-c max-mounts Set no of mounts before fsck is forced


-g group Set the group who can use reserved blocks
-j Add a journal to the filesystem
-L label Set the volume label
-r blocks Set the number of reserved blocks
104.2 Maintain the integrity of filesystems
debugfs - ext2/ext3/ext4 filesystem debugger

It can be used to examine and change the state of an ext2/ext3/ext4 file system. debugfs is an
interactive debugger. It understands a number of commands:

cat filespec Dump the contents of the inode filespec to stdout.


cd filespec Change the current working directory to filespec.
chroot filespec Change the root directory to be the directory file spec.
close Close the currently open file system.
quit Exit debugfs.
104.2 Maintain the integrity of filesystems
dumpe2fs - Dump filesystem information

dumpe2fs prints the super block and blocks group information for the filesystem present on device.

A superblock is a record of the characteristics of a filesystem, including its size, the block size, the empty and the
filled blocks and their respective counts, the size and location of the inode tables, the disk block map and usage
information, and the size of the block groups.

Usage: dumpe2fs [options] device

Common options

-b Display badblocks on device


-h Display superblock information
104.2 Maintain the integrity of filesystems
XFS utilities are available to perform file system maintenance on XFS filesystems. These utilities
include the following:

xfs_fsr: XFS is an extent-based file system. The xfs_fsr utility reorganizes and improves the layout of the
file extents, which improves overall performance. Run this command on a mounted XFS file system or on
individual files in the file system.

xfs_repair: Repair a corrupted or damaged XFS file system. Unmount the file system before running this
command. If the file system cannot be repaired, restore files from a backup with xfsrestore.

xfs_db: Debug an XFS file system. This utility provides a command set that allows you to perform scans on
the file system and to navigate and display its data structures.

More on these utilities: https://www.thegeekdiary.com/running-repairs-on-xfs-filesystems/


104.3 Control mounting and unmounting of
filesystems
/etc/fstab (fstab = filesystems table)

/etc/fstab is the system's filesystem table. At boot time the /etc/fstab file assigns mount
points for block devices.
104.3 Control mounting and unmounting of
filesystems
# <file system> <mount point> <type> <options> <dump> <pass>

# / was on /dev/sda5 during installation


UUID=246723c3-7643-419c-b3aa-02953f2dd906 / ext4 errors=remount-ro 0 1

# /boot was on /dev/sda1 during installation


UUID=1e942a71-b200-4bc3-b046-3becc4dbd6dc /boot ext4 defaults 0 2

# /home was on /dev/sda9 during installation


UUID=0b30b183-cf47-4171-9b6a-6e7ebd3d295c /home ext4 defaults 0 2

# swap was on /dev/sda8 during installation


UUID=273b943b-7b56-4a4a-9bdd-450e955fb3cb none swap sw 0 0

/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0


104.3 Control mounting and unmounting of
filesystems
Some options:

sync/async - All I/O to the file system should be done (a)synchronously.


auto - The filesystem can be mounted automatically (at bootup, or when mount is passed the -a option). This is really
unnecessary as this is the default action of mount -a anyway.
noauto - The filesystem will NOT be automatically mounted at startup, or when mount passed -a. You must explicitly mount
the filesystem.
dev/nodev - Interpret/Do not interpret character or block special devices on the file system.
exec/noexec - Permit/Prevent the execution of binaries from the filesystem.
suid/nosuid - Permit/Block the operation of suid, and sgid bits.
ro - Mount read-only.
rw - Mount read-write.
user - Permit any user to mount the filesystem. This automatically implies noexec, nosuid,nodev unless overridden.
nouser - Only permit root to mount the filesystem. This is also a default setting.
defaults - Use default settings. Equivalent to rw, suid, dev, exec, auto, nouser, async.
104.3 Control mounting and unmounting of
filesystems
Dumping and Fscking:

Column 5 of the fstab indicates whether to use the backup utility dump for the file system. 0 means no backup.

Column 6 indicates the sequence of the file system checks (with the fsck utility) when the system is booted:

0: file systems that are not to be checked

1: the root directory

2: all other modifiable file systems; file systems on different drives are checked in parallel
104.3 Control mounting and unmounting of
filesystems
mount

The mount command without any options will display all filesystems mounted as at the command time.

The mount command is used to make a particular device available on a specific directory (mount point). The syntax
is:

mount -t [FSTYPE] -o [OPTIONS] DEVICE DIRECTORY

For example we can mount a CDROM on the mount point /mnt/cdrom with:

mount -t iso9660 /dev/cdrom /mnt/cdrom

mount -t exfat /dev/sda2 /media/[username]/[reserved-folder] # To mount a USB disk partition


104.3 Control mounting and unmounting of
filesystems
Option summary for mount:

rw,ro read-write and read-only

noauto the device is not mounted at boot time

users the device can be read and unmounted by all users

user the device can be unmounted only by the user

owner the device will change it's permission and belong to the user that mounted it

usrquota start user quotas on the device

grpquota start group quotas on the device


104.3 Control mounting and unmounting of
filesystems
The umount command will unmount a device.

Syntax:

umount DEVICE or MOUNT-POINT

For example the following commands will both unmount the CDROM device:

umount /dev/cdrom

or

umount /mnt/cdrom
104.3 Control mounting and unmounting of
filesystems
blkid

Using blkid command you can view attributes of block devices that are on your system. This is a quick way to find
the type of the block devices on your system.

For example,

# blkid
/dev/sdb1: UUID="6e0acfe3-81ed-4f9f-8ab5-0d65ba1f0ef2" TYPE="ext2"
/dev/sdc1: UUID="aa82d7bb-ab2b-4739-935f-fd8a5c9a6cb0" TYPE="ext2"
/dev/sda1: UUID="187171ab-c9b8-43ec-b0bb-77c736ca22e0" TYPE="ext4" LABEL="/home"
/dev/sda2: UUID="1a225baa-7027-4619-aaa5-900e24c1fdff" TYPE="swap"
/dev/sdb3: UUID="2a294b33-eb61-40a3-b3fc-ad6eaf7f156f" TYPE="ext2"
104.3 Control mounting and unmounting of
filesystems
blkid commands

blkid -i /dev/sdb1 (View I/O Limits)

blkid -p /dev/sdc (View additional information)

blkid -pi /dev/sdc (View I/O limits and additional information)

blkid -l -t LABEL=/home (Search for label)

blkid -t TYPE=ext2 (Search for fs type)

blkid -U 6e0acfe3-81ed-4f9f-8ab5-0d65ba1f0ef2 (Search the UUID)

blkid -o list (Display output in list/table format)


104.3 Control mounting and unmounting of
filesystems
lsblk - list block devices

Example:
104.5 Manage file permissions and ownership
You own the files and directories that you created. As their owner, you have the
permission to specify who else is allowed access to them.

Create a file and enter this command: ls -l file-that-you-created.

You can see who can read (r) and write to (w) the file, as well as who created the file (user), and to which group the
owner belongs (user). (By default, the name of your group is the same as your login name.)

Other information to the right of the group includes file size, date and time of file creation, and file name.

The first column shows current permissions; it has ten slots. The first slot represents the type of file. The remaining
nine slots are actually three sets of permissions for three different categories of users.
104.5 Manage file permissions and ownership
Using ls -l command and option will give ownership and permision information about
files.
104.5 Manage file permissions and ownership
A file has 3 modes of access:

– Read (r) - Can view the file


– Write (w) - Can change the file
– Execute (x) - Can run the file (program)

A file can be accessed by 3 different types of people:

– The file owner or user (u)


– A member of the files group (g)
– Anyone else or others (o)
104.5 Manage file permissions and ownership
Directories are treated in the same way as files.

They have an associated owner.

They have an associated group.

The permissions do slightly different things

– Read (r) - Can view the contents of directory (ls)


– Write (w) - Can add, delete, rename files
– Execute (x) - Can ’cd’ into the directory and open files in it or its subdirectories
104.5 Manage file permissions and ownership
Numeric Equivalents

Each permission setting can be represented by a numerical value:

r=4
w=2
x=1
-=0
104.5 Manage file permissions and ownership
chown - change file owner and group

To change the ownership of a file:

chown username file (user only)


chown username:group file (user and group)

To change the owner and group of a file or directory:

chown -R username directory (user only)


chown -R username:group directory (user and group)
104.5 Manage file permissions and ownership
chgrp - change group ownership

To change the group ownership of a file:

chgrp group file

To change the group ownership of a directory:

chgrp -R group directory


104.5 Manage file permissions and ownership
chmod - change file mode bits, or change file permissions

This can be done in two ways:

- octal specification (use of numbers)


- symbolic mode
104.5 Manage file permissions and ownership
When using an octal specification, you must set the permissions for each of the user,
group and other in one go:

chmod 0543 test.txt (give permissions of 0543 to the file test.txt)

5 = 4 (r ) + 0 (w) + 1 (x)

4 = 4 (r ) + 0 (w) + 0 (x)

3 = 0 (r ) + 2 (w) + 1 (x)
104.5 Manage file permissions and ownership
When using the symbolic mode, consider the following symbols:

Identities
u — the user who owns the file (that is, the owner)
g — the group to which the user belongs
o — others (not the owner or the owner's group)
a — everyone or all (u, g, and o)

Permissions Actions
r — read access + — adds the permission
w — write access - — removes the permission
x — execute access = — makes it the only permission
104.5 Manage file permissions and ownership
Some examples of permission settings using symbolic mode:

g+w — adds write access for the group


o-rwx — removes all permissions for others
u+x — allows the file owner to execute the file
a+rw — allows everyone to read and write to the file
ug+r — allows the owner and group to read the file
g=rx — allows only the group to read and execute (not write)
104.5 Manage file permissions and ownership
Some examples of using the symbolic mode:

Add execute permission for the file’s owner (and leave everything else)
# chmod u+x file.txt

Remove write permission from group and others (and leave everything else)
# chmod go-w file.txt

Set the file to read only for everyone (kills existing permissions)
# chmod a=r file.txt
104.5 Manage file permissions and ownership
umask - set file mode creation mask

When a file is created, the system needs to know what permissions to assign to the newly
created file. This is done using ’umask’.

You set the bits in umask that you don't want set on any newly created file.

A newly created file will never have the execute bit set, regardless of the value of umask.

For example, a umask of 022 will ensure that write access is not granted to group and others.
Or, use 026 to make sure that other users can neither read nor edit your files.
104.5 Manage file permissions and ownership
Set-user Identification (SUID)

-rwsr-xr-x 1 root root 47032 May 17 2017 /usr/bin/passwd


-rwsr-xr-x 1 root root 36936 May 17 2017 /bin/su

The 's' symbol indicates SUID bit.

When a command or script with SUID bit set is run, its effective UID becomes that of the
owner of the file, rather than of the user who is running it.

SUID bit is also known as Setuid bit with value of 4000.


104.5 Manage file permissions and ownership
$ ls -l hexdump
-rwxr-xr-x 1 root root ... hexdump

$ ls -l /dev/sda1
brw-rw---- 1 root disk ... /dev/hda1

$ hexdump -n 10 /dev/sda1
hexdump: /dev/sda1: Permission denied

# chmod 4755 hexdump


# ls -l hexdump
-rwsr-xr-x 1 root root ... hexdump

$ hexdump -n 10 /dev/sda1
0000000 ace9 4100 4a50 5726 1a4e
104.5 Manage file permissions and ownership
Set-group identification (SGID)

SGID permission is similar to the SUID permission, only difference is – when the script or
command with SGID on is run, it runs as if it were a member of the same group in which
the file is a member.

-rwxr-sr-x 1 root tty 14688 Jun 4 2013 /usr/bin/bsd-write

The setgid permission displays as an “s” in the group’s execute field.

The setgid bit value is set to 2000.

chmod 2755 [path-to-file]


104.5 Manage file permissions and ownership
SGID on a directory

When SGID permission is set on a directory, files created in the directory belong to the
group of which the directory is a member.

For example if a user having write permission in the directory creates a file there, that file
is a member of the same group as the directory and not the user’s group.

This is very useful in creating shared directories.

chmod g+s [path_to_directory]


104.5 Manage file permissions and ownership
Sticky Bit

The sticky bit is primarily used on shared directories.

It is useful for shared directories such as /var/tmp and /tmp because users can create files, read and
execute files owned by other users, but are not allowed to remove files owned by other users.

Sticky bit value is 1000.

chmod +t [path_to_directory]
chmod 1777 [path_to_directory]
104.6 Create and change hard and symbolic links
inode

An inode (index node) is a data structure of a file. An inode stores basic information about
a regular file, directory, or other file system object:

=> File type (executable, block special etc) => Permissions (read, write etc)
=> Owner => Group
=> File Size => File access, change and
modification time
=> File deletion time => Number of links (soft/hard)
=> Extended attribute such as append => Access Control List (ACLs)
only or no one can delete file including
root user (immutability)
104.6 Create and change hard and symbolic links
To access the file's inode:

stat [file]

To include inode in the output of ls command:

ls -i
104.6 Create and change hard and symbolic links
A soft link to a file or a directory creates a new inode that points to the same data area:

ln-s lilo.conf lilo.sym

This is the listing for these files. Notice that the reference count is 1 for both files.

-rw------- 1 root root 223 Nov 9 09:06 lilo.conf


lrwxrwxrwx 1 root root 9 Nov 9 09:06 lilo.sym -> lilo.conf

Soft links can be created across filesystems.


104.6 Create and change hard and symbolic links
Hard Links

A hard link is an additional name for the same inode and as such the reference count of the file
increases by one for every new hard link.

ln lilo.conf lilo.link

In the listing notice that the reference count is 2 and that both files have the same size. In fact they are
identical.

-rw------- 2 root root 223 Nov 9 09:06 lilo.conf


-rw------- 2 root root 223 Nov 9 09:06 lilo.link

Hard links can only be created within the same filesystem.


104.6 Create and change hard and symbolic links
In summary:

Soft link
● can cross the file system,
● allows you to link between directories,
● has different inode number and file permissions than original file,
● permissions will not be updated,
● has only the path of the original file, not the contents.

Hard Link
● can't cross the file system boundaries (i.e. A hardlink can only work on the same filesystem),
● can't link directories,
● has the same inode number and permissions of original file,
● permissions will be updated if we change the permissions of source file,
● has the actual contents of original file, so that you still can view the contents, even if the original file moved or
removed.
104.7 Find system files and place files in the correct
location
The Filesystem Hierarchy Standard (FHS)

This standard enables:

Software to predict the location of installed files and directories, and


Users to predict the location of installed files and directories.

This is done by:

Specifying guiding principles for each area of the filesystem,


Specifying the minimum files and directories required,
Enumerating exceptions to the principles, and
Enumerating specific cases where there has been historical conflict.
104.7 Find system files and place files in the correct
location
Directories may be categorized
as shareable or unshareable
and static or variable
104.7 Find system files and place files in the correct
location
Directories

/ Primary hierarchy root and root directory of the entire file system hierarchy.

/bin Essential command binaries that need to be available in single user mode; for all
users, e.g., cat, ls, cp.

/boot Boot loader files, e.g., kernels, initrd.

/etc Host-specific system-wide configuration files

/home Users' home directories, containing saved files, personal settings, etc.

/lib Libraries essential for the binaries in /bin and /sbin.


104.7 Find system files and place files in the correct
location
/lib<qual> Alternative format essential libraries. Such directories are optional, but if they
exist, they have some requirements.

/media Mount points for removable media such as CD-ROMs

/mnt Temporarily mounted filesystems.

/opt Optional application software packages

/proc Virtual filesystem providing process and kernel information as files. In Linux,
corresponds to a procfs mount. Generally automatically generated and populated by the
system, on the fly.
104.7 Find system files and place files in the correct
location
/root Home directory for the root user.

/run Run-time variable data: Information about the running system since last boot, e.g.,
currently logged-in users and running daemons. Files under this directory must be either
removed or truncated at the beginning of the boot process; but this is not necessary on
systems that provide this directory as a temporary filesystem (tmpfs).

/sbin Essential system binaries, e.g., fsck, init, route.

/srv Site-specific data served by this system, such as data and scripts for web servers, data
offered by FTP servers, and repositories for version control systems
104.7 Find system files and place files in the correct
location
/sys Contains information about devices, drivers, and some kernel features.

/tmp Temporary files (see also /var/tmp). Often not preserved between system reboots, and
may be severely size restricted.

/usr Secondary hierarchy for read-only user data; contains the majority of (multi-)user
utilities and applications.

/var Variable files—files whose content is expected to continually change during normal
operation of the system—such as logs, spool files, and temporary e-mail files. (mysql files
- /var/lib/)
104.7 Find system files and place files in the correct
location
locate - find files by name

-0 to display all the output in one line


-c to get the count of the matching entry
-d <new mlocate db path> <filename>
-e display only files that exist in the system
-i ignore the case of file
-l limit the number of records to be displayed.
104.7 Find system files and place files in the correct
location
updatedb - update a database for locate

The commands update the database /var/cache/locate/locate.

To change how the updatedb updates the database, the file /etc/updatedb.conf needs to be
edited. If this does not exist, it may be located in /etc/cron.daily/locate. Values of the following
variables may be changed.

PRUNE_BIND_MOUNTS="yes"
PRUNENAMES=".git .bzr .hg .svn"
PRUNEPATHS="/tmp /var/spool /media"
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"

You might also like