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

Linux Unit 3

The document discusses the Linux file system, including the root directory, common subdirectories, file permissions, and how to navigate and manage the file system. It covers file system concepts like paths, permission types for users and how to set permissions using chmod.

Uploaded by

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

Linux Unit 3

The document discusses the Linux file system, including the root directory, common subdirectories, file permissions, and how to navigate and manage the file system. It covers file system concepts like paths, permission types for users and how to set permissions using chmod.

Uploaded by

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

Unit 3: Introduction to Linux File System

 Introduction to The File System and Working with Linux Permissions


 File System Navigation,
 Managing The File System Understanding Permissions,
 Changing File And Directory Permissions
 Changing Default Permissions And Ownership

Que. 1: Explain the file system and file permissions in Linux (6)
Or Write short note on file permissions in Linux (3/4)
Answer:
Linux File System: The Linux file system contains the following sections:
A) The root directory (/)
B) A partition or logical volume having a particular file system.
C) A specific data storage format (EXT3, EXT4, BTRFS, XFS and so on)
A) Root Directory:- Linux file system considers everything as a file in Linux; whether it is text file images,
partitions, compiled programs, directories, or hardware devices. If it is not a file, then it must be a
process. Linux file system has a hierarchal file structure as it contains a root directory and its
subdirectories. All other directories can be accessed from the root directory. To manage the data, it
forms a tree structure.

Fig. – Hierarchical File system in Linux


Directory Description
 Primary hierarchy root and root directory of the entire file system hierarchy.
/  Every single file and directory starts from the root directory
 The only root user has the right to write under this directory
/usr Contains information related to all users.
 Contains binary executables
 Common linux commands you need to use in single-user modes are located under this
/bin
directory.
 Commands used by all the users of the system are located here e.g. ps, ls, ping, grep, cp
 Boot loader files (e.g., kernels, initrd).
/boot
 Kernel initrd, vmlinux, grub files are located under /boot
/dev  Essential Device files
 These include terminal devices, usb, or any device attached to the system.
 Example: /dev/tty1, /dev/usbmon0
 Host-specific system-wide configuration files.
 Contains configuration files required by all programs.
/etc  This also contains startup and shutdown shell scripts used to start/stop individual
programs.
 Example: /etc/resolv.conf, /etc/logrotate.conf.
/home  Users' home directories, containing saved files, personal settings, etc.
 Libraries essential for the binaries in /bin and /sbin .
/lib  Library filenames are either ld* or lib*.so.*
 Example: ld-2.11.1.so, libncurses.so.5.7

B) Partitions:- A Linux file system is a structured collection of files on a disk drive or a partition. A
partition is a segment of memory and contains some specific data. In our machine, there can be various
partitions of the memory. Generally, every partition contains a file system.
The general-purpose computer system needs to store data systematically so that we can easily
access the files in less time. It stores the data on hard disks (HDD) or some equivalent storage type.
C) Data storage format:- When we install the Linux operating system, Linux offers many file systems
such as Ext, Ext2, Ext3, Ext4, JFS, ReiserFS, XFS, btrfs, and swap.
Linux files are case sensitive, so test.txt and Test.txt will be considered as two different files.
There are multiple ways to create a file in Linux. Some conventional methods are as follows:
o using cat command
o using touch command
o using redirect '>' symbol
o using echo command
o using printf command
o using a different text editor like vim, nano, vi
Apart from all of the above methods, we can also create a file from the desktop file manager.
Working with Linux file permissions:
File ownership provides a secure method for storing files. Every file has the following attributes −
 Owner permissions − The owner's permissions determine what actions the owner of the file can
perform on the file.
 Group permissions − The group's permissions determine what actions can be performed by all users of
that group.
 Other (world) permissions − The permissions for others indicate what action all other users can
perform on the file.
All the above three owners in the Linux system have three types of permissions defined. Nine characters
denotes the three types of permissions.
1. Read (r) : The read permission allows you to open and read the content of a file. But you can't do any
editing or modification in the file.
2. Write (w) : The write permission allows you to edit, remove or rename a file. For instance, if a file is
present in a directory, and write permission is set on the file but not on the directory, then you can edit
the content of the file but can't remove, or rename it.
3. Execute (x): In Linux type system, you can't run or execute a program unless execute permission is
set.But in Windows, there is no such permission available.
Permissions are listed below:
Permission For a File For a Directory
r (read) read file content (cat) read directory content (ls)
w (write) change file content (vi) create file in directory (touch)
x (execute) execute the file enter the directory (cd)

Permission Set/ Access modes:


For exampls:
i) -rwxr-xr-- 1 amrood users 1024 Nov 2 00:10 myfile
ii) drwxr-xr--- 1 amrood users 1024 Nov 2 00:10 mydir
In above examples, there are ten characters for each entry.
Character Position Meaning
Denotes file type.
1 “-” Indicates a file and
“d” indicates a directory
2-4 (First triplet) Indicates the permission of the User
5-7 (Second triplet) Indicates the permission of the Owner
8-10 (Third triplet) Indicates the permission of the Other

Que. 2: Explain the file system navigation with example. (3 / 6) OR


What is file system navigation? How one can navigate in the file system?
Answer:
Concept: Iterate over files and directories under a specified path. Get information about files including the
time created, size, extension, and root directory. compose, decompose, and compare paths. create, copy, and
delete directories.
To navigate through the directories of your computer in a graphical interface, you're probably used
to opening a window to get "into" your computer, and then double-clicking on a folder, and then on a
subfolder, and so on. You may also use arrow buttons or keys to back track.
Concept of Path in file system: Navigation is based on the concept of paths. These paths specify what
directories to traverse to reach a particular subdirectory or file. There are two types of paths: Absolute
paths and relative paths.
1) Absolute path: An absolute path is a complete path to a resource, beginning at the filesystem's root.
The filesystem root is represented as a single forward slash: /
2) Relative path: Relative paths vary by your location in the filesystem, hence the term relative.
Therefore, the directories specified in the path change depending on where you are and where you're
going.
Commands used for navigating the linux file system:
Sr. Command Meaning Example
No.
1 tree To get a view of your Linux file system $ tree
hierarchy. The tree command lists the
contents of file systems in a tree-like
structure.
2 cd To navigate through your computer in the $ cd /etc/ssh
terminal
3 cd.. To move one directory back $ cd ..
4 cd To jump through many folders into a specific $ cd /etc/ssh/sshd_config ~
./path/to/another/ location.
folder
5 pwd Print working directory. It shows the $ pwd
current directory you are currently working
in.
6 ls List down all the content inside the directory. $ ls

Que. 3: How the permissions are set to file or directory? Explain with example. (6)
Answer:
File/Directory Access Modes: The permissions of a file are the first line of defense in the security of a
Linux system. The basic building blocks of file permissions are the read, write, and execute, which have
been described below −
 Read: Grants the capability to read, i.e., view the contents of the file.
 Write: Grants the capability to modify, or remove the content of the file.
 Execute: User with execute permissions can run a file as a program.
Changing Permissions
To change the file or the directory permissions, you use the chmod (change mode) command. There are two
ways to use chmod — the symbolic mode and the absolute mode.
Syntax:
chmod <groupName>+/-[=]<permissionName> <fileName>

 Using chmod in Symbolic Mode: The easiest way for a beginner to modify file or directory permissions
is to use the symbolic mode. With symbolic permissions you can add, delete, or specify the permission
set you want by using the operators in the following table.
Chmod operator Description
+ Adds the designated permission(s) to a file or directory.
- Removes the designated permission(s) from a file or directory.
= Sets the designated permission(s).

Examples:
$chmod o +wx testfile
$chmod u-x testfile
$chmod g=rx testfile
$chmod o =rw testfile
$chmod u =rwx,g=rw,o=r testfile
$chmod o +wx,u-x,g = rx testfile

 Using chmod in Absolute/ Numeric Mode: There are three user categories: User (the owner of the
file), Group (the security group you are in), and Other (for the world to see). Each category has three
permissions that can be set: r, w, and x to read, write, and execute a file, respectively. Permissions
consist of three numbers: 4 for Read, 2 for Write, and 1 for Execute access. By adding these numbers
together, you form the permissions that make up one digit. This table can be used as a quick reference:
Permission User Group Other
Read = 4 x x X
Write = 2 x
Execute = 1 x x X
Totals (4+2+1) = 7 (4 + 1) = 5 (4 + 1) = 5

For example, 4 + 2 + 1 = 7, which grants read, write, and execute permissions; 4 + 1 = 5, which grants only
read and execute permissions. Thus, 755 grants 7 (read, write, execute) to the owner of the file, and 5 (read
and execute) to the group the file is in and 5 (read and execute) to the world.
Examples:
1. Read by owner only $ chmod 400 sample.txt
2. Read by group only $ chmod 040 sample.txt
3. Read by anyone $ chmod 004 sample.txt
4. Write by owner only $ chmod 200 sample.txt
5. Write by group only $ chmod 020 sample.txt
6. Write by anyone $ chmod 002 sample.txt
7. Execute by owner only $ chmod 100 sample.txt
8. Execute by group only $ chmod 010 sample.txt
9. Execute by anyone $ chmod 001 sample.txt
10. Allow read permission to owner and group and anyone. $ chmod 444 sample.txt
11. Allow everyone to read, write, and execute file. $ chmod 777 sample.txt
12. Deny execute permission to everyone. $ chmod a-x sample.txt
13. Allow read permission to everyone. $ chmod a+r sample.txt
14. Make a file readable and writable by the group and others. $ chmod go+rw sample.txt
15. Make a shell script executable by the user/owner. $ chmod u+x samplescript.sh
Que. 4: Write short note on –
a) Changing the default permissions (4)
b) Changing the ownership of the files. (4)
Answer:
A) Changing the default permission: By default, on Linux systems, the default creation permissions
are 666 for files, which gives read and write permission to user, group, and others, and to 777 for
directories, which means read, write and execute permission to user, group, and others. Linux does not
allow a file to be created with execute permissions.
The umask command in Linux is used to set default permissions for files or directories. The
syntax is similar to that of chmod, but use the = operator to set the default permissions.
Syntax:
umask <permissions>
Example:
umask u=rwx,g=rwx,o=rx
The above command will give set read, write and execute permission to owner and group members. At the
same time it will set only read and execute permission to others.
 The umask command can be only used on new files i.e. while creating new files, any files created prior
to using the umask command will have no effect.
 The chmod command must be used on files that are already present, it is used to change the access
permissions of files that have been created earlier.
 Some common umask settings are as follows -

Umask code User Access Group Access Other


0000 all all all
0002 all all read, execute
0007 all all none
0022 all read, execute read, execute
0027 all read, execute none
0077 all none none

B) Changing the ownership of the files:


Linux chown command is used to change a file's ownership, directory, or symbolic link for
a user or group. The chown stands for change owner. In Linux, each file is associated with a
corresponding owner or group.
The Linux system may have multiple users. Every user has a unique name and user ID. If only a user is
available in the system, the user will be the owner of each file.
Syntax:
chown [OPTION]... [OWNER][:[GROUP]] FILE...
Options:
Following are the command-line options of the chown command:
a) -c, --changes: It is used to display the detailed output like verbose, but it is reported when only a
change is made.
b) -f, --silent, --quiet: It is used to suppress the error messages.
c) -v, --verbose: It is used to display a diagnostic for every processed file.
d) -R, --recursive: It is used to perform operations on files and directories recursively.
The Linux system may have multiple users. Every user has a unique name and user ID. If only a
user is available in the system, the user will be the owner of each file.
Examples:
i) Changing owner of file “file1.txt” to new owner as “master”
chown master file1.txt
ii) Changing Group of file “file1.txt” to new group as “adm”
chown :adm file1.txt
iii) Changing owner and group together for the above examples.
chown master:adm file1.txt
****

You might also like