What Is Linux / Unix?: Applications: The Highest Functional Layer. This Layer Includes Software
What Is Linux / Unix?: Applications: The Highest Functional Layer. This Layer Includes Software
The kernel, the file system and utilities, and the shell are the main components of
the Linux OS
Kernel: the core of the OS
o only one kernel can run per system
o gets loaded into in the main memory during power up
o manages resources so that multitasking can take place
File system: for data storage
o data are organized into files
o files are organized into directory structures
Shell: how the user interfaces with the OS
o the shell interprets what the user types on the keyboard so it can be run
by the system
o there can be more than one shell running at a time
o the shell also coordinates multiple commands in a file and acts as a
programming language
Utilities: tools to help a user do work on the system
o also called commands
o there are many utilities, each utility is supposed to do one task and do it
well
o they are programs that are run by the user to do specific tasks, such as
copy a file, send email, communicate with another user, check system
resources
Files in Linux
1. regular file: a file of data. Data can be text (human readable) or binary (machine
readable)
2. directory: a file that can “contain” other files (equivalent to folders in Windows)
3. character special file: IO device that processes one character at a time, such as a
printer
4. block special file: IO device that processes a block of characters at a time, such as
a hard disk
5. symbolic link: a file that holds the address of another file
Directories
Directories help you organize files by providing ways to group similar files
together
In Linux, files are grouped into directories (which themselves are files), and
directories are grouped under other directories, in “tree” form called a directory
tree or directory hierarchy
Each file in the hierarchy is called a node
The top node is called root
Except for root, each node can have
o 1 node above it, called its parent node
o 0 or more nodes below it, called its child nodes
A parent directory can have directory child nodes, called subdirectories
Root Directory
Home Directory
Every user is assigned a unique directory to store his / her files. This directory is
called the home directory
It has the same name as your log in name
You cannot change your home directory name or its location in the system
When you first log in the system, you are at the home directory
Often you will not be at the home directory. Instead you will move to a different
directory, depending on the task you are doing. The directory where you are
working is called the current directory or the working directory
Directory Path
Since the Linux directory tree is a huge hierarchy of files, it is important to know
the path to a file in order to access it
The path of a file is the location of the file in the directory tree
A path is formed by
o listing node names that are connected to each other in the tree structure
o separate node names with / (not the same as root)
2 types of paths: absolute path and relative path
Absolute path
o Shows the location of a file, starting from root /
o The absolute path of a file will not change unless the file is moved to
another place in the hierarchy
Relative path
o Shows the location of a file, starting from your current directory
o Since the relative path is relative to your current directory, the relative path
of a file will change if you change your current directory
Assume your home directory is ImaStudent:
pwd and cd
pwd: (for print working directory) shows the absolute path of where you are in
the directory tree
ls and Directories
Recall:
o ls will list filenames in the current directory
o ls filename will echo filename if file exists and is a regular file
If filename is the name of a directory, then ls will list filenames under that
directory
To see the file type of a file:
o Use the long listing: ls –l
The first character in the mode column will tell you the file type:
d for directory, l for link, - for regular file
o Use: ls –F
The filenames will be listed with an additional symbol at the end:
/ for directory, @ for link, * for executable regular file, nothing
for text file (which is also a regular file)
mkdir: (for make directory) creates a new directory in the current directory, or
under a different directory if a path is given
o Common format: mkdir directory_name
o When first created, the directory is an empty directory (no files in it, except
2 hidden files . and ..)
rmdir: (for remove directory) deletes an empty directory
o If the directory is not empty, you must delete all files in it first
o Common format: rmdir directory_name
o Alternatively, to remove a non-empty directory, use rm –r
directory_name where -r is for recursive
o Removes the directory and recursively go down all its subdirectories and
remove all the files under them
o Caution: this can remove a large number of files, make sure you don’t run
this command ‘by accident’
cp and Directories
Recall that cp will copy the source file to the destination file. Now we discuss all
the combinations of cp with regular files and with directories
o File below means regular file, Dir below means directory
Copying a source regular file
o cp existingFile nonExistingFile new nonExistingFile is created
o cp existingFile1 existingFile2 existingFile2 is overwritten
o cp existingFile nonExistingDir new regular file created with the
name of nonExistingDir
o cp existingFile existingDir new file called existingFile created
under existingDir
o Copying a source directory (need to use –r option, for recursively copy, all
files and subdirectories will also get copied)
o cp –r existingDir nonExistingDir new nonExistingDir is created
o cp –r existingDir1 existingDir2 existingDir1 is copied and put
under existingDir2
o cp –r existingDir nonExistingFile new directory called nonExistingFile
is created
o cp –r existingDir existingFile not possible
mv and Directories
Recall that mv will move the source file to the destination file, and the source file
will no longer exist. Now we discuss all the combinations of mv with regular files
and with directories
o File below means regular file, Dir below means directory
Move a source regular file
o mv existingFile nonExistingFile new nonExistingFile is created
o mv existingFile1 existingFile2 existingFile2 is overwritten
o mv existingFile nonExistingDir new regular file created with the
name of nonExistingDir
o mv existingFile existingDir new file called existingFile created
under existingDirectory
o Moving a source directory (don’t need option, all files and subdirectories
will move)
o mv existingDir nonExistingDir new nonExistingDir is created
o mv existingDir1 existingDir2 existingDir1 moves under existingDir2
o mv existingDir nonExistingFile new directory called nonExistingFile
is created
o mv existingDir existingFile not possible
File Permissions
Linux makes it easy for users to share data, but only if the owner of the file allows
his/her file to be shared.
The file owner is the user who created the file. The owner can set permissions for
the file to allow or deny access to the file
The types of permissions that can be set: read, write, execute
The file owner always has permission to his / her own files by default
If the file owner changes a file’s permission so that there is no access to the file,
s/he can always change that file’s permission so that there is access again
Note: even if the owner of a file gives no access to the file, system administrators
with root or superuser login ID still has full access to the file (read, write, and
execute permission)
Types of Permissions
Levels of Permissions
3 levels of permission:
o u : (for user) permission for the owner of the file
o g: (for group) permission for the group in which the file owner belongs.
Each user belongs to at least 1 group, as set by system admin. Your
group choice is most likely dependent on your job in your organization.
o o: (for other) permission for all users who are not the owner or who don’t
belong in the same group as the owner
Each level of permission contains all 3 types of access (r,w,x)
This means that for each file you own, you can set r,w,x access for yourself (as
owner), r,w,x access for users in your group, and r,w,x access for all other users
The 3 types of permission at each of the 3 levels make up the 9 characters of the
mode of the file
Mode
A file permission can be changed only by the owner of the file or by system
admin with superuser (or root) privilege
chmod: (for change mode) changes the permission of a file
2 ways to use chmod: symbolic and absolute
Symbolic format for chmod: chmod who operator permission filename
o where
who: u (user), g (group), o (other), a (all)
a means u and g and o
operator: + (add), - (remove), = (set)
For add and remove, the existing permission is modified by
the specified add or remove
For set, the existing permission is overwritten by the
specified permission
permission: r (read), w (write), x (execute)
filename: can contain a path and/or can be a file list
o The who, operator, and permission arguments have no space in between
them on the command line
Special cases
To apply a permission to all levels (owner, group, others), use a for the who field
o Example: chmod a-x filename
Remove execute permission for all levels
To remove all permissions for one level, set the permission to nothing
o Example : chmod o= filename
Remove all permission for others
Since regular files do not have execute permission by default, add execute
permission for all levels: chmod +x filename