0% found this document useful (0 votes)
24 views17 pages

CH 2

Chapter 2 discusses the file system in Unix and GNU Linux, explaining its structure, functionalities, and management commands. It covers file paths, types of links, and common file types, emphasizing the hierarchical organization of files and directories. The chapter also provides examples of commands for managing directories and files, including creating, removing, and copying files.

Uploaded by

Amina Chikhaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views17 pages

CH 2

Chapter 2 discusses the file system in Unix and GNU Linux, explaining its structure, functionalities, and management commands. It covers file paths, types of links, and common file types, emphasizing the hierarchical organization of files and directories. The chapter also provides examples of commands for managing directories and files, including creating, removing, and copying files.

Uploaded by

Amina Chikhaoui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Chapter 2 – File System Unix: GNU Linux

Operating System

A. Chikhaoui

2023-2024
File System

A file system (FS) is a way of organizing and storing files on a computer.


It provides a structure that allows for efficient storage, retrieval, and manipulation of
data.
A FS offers the user an abstract view of their data (a tree of files and directories) and
allows them to be located using a path.

1 16
Functionalities of a FS

Manage used and free blocks on the disks;


Manage multiple files;
Manage multiple devices;
Manage user permissions
, etc.

2 16
Files and Directories

Files are logical units for storing information. There are many types of files such
as text, audio, script, etc.
Directories are containers that hold sets of related files.
Each file name within a directory has to be unique.
UNIX is case-sensitive i.e., the file example.txt is different from the file
Example.txt
Directory names are also case-sensitive.

3 16
Typical structure of UNIX FS

Unix uses a hierarchical file system structure, much like an upside-down tree, with root
(/) at the base of the file system and all other directories spreading from there

4 16
File paths

A File path specifies the location of a file or directory within the file system hierarchy.
There are two types of file paths: absolute paths and relative paths.
1. Absolute Paths:
An absolute path specifies the full path from the root directory ("/") to the target file or
directory.
Example: /home/user/documents/file.txt
In this example, / is the root directory, home is a subdirectory of the root, user is a subdirectory
of home, and so on.
2. Relative Paths:
A relative path specifies the location of a file or directory relative to the current working
directory.
It does not start with a forward slash.
Example: If the current working directory is /home/user/, a relative path to the file might be
documents/file.txt.

5 16
Common elements used in Unix file paths

. (Dot): Represents the current directory. For example, ./file.txt refers to a file in the
current directory.
.. (Double Dot): Represents the parent directory. For example, ../file.txt refers to a file
in the parent directory.
∼ (Tilde): Represents the home directory of the current user. For example, ∼/file.txt
refers to a file in the user’s home directory.
/ (Forward Slash): Path separator used to separate directory and file names.

6 16
Unix directory and file management commands

Command Desciption Examples


mkdir makes (creates) an empty directory $mkdir dir1
$mkdir -p dirParent/dirChild
rmdir removes empty directories $rmdir dir1
$rmdir -p dirParent/dirChild
cd change the current working directory cd /usr/share/
cd .. (go to parent directory)
pwd print working directory $cd /usr/share/doc
$cd ..
$pwd
/usr/share

7 16
Unix directory and file management commands

ls lists the contents of a directory $ls


Some options: Rep texte1 texte2 texte3
-l: long format, displaying addi- $ls -a
tional information such as permis- . .. Rep texte1 texte2 texte3
sions, owner, group, size.
-a: include hidden files and directories
(those starting with a dot)
-h: Human-readable sizes (e.g., KB,
MB)
-R: Recursive listing, showing the con-
tents of subdirectories.

8 16
Unix directory and file management commands

cp is used to copy files and directories. $cp fileS fileD


Some options: $cp -r dirS dirD
-r or -R: Copy directories recursively.
-i: Prompt before overwriting files.
-a: preserve file attributes, permissions, and owner-
ship.

9 16
Unix directory and file management commands

mv move or rename files and directories. $mv -f fileS fileD


Some options
-i: prompts the user for confirmation before over-
writing an existing destination file.
-f: forces to move without prompting.
-v: makes the command more verbose.
rm removes or deletes files and directories. rm *.tmp
Some options
-i: prompts for confirmation before removing each
file.
-f: forces the removal without prompting.
-r: deletes the contents of a directory recursively

10 16
Unix directory and file management commands

touch creates empty files or updates the timestamp of touch fileName


existing files.

cat concatenates and displays the content of files. $ cat file1


This command displays
the content of file1.
$ cat file1 file2 file3
This command concate-
nates the content of
multiple files and dis-
plays the result in the
terminal.
more allows users to view text files one screen at a time.

less Same as more

11 16
Unix directory and file management commands

head displays the first 10 lines of a file. head -n 5 filename


The option -n allows us to specify the number of
lines to display.
tail displays the last ten lines of a file. tail -n 15 filename
The option -n allows us to specify the number of
lines to display.
nl this command is used to number lines in a file. nl /etc/passwd
wc this command is used to count the number of lines,
words, and bytes (or characters) in a file.

12 16
Links

Links are a way to associate multiple filenames with the same file or directory.
There are two types of file links:
1. Hard links.
2. Symbolic (soft) links.

13 16
Hard Links

Associates two or more files with the same disk space.


The file will be deleted only if all these hard links are removed

To create a hard link, you can use the ln command as follows:

14 16
Symbolic Links

A symbolic link, or symlink, is a separate file that contains a path to another file or
directory. It acts as a pointer or reference to the target file or directory.
If the source file is deleted then the link will be considered "broken".

To create a symbolic link, use the -s option with the ln command:

15 16
Common file types in Unix

The file type is often indicated by the first character in the output of the "ls -l" command.
Following are the common file types in Unix:
1. Regular File (-): Regular files contain user data, such as text files, binary executables, or
any other file type.
2. Directory (d): Directories are files that contain references (or entries) to other files and
directories. They provide a way to organize and structure the file system hierarchy.
3. Symbolic Link (l): Symbolic links, or symlinks, are files that point to another file or
directory. They act as references to the target file and can span filesystems.

16 / 16

You might also like