Linux Specialization Course 1 Module 3
Linux Specialization Course 1 Module 3
© LearnQuest 2015
2021
View, Create, Copy, Move and Remove Files
In the third module of this course, we will learn how to manage files
and directories in the Linux operating system.
2 © LearnQuest 2021
Learning Objectives
View, Create, Copy, Move and Remove Files
• Remove Files
4 © LearnQuest 2021
ls Command Deep Dive (part I)
ls [options] [paths]
5 © LearnQuest 2021
ls Command Deep Dive (part II)
• -l: list the files in long format i.e. with an
index number, owner name, group
name, size, and permissions.
7 © LearnQuest 2021
File Commands Review
• cat – list the contents of a file on the
standard output
8 © LearnQuest 2021
Lesson 1
Review Touch command can create new
files
9 © LearnQuest 2021
Lesson 2 In this lesson, we look at how you
can create links in the file system
Files and Directory Links that point to other files or
directories
10 © LearnQuest 2021
Hard Link
A file (or directory) with one index
(inode) number and at least two
different file names.
• ln [originalfilename] [linkname]
12 © LearnQuest 2021
Soft Link
A file with different index (inode)
numbers. The soft link file points to
other file.
• ln –s [originalfilename] [linkname]
14 © LearnQuest 2021
Lesson 2
Review If you delete the original file with a
hardlink, the link still works
15 © LearnQuest 2021
Lesson 3 In this lesson, we look at how to
read complete and parts of files
Reading Files
from the Linux command line.
16 © LearnQuest 2021
Linux Text Files
Linux systems contain many text files.
They include
• configuration files
• log files
• data files
• plus, others
Example Usage:
Options:
Example Usage:
• pr –m file1.txt file2.txt
Options:
Help you find a file line (or lines) that contain certain text
strings.
20 © LearnQuest 2021
Head Command
Example Usage:
•head –n 5 /etc/passwd
Options:
•-n: the number of file lines to display.
21 © LearnQuest 2021
Tail Command
Example Usage:
•tail –n 5 /etc/passwd
Options:
•-n: the number of file lines to display.
22 © LearnQuest 2021
Pager Commands
Example Usage:
One way to read through a large •less /etc/passwd
file’s text is by using a pager. A
pager utility allows you to view one
text page at a time and move
through the text at your own pace.
The two commonly used pagers
are the more and less utilities.
Options:
•Move forward one line: Down Arrow, Enter, e,
or j.
•Move backward one line: Up Arrow, y, or k.
•Move forward one page: Space bar or Page
Down.
•Move backward one page: Page Up or b.
•Scroll to the right: Right Arrow.
•Scroll to the left: Left Arrow.
•Jump to the top of the file: Home or g
23 © LearnQuest 2021
Lesson 3
Review Grep can find individual lines in a
text file
24 © LearnQuest 2021
Lesson 4 In this lesson, we look at how to
Locate File Locations from the
Find and Compare Files Linux command line
25 © LearnQuest 2021
Diff Command
Make comparisons between two files, line by line.
Example Usage:
Options:
Example Usage:
• which diff
• /usr/bin/diff
27 © LearnQuest 2021
Locate Command
Example Usage:
• locate myProject.txt
This utility searches a database, • /home/aspeno/myProject.txt
mlocate.db, which is located in the
/var/lib/mlocate/ directory, to
determine if a particular file exists on
the local system.
Options:
• -b: Display only file names that match the
pattern and do not include any directory names
that match the pattern.
• -i: Ignore case in the pattern for matching file
names.
• -q: Do not display any error messages, such as
permission denied, when processing.
• -r: Use the regular expression, R, instead of the
pattern list to match file names.
28 © LearnQuest 2021
Find Command
Allows you to locate files based-on data, such as who owns the file, when the file was last
modified, permission set on the file, and so on.
Example Usage:
Options:
29 © LearnQuest 2021
Lesson 4
Review Diff command can be used to
compare two files
30 © LearnQuest 2021