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

Lecture 5

Uploaded by

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

Lecture 5

Uploaded by

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

Systems Programming (CS 423)

Lecture 5:

Users, Files, and Directories

Dr. Mohamed Abbas Alameen Saleh


Introduction to Linux
UNIX OS:
• Unix is a multi-user, multi-tasking operating
system.
• You can have many users logged into a system
simultaneously, each running many programs.
• It's the kernel's job to keep each process and
user separate and to regulate access to system
hardware, including cpu, memory, disk and other
I/O devices.
What is LINUX:
• Linux is a free Unix-type operating system
originally created by Linus Torvalds with the
assistance of developers around the world.
• It originated in 1991 as a personal project of Linus
Torvalds, a Finnish graduate student.
• The Kernel version 1.0 was released in 1994 and
today the most recent stable version is 2.6.9
• Developed under the GNU General Public License
, the source code for Linux is freely available to
everyone.
UNIX Structure:
UNIX File System:
File System:

• The Unix file system looks like an inverted tree


structure.
• You start with the root directory, denoted by /,
at the top and work down through sub-
directories underneath it.
File System (Cont’d):
• Each node is either a file or a directory of files,
where the latter can contain other files and
directories.
• You specify a file or directory by its path name,
either the full, or absolute, path name or the one
relative to a location.
• The full path name starts with the root, /, and
follows the branches of the file system, each
separated by /, until you reach the desired file,
e.g.:
• /home/condron/source/xntp
File System (Cont’d):
• A relative path name specifies the path relative
to another, usually the current working directory
that you are at. Two special directories :
o . the current directory
o .. the parent of the current directory
• So if I'm at /home/frank and wish to specify the
path above in a relative fashion I could use:
• ../condron/source/xntp
• This indicates that I should first go up one
directory level, then come down through the
condron directory, followed by the source
directory and then to xntp.
Structure of Standard Directories in Unix/Linux:
• / The ancestor of all directories on the system; all
other directories are subdirectories of this
directory, either directly or through other
subdirectories.
• /bin Essential tools and other programs (or
binaries).
• /dev Files representing the system's various
hardware devices. For example, you use the file
`/dev/cdrom' to access the CD−ROM drive.
• /etc Miscellaneous system configuration files,
startup files, etc.
Structure of Standard Directories in Unix/Linux (Cont’d):

• /home The home directories for all of the


system's users.
• /lib Essential system library files used by tools in
`/bin'.
• /proc Files that give information about current
system processes.
• /root The superuser's home directory, whose
username is root. (In the past, the home
directory for the superuser was simply `/'; later,
`/root' was adopted for this purpose to reduce
clutter in `/'.)
Introduction to Linux
Structure of Standard Directories in Unix/Linux (Cont’d):
• /sbin Essential system administrator tools, or
system binaries.
• /tmp Temporary files.
• /usr Subdirectories with files related to user tools
and applications.
Directories, Files, and Inodes:
• Every directory and file is listed in its parent
directory.
• In the case of the root directory, that parent is
itself.
• A directory is a file that contains a table listing the
files contained within it, giving file names to the
inode numbers in the list.
• The information about all the files and directories
is
maintained in INODE TABLE
• An Inode (Index Nodes) is an entry in the table
containing information about a file (metadata)
including file permissions, UID, GID, size, time
stamp, pointers to files data blocks on the disk
etc.
Users, Groups, and Access Permissions:
• In UNIX/LINUX, there is a concept of user and an
associated group
• The system determines whether or not a user or
group can access a file or program based on the
permissions assigned to them.
• Apart from all the users, there is a special user
called Super User or the root which has permission
to access any file and directory
Access Permissions:
• There are three permissions for any file, directory
or application program.
• The following lists the symbols used to denote
each, along with a brief description:
• r — Indicates that a given category of user can
read a file.
• w — Indicates that a given category of user can
write to a file.
• x — Indicates that a given category of user can
execute the file.
Access Permissions (Cont’d):
• Each of the three permissions are assigned to
three defined categories of users.
• The categories are:

owner — The owner of the file or


application.
group — The group that owns the file or
application.
others — All users with access to the
system.
Access Permissions (Cont’d):
• One can easily view the permissions for a file by
invoking a long format listing using the command
ls -l.
• For instance, if the user juan creates an
executable file named test, the output of the
command ls -l test would look like this:

o -rwxrwxr-x 1 juan student 0 Sep 26 12:25 test


Access Permissions (Cont’d):
• The permissions for this file are listed are listed at
the start of the line, starting with rwx.
• This first set of symbols define owner access.

• The next set of rwx symbols define group access

• The last set of symbols defining access permitted


for all other users.
Access Permissions (Cont’d):
• This listing indicates that the file is readable,
writable, and executable by the user who owns
the file (user juan) as well as the group owning
the file (which is a group named student).
• The file is also world-readable and world-
executable, but not world-writable.
Introduction to Linux
Listing the Content of a Directory:
• ls is used to list the contents of a directory.

• If the command ls is written with parameter –l


then the command lists contents of the working
directory with details. Example:
o $ ls –l
Moving in Directories:
• cd try_it: Changes the directory to try_it
• pwd: Prints present working directory (e.g.
/home/smith/try_it)
• cd ..: Move to superior directory
• pwd : Prints /home/smith
• cd /home The absolute path
• pwd : Prints /home
• cd The system is returned to the user home
directory
• pwd : Print /home/smith
Introduction to Linux
Make Directory:
• The command mkdir my_dir
o makes new directory my_dir (the path is given
relative) as a subdirectory of the current directory.
Remove Directory:
• The command rmdir your_dir
o removes directory your_dir if it is empty.
Copy File:
• The command cp file_1 file_2

• copies file_1 to file_2. The both files must be in the


same working directory. If they are in various
directories, the path must be given.
Rename and/or Move the File:
• The command mv file_1 file_2
o moves file_1 to file_2

• The both files must be in the same working


directory.

• If they are in different directories, the path must


be given.

• The file_1 is removed from the disk.


Remove File:
• The command rm file_a
o removes the file_a from the system
• If you use wildcard. For example
o rm h*c
• you will remove all files beginning with h and
ending with c which are in working directory.
• If you write
o rm *
• you will erase all files from your working directory.
Access Permission of File/Directory:
• The ownership of the file or directory can be
changed using the command
o chown <owner> <file/directory name>

• The group of the file or directory can be changed


using the command
o chgrp <group> <file/directory name>

• The permissions of the file can be changed using


chmod command
o chmod -R ### <filename or directory>

• -R is optional and when used with directories will


traverse all the sub-directories of the target
directory changing ALL the permissions to ###.
Access Permission of File/Directory (Cont’d):
• The #'s can be:
0 = Nothing
1 = Execute
2 = Write
3 = Execute & Write (2 + 1)
4 = Read
5 = Execute & Read (4 + 1)
6 = Read & Write (4 + 2)
7 = Execute & Read & Write (4 + 2 + 1)
Thanks ...

You might also like