0% found this document useful (0 votes)
9 views40 pages

5 Introductionto Operating Systems 1

The document provides an overview of files and directories in Unix systems, explaining that everything is treated as a file, including input and output devices. It details the structure of directories, commands for navigating and managing files, types of files, and the hierarchical file system. Additionally, it covers special files, pathnames, and the purpose of various important directories within the Unix file system.

Uploaded by

zenda1551
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)
9 views40 pages

5 Introductionto Operating Systems 1

The document provides an overview of files and directories in Unix systems, explaining that everything is treated as a file, including input and output devices. It details the structure of directories, commands for navigating and managing files, types of files, and the hierarchical file system. Additionally, it covers special files, pathnames, and the purpose of various important directories within the Unix file system.

Uploaded by

zenda1551
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

Linux files and

directories
Dr Marir
What is a file?

• File is a container for storing content, records or


information.
• Input and output devices are also considered to be files in
Unix system. It's a way of simplifying how the computer
handles information.
• Files on the Unix system are grouped into directories,
same as folders in Windows environment.
What is a file?

Files as Input and Output Devices


In Unix systems, everything is treated as a file. This includes not just
the boxes (files) where you store information, but also the ways you
interact with the computer.
For example, when you use the keyboard (an input device), Unix
thinks of it as if you're sending information to a special kind of file.
The same goes for when you see things on your screen (an output
device); Unix treats the screen like a file where information is being
shown.
Directories and sub-directories
• Directory within a directory is called as a sub-directory
• Each directory can contain multiple sub-directories and/or files
• In Unix , a directory is also a file containing the names of others
files
• The structure of directories in Unix is called as tree
• All types of operations are possible for directories and files such as
create, delete, copy, move, split and so on
• A directory can be a file, but a file cannot be a directory since, file
contains the information/records and directory contains sub-
directories and files
Directories and sub-directories
The working directory
While you are logged in on a Unix system, you will always be associated with one
directory or another. The directory you are associated with, or are working in, is called
the working directory, or the current directory.
Your home directory
When you first log in on a Unix system, the working directory is your home directory.
You own this directory and any subdirectories or files created within or below it.
The . and .. directory entries
Whenever a new directory is created using the mkdir utility, two entries are
automatically placed in it. They are a single and double period, representing the
directory itself and the parent directory, respectively. These entries are invisible
because their filenames begin with periods.
Directories and sub-directories
Special Files and Directories
. Represents the current directory.
.. Represents the parent directory.
~ Represents the home directory of the current user.

So, your working directory is like the folder you're currently inside,
your home directory is where you start, and these hidden dots (.)
and (..) help you move around between folders. It's a bit like having
a map of the places you're in and where they connect.
Directories and sub-directories
Commands
Navigating Directories
cd: Change the current working directory. Example: cd /path/to/directory
pwd: Print the current working directory.
ls: List the contents of a directory.
Managing Files and Directories
cp: Copy files or directories. Example: cp [Link] [Link]
mv: Move or rename files or directories. Example: mv old_name.txt
new_name.txt
rm: Remove files or directories. Example: rm [Link]
mkdir: Create a new directory. Example: mkdir new_directory
rmdir: Remove an empty directory.
Types of Files in Unix
Types of Files in Unix

1. Ordinary Files / Regular Files

• Used to store your information, such as some text you


have written or an image you have drawn.
• This is the type of file that you usually work with.
• Always located within/under a directory file
• Do not contain other files
• In the long-format output of ls -l, the "-" symbol is used to
specified such kind of file.
Types of Files in Unix
2. Directories
• Branching points in the hierarchical tree
• Used to organize groups of files
• May contain ordinary files, special files or other directories
• Never contain "real" information which you would work with (such
as text). Basically, just used for organizing files.
• All files are descendants of the root directory, ( named / ) located at
the top of the tree.
• In the long-format output of ls -l, we used the "d" symbol in order
to specify this kind of file.
Types of Files in Unix
3. Special Files { Character Devices or Block Devices}:
• Used to represent a real physical device such as a printer, tape drive or terminal,
used for Input/Ouput (I/O) operations
• Unix considers any device attached to the system to be a file - including your
terminal
• By default, a command treats your terminal as the standard input file (stdin) from
which to read its input
• Your terminal is also treated as the standard output file (stdout) to which a
command's output is sent
• Usually only found under directories named /dev
• In the long-format output of ls -l, using the "c" symbol character distinct, files are
marked. In the long-format output of ls -l, using the "b" symbol block, distinct
files are marked.
3. Special Files
Identifying Special Files:
a. Character Devices (c):
Symbol: Represented by the "c" in the first column of the ls -l output.
Data Transfer: Character devices transfer data one character at a time.
Example: A keyboard is a character device because when you press a key, it sends one
character to the computer.
Real-Life Analogy: Think of it like talking to someone on the phone. You speak one word at
a time, and the person on the other end hears you one word at a time.
b. Block Devices (b):
Symbol: Represented by the "b" in the first column of the ls -l output.
Data Transfer: Block devices transfer data in blocks or chunks, not one character at a time.
Example: A hard drive is a block device because when you save a file, it doesn’t save one
character at a time. Instead, it saves chunks of data to be more efficient.
Real-Life Analogy: Think of it like sending a package through the mail. You don’t send one
Types of Files in Unix
4. Pipes
• UNIX allows you to link commands together using a pipe. The pipe acts a
temporary file which only exists to hold data from one command until it is read
by another
• For example, to pipe the output from one command into another command: who |
wc -l This command will tell you how many users are currently logged into the
system. The standard output from the who command is a list of all the users
currently logged into the system. This output is piped into the wc command as its
standard input. Used with the -l option this command counts the numbers of lines
in the standard input and displays the result on its standard output - your terminal.
• In the long-format output of ls -l, known as pipes, are marked using the symbol
"p."
Types of Files in Unix
Sockets
• Unix sockets are a type of file that enables for advanced inter-
process communication. It is also known as inter-process
communication socket. In the framework of the client-server
application, a Unix Socket is used. It is essentially a data stream,
same as the network stream and network socket, except each
transaction is local to the file system.
• In the long-format output of ls -l, using the "s" symbol, Unix
sockets are marked.
Types of Files in Unix
Symbolic Link
• The symbolic link is used to reference another file in the file system. In order to
reference another file of the file system, we use the symbolic link. It involves a
text representation of the path to the file it refers to. To an end-user, a symbolic
link will seem to have its own name, yet when we need writing or reading data to
this file, it will rather reference these tasks to the file it focuses to. When we
delete the soft link itself, then the data file would, in any case, be there. The
symbolic file will not function if the source file is deleted or moved to the
different location.
• In the case of the long-format output of ls -l, using the "l" symbol, the symbolic
link is marked.
File Names
• UNIX permits file names to use most characters, but avoid
spaces, tabs and characters that have a special meaning to the
shell, such as: & ; ( ) | ? \ ' " ` [ ] { } < > $ - ! /
• Case Sensitivity: uppercase and lowercase are not the same!
These are three different files:
NOVEMBER November november
• Extensions: may be used to identify types of files libc.a -
archive, library file program.c - C language source file
alpha2.f - Fortran source file xwd2ps.o - Object/executable
code mygames.Z - Compressed file
File Names
• Hidden Files: have names that begin with a dot (.) For example:
.cshrc .login .mailrc .mwmrc
• Uniqueness: as children in a family, no two files with the same
parent directory can have the same name. Files located in
separate directories can have identical names.
• Reserved Filenames:
/ the root directory (slash)
. current directory (period)
.. parent directory (double period)
~ your home directory (tilde)
Hierarchical File Structure

• All of the files in the UNIX file system are organized into a multi-
leveled hierarchy called a directory tree.
• At the very top of the file system is single directory called "root"
which is represented by a / (slash). All other files are "descendents"
of root.
• The number of levels is largely arbitrary, although most UNIX
systems share some organizational similarities.
Unix file system hierarchy
/ directory

The root directory, represented by a forward slash (/), stores


all the directories in Linux.
The /boot Directory

/boot directory contains everything required for the boot process


except for configuration files not needed at boot time (the most
notable of those being those that belong to the GRUB boot-loader)
and the map installer. Thus, the /boot directory stores data that is
used before the kernel begins executing user-mode programs. This
may include redundant (back-up) master boot records, sector/system
map files, the kernel and other important boot files and data that is
not directly edited by hand.
The /bin and /sbin Directories

/bin is a standard subdirectory of the root directory in Unix-


like operating systems that contains the executable (binary) (i.e.,
ready to run) programs that must be available in order to attain
minimal functionality for the purposes of booting (i.e., starting) and
repairing a system.

Common command-line utilities are stored here, such as ls, cp, and
mv.
The /bin and /sbin Directories

The /sbin contains binaries to configure the operating system. The


‘/sbin’ directory also contains executable files, but unlike ‘/bin’ it
only contains system binaries which require root privilege to perform
certain tasks and are helpful for system maintenance purpose. e.g.
fsck, root, init, ifconfig, etc. Many of the system
binaries require root privilege to perform certain tasks.
The /usr Directories

The /usr directory stores user-related data, including user commands,


libraries, and documentation.
Installed software, shared libraries, include files, and static read-only
program data. Important subdirectories include:-
* /usr/bin: User commands.
* /usr/sbin: System administration commands.
* /usr/local: Locally customized software.
The /dev Directory

The /dev directory is the location of special or device files. Look


through this directory and you should hopefully see sda1, sda2 etc....
which represent the various partitions on the first drive of the system.
/dev/cdrom represents your CD-ROM drive.
The /dev Directory
The /etc Directory

The /etc hierarchy contains configuration files. A "configuration file"


is a local file used to control the operation of a program;
It includes files like passwd and fstab.
The /var Directory

/var : Files that dynamically change (e.g. databases, cache directories,


log files, printer spooled documents, and website content) may be
found under /var.
The /home Directory

/home : User home directories are located in the /home directory.


Each user has their own subdirectory here for personal files and
settings.
The /lib Directory

The /lib directory contains those shared library images needed to boot
the system and run the commands in the root filesystem is a fairly
standard concept, but it is clearly a site-specific filesystem. 6 The
setup will differ from host to host
Removable media: the /media, /run and /mnt
Directories

This directory contains subdirectories which are used as mount points


for removable media such as floppy disks, cdroms and zip disks.
Pathnames
Pathnames
Absolute Pathnames: Specify a file/directory location in relation to the
root directory. Example: /home/user/Documents
Relative Pathnames: Specify a file/directory location in relation to the
current directory. Example: Documents (if the current directory is
/home/user)
Navigating Directories
cd: Change the current working directory. Example: cd /path/to/directory
pwd: Print the current working directory.
ls: List the contents of a directory.
Recap
Sub files
directories
Root Directories
Pathnames
• Specify where a file is located in the hierarchically organized file
system
• Must know how to use pathnames to navigate the UNIX file system
• Absolute Pathname: tells how to reach a file begining from the root;
always begins with / (slash). For example:
/usr/local/doc/training/sample.f
• Relative Pathname: tells how to reach a file from the directory you are
currently in ( current or working directory); never begins with / (slash).
training/sample.f
../bin
~/projects/report.001
Pathnames

For example, if your current directory is /usr/home/naila and


you wanted to change to the directory /usr/home/guest, you
could use either of these commands:
•cd ../guest - relative pathname
•cd /usr/home/guest - absolute pathname
Absolute Pathnames
Relative pathnames
Using Absolute and Relative Pathnames
You might be wondering when you should use absolute pathnames
and when you should use relative pathnames. It is entirely a question
of convenience.
If you need to name a directory that is ``close to'' your working
directory, then relative pathnames are quite convenient. This will
usually be the case, since you'll do most of your work in or near your
home directory.
On the other hand, if you need to name a directory that is ``far away
from'' your working directory, then you should use an absolute
pathname.

You might also like