Understanding Files and File System

Index

  1. File System in Linux
  2. Directories in Linux
  3. File Structure and hierarchy
  4. File Permissions
  5. File Management and Manipulation
  6. Managing File System

File System in Linux

In a Linux system, all data and programs are stored in the file. There is not any restriction on the structure of a file. It is a collection of related data. The size of a Linux file is the exact size of the contents stored inside the file. That means it does not need its own size for storage. A Linux file or a file system is said to be the heart of it. The files in a file system are connected logically. A file system manages how the files are stored and can be retrieved easily

Type of Files

Linux operating systems have different types of files. Most of the commonly used file types are regular files, directory files, and device files.

  • Regular Files: - Regular files or ordinary files are the most used files in the Linux system. All the text files, binary files, executable program files, image files, shared libraries, etc. are known as regular files. Regular files are denoted by a dash (‘–’) symbol.
  • Directory Files: - Linux stores all the data and programs in files. These files are contained in directories. A directory contains all the regular files, special files, other folders stored in a physical device. These files are denoted by the symbol ‘d’.
  • Special or Device File: - Device files or special files in Linux are the files that work as an interface to device drivers. It allows an application to interact with a device via any device driver. Most of the device files are stored in /dev directory in Linux. Each device in the system should have an entry in /dev. These files are created during installing the system and device drivers. There are two different types of device files present in Linux operating systems.
  • Symbolic Links: - They are actually either the regular files or directories. A symbolic link is a reference to another file located in a disk. This file is stored as referenced file’s path. These files are denoted by ‘l’. It is also known as a soft link. Each soft link contains a different inode value which directs to the original file A hard link has the same inode value as the original file. For this, it remains linked even the original file is moved to another location, unlike a soft link file.

File Attributes

File attributes are used along with the computer files as settings. They are used to either allow or restrict certain operations for a user or for the operating system.

Attribute Meaning Functions
a append only This attribute permits a file to be added or appended only. It does not allow the removal of file.
c Compressed This attribute helps kernel to compress any data automatically written in a file and uncompress it when require.
d no dump It ensures that file is not backed up in backups where dump utility is used.
e extent format This attribute depicts that extent is used by file for mapping the blocks
i Immutable An immutable file cannot be removed, cannot be renamed and link can’t be created
j Journaling Journaling option guarantees that a file will be written in journal first and then to the disk
s source deletion It tells that a particular file cannot be recovered once it has deleted.
t no tail merging It is a process in which small part of data which do not feel a complete block are merged with similar field of data from other files.
u Undeletable The contents of a deleted file is saved which allows a utility to recover the deleted file
A no time updates Access timestamp will not update at a time accessing the file
D synchronous directory updates It ensures that the changes made to the file are written immediately in the disk
S synchronous updates It writes the changes made in the file synchronously in the disk
T top of directory hierarchy A directory is deemed to be the top of directory hierarchies

Directories in Linux

Linux stores all the data and programs in files. These files are contained in directories. A directory contains all the regular files, special files, other folders stored in a physical device. These files are denoted by the symbol ‘d’. Each shell and system process has a current working directory(cwd)

File Structure and hierarchy

The standard directories

  • /bin: - It contains the programs needed for using and managing the system. The commands found in this directory are date (displays today’s date), ls (lists the contents of a directory), and cp (makes a copy of a file).
  • /boot: - It contains the static files of the boot loader
  • /dev: - It contains system device files. A device file provides an interface to a particular device. Examples of devices having device files in /dev are disk drives, tape drives, or CDROM drives.
  • /etc: - It contains system specific configuration files, and files essential for system startup
  • /home: - This is the directory where the home directories for all users of the system are stored.
  • /lib: - Shared libraries and kernel modules are under this directory
  • /mnt: - This is the directory where temporary file systems are mounted. It may contain subdirectories like cdrom, floppy, and disk.
  • /opt: - It contains software files that are not installed when the operating system is installed. This directory usually contains products provided by third-party software vendors.
  • /sbin: - Programs for administering a system are located in this directory. The commands fdisk (used to partition a disk),fsck(used to check the integrity of a file system), and shutdown (used for stopping a system) are found under this directory
  • /tmp: - This directory is used to hold temporary files. This directory is generally referred to as a scratch directory, and can be used by all system users.
  • /usr: - It contains programs and files related to the users of a system. The data in /usr is typically read-only, and may be shared with other computer systems on a network.
  • /var: - Files with varying content are stored in this directory. It includes system log files, mail system files, and print spooling system files.
  • /srv: - It contains data for services provided by the system.
  • /media: - The /media directory is where external storage will be automatically mounted when you plug it in and try to access it. As opposed to most of the other items on this list, /media does not hail back to the 1970s, mainly because inserting and detecting storage (pen drives, USB) on the fly, while a computer is running is a relatively new thing.
  • /proc: - Contains all processes marked as a file by process number or other information that is dynamic to the system.
  • /sys: - /sys is another virtual directory like /proc and /dev and also contains information from devices connected to your computer.

File Permissions

Permissions is a set of characters describing access rights. There are 9 permission characters, describing 3 access types given to 3 user categories. The three access types are read (‘r’), write (‘w’), and execute (‘x’) and the three user categories are the user who owns the file, users in the group that the file belongs to and other users (general public). An ‘r’, ‘w’, or ‘x’ character means the corresponding permission is present; a ‘–‘ means it is absent.

On a Linux system, each file and directory is assigned access rights for the owner of the file, the member of a group of related users, and everybody else. Right can be assigned to read a file, to write a file, and to execute a file.

Octal Binary File mode
0 000 ---
1 001 --x
2 010 -w-
3 011 -wx
4 100 r--
5 101 r-x
6 110 rw-
7 111 rwx

Find the user Permissions:

ls -ls
- rw- r-- r--
  • rw-: - root user
  • r--: - normal
  • r--: - other

Set the Permissions: Sum of octal numbers for provide the permissions.

chmod +730 Result.txt
  • 7: - root user
  • 3: - normal user
  • 0: - other user

Denial the permissions:

chmod -777 Result.txt
  • 7: - root user
  • 7: - normal user
  • 7: - other user

File Management and Manipulation

  • pwd Command: - The pwd command displays the full absolute path to the current location in the file system.
  • ls Command: - The ls command lists the contents of a directory. If no target directory is specified, then the contents of the current working directory are displayed.
    • type: - is a single character which is either: d (directory), – (ordinary file), | (symbolic link), b (block-oriented device), c (character-oriented device)
    • permissions: - is a set of characters describing access rights. There are 9 permission characters, describing 3 access types given to 3 user categories. The three access types are read (‘r’), write (‘w’) and execute (‘x’) and the three user categories are the user who owns the file, users in the group that the file belongs to and other users (general public). An ‘r’, ‘w’, or ‘x’ character means the corresponding permission is present; a ‘–‘ means it is absent.
    • links: - refers to the number of the filesystem links pointing to the file or directory.
    • owner: - is usually the owner who created the file or directory
    • group: - denotes a collection of users who are allowed to access the file according to the group access rights specified in the permissions field.
    • size: - is the length of the file, or the number of bytes used by the operating system to store the list of files in a directory
    • date: - is the date when the file or directory was last modified (written to). The –u option displays the time when the file was last accessed (read).
    • name: - is the name of the file or the directory.
  • cd Command: - The cd command changes the current working directory.

Managing File System

Linux file system is organized as a tree or hierarchy of directories and files. i.e., all files and sub-directories are stored within directories. The tree or hierarchy starts with the root directory. There are several system directories and the home directories are found under the root directory. The forward slash is used as a separator of directories and files, where the first forward slash represents the root directory. For example, a subdirectory abc of the directory usr is shown as /usr/abc. Here, the first forward slash represents the root directory

Top

Comments

Popular posts from this blog

Introduction

Managing Packages & Users