Module-6-Y-Managing Linux File System
Module-6-Y-Managing Linux File System
In other words, if you save a file to a storage device, you should be able to find it
later on and retrieve it, assured that its contents will be exactly the same as
when it was saved
Types of Files
Linux supports seven types of files:
• Simple/ordinary file
• Directory
• Symbolic (soft) link
• Character special file
• Block special file
• Named pipe (also called FIFO)
• Socket
You can use the ls –l command to display the type of a file.
As you work with the Linux file system, one of the most common tasks you will
need to complete is to move around between the different directories on your
hard disks.
Your Linux system provides the following commands that you can use from the
shell prompt to do this:
■ pwd :The pwd command is a relatively simple utility. It simply displays the
current directory on the screen. (pwd stands for Present Working Directory.)
• This utility can be exceptionally useful if your shell profile hasn’t been configured to
display the current directory as a part of the shell prompt.
• To use pwd, simply enter pwd at the shell prompt. The ~ character in the shell prompt is
shorthand that refers to the current user’s home directory.
• At this point, you know how to identify what directory you’re in. More than
likely, you’re going to need to change to a different directory in the file system at
some point. Let’s discuss how to do this next
Using the cd Command
■ cd
You can also use absolute paths with the cd command. When you use an absolute path, you specify
the full path, starting from /, to the directory you want to change to.
• For example while in /home/Babcock one can issue the cd /var/log command. Because we
specified an absolute path, the cd command knew that the var/log directory didn’t exist in the
current directory. Instead, the path was determined from the root directory (/) and the current
directory was changed to it.
• If you enter cd at the shell prompt without specifying a path, it will automatically change
directories to the home directory of the currently logged-in user.
• You can also use the cd command to move up the file system hierarchy. You can do this by entering
cd .. . This will change the current directory to the next directory higher in the hierarchy. For
example if working at /var/log and the cd .. command is issued, it changes the directory from
/var/log to /var.
Using the ls Command
■ ls
The ls command is used to list the files and subdirectories that may exist within a
directory.
• If you enter ls at the shell prompt, the contents of the current directory are listed
on the screen.
• As with the cd command, you can also provide an absolute path when using ls.
This will cause ls to display the contents of the directory you specify.
• When working with ls, you can use a variety of options to customize how it
works. Some of these options include the following:
• –a Displays all files, including hidden files.
• –l Displays a long listing of the directory contents. This is a very useful option.
You can use it to see the file names, ownership, permissions, modification date,
and size.
Creating Files and Directories
• From time to time, you will need to create new files and directories in your Linux
file system.
Creating a new file can be accomplished using the touch command from the shell
prompt.
• To use touch, enter touch followed by the name of the file you want to create
• You can also use shell commands to create new directories.
This is done using the mkdir command.
• As with touch, you can enter mkdir from the shell prompt followed by the name
of the directory you want to create.
Example: $ mkdir mydocs
Create a file inside mydocs: $mydocs touch myfile
Viewing Text File Contents
• cat The cat filename command will display the specified text file on screen. This
command doesn’t pause the output, so if you use it to view a long file, you may
need to append |more to the command to pause the output a page a time.
• less The less filename command can also be used to display the specified text file
on screen, much like cat. However, the less command automatically pauses a long
text file one page at time. You can use the SPACEBAR, PAGEUP, PAGE DOWN, and
ARROW keys to navigate around in the file.
• head The head filename command is used to display the first couple of lines of a
text file on the screen.
• tail The tail filename command is used to display the last couple of lines of a text
file on screen. The tail command is particularly useful when displaying a log file on
screen. When viewing a log file, you probably only want to see the end of the file.
You probably don’t care about log entries made several days ago. You can use tail
to see just the last log entries added to the end of the file.
Deleting Files and Directories
■ rmdir This utility can be used to delete an existing directory. To use it, simply
enter rmdir directory_name
For example, rmdir MyFiles. Be aware, however, that rmdir requires that the
directory be empty before it will delete it.
■ rm The rm utility is a more powerful deletion utility that can be used to
delete either a file or a populated directory.
To delete a file,
simply enter rm filename.
To delete a directory,
enter rm –r directory_name.
Deleting Files and
Directories[ctd]
Copy Files and Directories
cp item1 item2: copies the single file or directory item1 to the file or directory item2.
Whereas
This command:
cp item... Directory: copies multiple items (either files or directories) into a directory
Useful Options and Examples
cp: Examples
mv—Move and Rename Files
The mv command performs both file moving and file renaming, depending on how it is used. In either
case, the original filename no longer exists after the operation.
mv is used in much the same way as cp, as shown here:
mv item1 item2: to move or rename the file or directory item1 to item2. It’s also used as follows
mv item... directory: mv shares many of the same options as cp, as described above
Useful Options and
Examples
File Security
File Security
• Password-based Protection
• Encryption-based Protection
Protection-based on Permission
• Types of Users
• Types of File Operations/Access Permission
Objectives
To show the protection and security mechanisms that Linux provides
• To describe the types of users of a Linux file
• To discuss the basic operations that can be performed on a Linux file
• To explain the concept of file access permissions/privileges in Linux
• To discuss how a user can determine access privileges for a file
• To describe how a user can set and change permissions for a file
• To discuss special protection bits, set-user-ID, set-group-ID, and sticky bit, and describe
their purpose
• To cover the following commands and primitives:
Introduction
In a time-sharing system like Linux there are great benefits. However, there is a main
challenge of protecting the hardware and software resources in it. These resources
include the input/ output devices, central processing unit (CPU), main memory, and the
secondary storage devices that store user files.