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

Mozilla

Uploaded by

v2winonline
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)
14 views

Mozilla

Uploaded by

v2winonline
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
You are on page 1/ 31

Learn Linux in One Week and Go From Zero to Hero - Get This Book

Home About eBooks Shop Donate Linux Online Courses

Subscribe to Newsletter Linux Hosting A-Z Linux Commands Get Involved 

Linux Distro’s  FAQ’s Programming  Linux Commands Linux Tricks

Best Linux Tools Certi�cations  Guides  Monitoring Tools  

Over 3,500,000+
LFCA: Learn Basic File Readers
Management Commands in
Linux – Part 2
James Kiarie Last Updated: March 26, 2021 LFCA, Linux
Certi�cations 3 Comments

1 of 31
This article is Part 2 of the LFCA series, here in this part, we
will explain about Linux �le system and cover the basic �le
management commands, that are required for the LFCA
certi�cation exam.

As you get started out in Linux, you’ll spend a great deal of


time interacting with �les and directories. Directories are also
known as folders, and they are organized in a hierarchical A Beginners Guide
structure. To Learn Linux for
Free [with
In the Linux operating system, each entity is regarded as a
Examples]
�le. In fact, there’s a popular statement in Linux circles that
goes: ‘Everything is a �le in Linux’. This is just an
oversimpli�cation and in the real sense, most �les in Linux
are special �les that include symbolic links, block �les, and so
on.
Red Hat

Linux File System Overview RHCSA/RHCE 8


Certi�cation Study
Let’s take a moment and have an overview of the main �le Guide [eBooks]
types:

1. Regular Files Linux Foundation


LFCS and LFCE
These are the most common �le types. Regular �les contain Certi�cation Study
human-readable text, program instructions, and ASCII Guide [eBooks]
characters.

Examples of regular �les include:


2 of 31
Simple text �les, pdf �les
Multimedia �les such as image, music, and video �les
Binary �les
Zipped or compressed �les

And so much more.

2. Special Files

These are �les that represent physical devices such as


mounted volumes, printers, CD drives, and any I/O ) input
and output device.

3. Directories

A directory is a special �le type that stores both regular and


special �les in a hierarchical order starting from the root (
/ ) directory. A directory is the equivalent of a folder in the
Windows operating system. Directories are created using the
mkdir command, short for making the directory, as we shall
see later on in this tutorial.

The Linux hierarchy structure starts from the root directory


and branches out to other directories as shown:

Learn Linux
Commands and
Tools

How to Run Shell


Scripts with Sudo
Command in Linux

How to Kill Linux



Process Using Kill,
Linux Directory Structure
Pkill and Killall

3 of 31
Let’s understand each directory and its usage. 6 Best CLI Tools to
Search Plain-Text
The /root directory is the home directory for the root Data Using Regular
user. Expressions
The /dev directory contains device �les such as
How to Find and Kill
/dev/sda.
Running Processes in
Static boot �les are located in the /boot directory.
Linux
Applications and user utilities are found in the /usr
directory. How to Append Text
The /var directory contains log �les of various system to End of File in Linux
applications.
7 ‘dmesg’
All system con�guration �les are stored in the /etc
directory. Commands for
Troubleshooting and
The /home directory is where user folders are located.
Collecting
These include Desktop, Documents, Downloads,
Information of Linux
Music, Public, and Videos.
For add-on application packages, check them out in Systems

the /opt directory.


The /media directory stores �les for removable devices
such as USB drives.
The /mnt directory contains subdirectories that act as
temporary mount points for mounting devices such as
CD-ROMs.
The /proc directory is a virtual �lesystem that holds
information on currently running processes. It’s a
strange �lesystem that is created upon a system boot If You Appreciate

and destroyed upon shutdown. What We Do Here On

The /bin directory contains user command binary �les. TecMint, You Should

The /lib directory stores shared library images and Consider:

kernel modules.

Linux File Management


Commands 

4 of 31
You will spend a great deal of time interacting with the
terminal where you will be running commands. Executing
commands is the most preferred way of interacting with a
Linux system as it gives you total control over the system
compared to using the graphical display elements.

For this lesson, and the coming lessons, we will be running


commands on the terminal. We are using Ubuntu OS and to
launch the terminal, use the keyboard shortcut CTRL +
ALT + T .

Let’s now delve into the basic �le management commands


that will help you create and manage your �les on your
system.

1. pwd Command

pwd, short for the print working directory, is a command that


prints out the current working directory in a hierarchical
order, beginning with the topmost root directory ( / ) .

To check your current working directory, simply invoke the


pwd command as shown.

$ pwd

The output shows that we are in our home directory, the


absolute or full path being /home/tecmint.

5 of 31
Print Current Working Directory

2. cd Command

To change or navigate directories, use the cd command


which is short for change directory.

For instance, to navigate to the /var/log �le path, run the


command:

$ cd /var/log

Navigate Directories in Linux

To go a directory up append two dots or periods in the end.

$ cd ..

To go back to the home directory run the cd command


without any arguments.

$ cd

6 of 31
cd Command Examples

NOTE: To navigate into a subdirectory or a directory within


your current directory, don’t use a forward slash ( / )
simply type in the name of the directory.

For example, to navigate into the Downloads directory, run:

$ cd Downloads

7 of 31
Navigate to Downloads Directory

3. ls Command

The ls command is a command used for listing existing �les


or folders in a directory. For example, to list all the contents in
the home directory, we will run the command.

$ ls

From the output, we can see that we have two text �les and
eight folders which are usually created by default after
installing and logging in to the system.

8 of 31
List Files in Linux

To list more information append the -lh �ag as shown.


The -l option stands for long listing and prints out
additional information such as �le permissions, user, group,
�le size, and date of creation. The -h �ag prints out the �le
or directory size in a human-readable format.

$ ls -lh

9 of 31
Long List Files in Linux

To list hidden �les, append the -a �ag.

$ ls -la

This displays hidden �les which start with a period sign


(.) as shown.

.ssh
.config
.local


List Hidden Files in Linux

10 of 31
4. touch Command

The touch command is used for creating simple �les on a


Linux system. To create a �le, use the syntax:

$ touch filename

For example, to create a �le1.txt �le, run the command:

$ touch file1.txt

To con�rm the creation of the �le, invoke the ls command.

$ ls

11 of 31
Create Empty File in Linux

5. cat Command

To view the contents of a �le, use the cat command as


follows:

$ cat filename

View Contents of Files

6. mv Command

The mv command is quite a versatile command. Depending

12 of 31
on how it is used, it can rename a �le or move it from one
location to another.

To move the �le, use the syntax below:

$ mv filename /path/to/destination/

For example, to move a �le from the current directory to the


Public/docs directory, run the command:

$ mv file1.txt Public/docs

Move Files in Linux


Alternatively, you can move a �le from a different location to

13 of 31
your current directory using the syntax shown. Take note of
the period sign at the end of the command. This implies this
location’.

$ mv /path/to/file .

We are now going to do the reverse. We will copy the �le


from the Public/docs path to the current directory as shown.

$ mv Public/docs/file1.txt .

Move Files from Location in Linux

To rename a �le, use the syntax shown. The command 


removes the original �le name and assigns the second

14 of 31
argument as the new �le name.

$ mv filename1 filename2

For example, to rename �le1.txt to �le2.txt run the command:

$ mv file1.txt file2.txt

Rename Files in Linux

Additionally, you can move and rename the �le at the same
time by specifying the destination folder and a different �le
name.

For example to move �le1.txt to the location Public/docs and

15 of 31
rename it �le2.txt run the command:

$ mv file1.txt Public/docs/file2.txt

Move and Rename Files in Linux

7. cp Command

The cp command, short for copy, copies a �le from one �le
location to another. Unlike the move command, the cp
command retains the original �le in its current location and
makes a duplicate copy in a different directory.

The syntax for copying a �le is shown below.

16 of 31
$ cp /file/path /destination/path

For example, to copy the �le �le1.txt from the current


directory to the Public/docs/ directory, issue the command:

$ cp file1.txt Public/docs/

Copy Files in Linux

To copy a directory, use the -R option for recursively


copying the directory including all its contents. We have
created another directory called tutorials. To copy this
directory alongside its contents to the Public/docs/ path, run
the command: 

17 of 31
$ cp -R tutorials Public/docs/

Copy Directory in Linux

8. mkdir Command

You might have wondered how we created the tutorials


directory. Well, it’s pretty simple. To create a new directory
use the mkdir ( make directory) command as follows:

$ mkdir directory_name

Let’s create another directory called projects as shown:


18 of 31
$ mkdir projects

Create Directory in Linux

To create a directory within another directory use the -p


�ag. The command below creates the fundamentals
directory inside the linux directory within the parent directory
which is the projects directory.

$ mkdir -p projects/linux/fundamentals

19 of 31
Create Directory in Linux

9. rmdir Command

The rmdir command deletes an empty directory. For


example, to delete or remove the tutorials directory, run the
command:

$ rmdir tutorials

20 of 31
Delete Empty Directory in Linux

If you try to remove a non-empty directory, you will get an


error message as shown.

$ rmdir projects

Delete Directory in Linux


21 of 31
10. rm Command

The rm (remove) command is used to delete a �le. The


syntax is quite straightforward:

$ rm filename

For example, to delete the �le1.txt �le, run the command:

$ rm file1.txt

Additionally, you can remove or delete a directory recursively


using the -R option. This could either be an empty or a
non-empty directory.

$ rm -R directory_name

For example, to delete the projects directory, run the


command:

$ rm -R projects

22 of 31
Delete Directory Recursively in Linux

11. �nd and locate Commands

Sometimes, you may want to search the location of a


particular �le. You can easily do this using either the �nd or
locate commands.

The �nd command searches for a �le in a particular location


and takes two arguments: the search path or directory and
the �le to be searched.

The syntax is as shown

$ find /path/to/search -name filename

For example, to search for a �le called �le1.txt in the home


directory, run:

$ find /home/tecmint -name file1.txt

23 of 31
Search Files in Linux

The locate command, just like the �nd command, plays the
same role of searching �les but only takes one argument as
shown.

$ locate filename

For example;

$ locate file1.txt

24 of 31
Locate Files in Linux

The locate command searches using a database of all the


possible �les and directories in the system.

NOTE: The locate command is much faster than the �nd


command. However, the �nd command is much more
powerful and works in situations where locate does not
produce the desired results.

That’s It! In this topic, we have covered the basic �le


management commands that will give you the know-how in
creating and managing �les and directories in a Linux
system.

Become a Linux Foundation Certi�ed IT Associate


(LFCA)

 LFCA Certi�cation Exam

25 of 31
 LFCA: Understanding Linux LFCA: Learn Basic Linux System
Operating System – Part 1 Commands – Part 3 

If you liked this article, then do subscribe to email alerts


for Linux tutorials. If you have any questions or doubts?
do ask for help in the comments section.

26 of 31
If You Appreciate What We Do Here
On TecMint, You Should Consider:

TecMint is the fastest growing and most


trusted community site for any kind of Linux
Articles, Guides and Books on the web.
Millions of people visit TecMint! to search or
browse the thousands of published articles
available FREELY to all.

If you like what you are reading, please


consider buying us a coffee ( or 2 ) as a token
of appreciation.

We are thankful for your never ending


support.

Related Posts


LFCA: Learn LFCA: Learn LFCA: Learn

27 of 31
Software the Basic the Basic
Deployment Concepts of Concepts of
Environments Using DevOps – Part
– Part 23 Containers – 21
Part 22

LFCA: How to LFCA: How to LFCA – Useful


Improve Linux Improve Linux Tips for
System Network Securing Data
Security – Part Security – Part and Linux –
20 19 Part 18

3 thoughts on “LFCA: Learn Basic


File Management Commands in
Linux – Part 2”

Anupa patil
July 19, 2021 at 7:20 pm

28 of 31
Your explanation is too excellent. I can understand
very easily..

Thank you

Reply

Gérard Talbot
April 21, 2021 at 7:16 pm

The -l option stands for long listing and prints out


additional information such as (...) date of
creation.

This is inaccurate. The date and time of the last


modi�cation (ctime) of the �le will be printed out. Not
the date of �le creation.

Gérard

Reply

dragonmouth
April 20, 2021 at 7:10 pm

James,

You need to include a warning about using the “rm 

29 of 31
-rf” command as its improper use can wipe an entire
directory, an entire HOME directory, or if used with
superuser privileges, the ENTIRE system.

Reply

Got
Linux something to say?
Server Monitoring ToolsJoin Learn
the Linux Tricks & Tips
discussion.
TCP�ow – Analyze and Debug Network How to Convert From RPM to DEB and
Traf�c
Have ain Linux or suggestion? Please leave a DEB
question to RPM
comment to Package Using Alien
start the discussion. Please keep in mind that all comments
How to Monitor Apache Web Server Find Top Running Processes by Highest
are moderated and your email address will NOT be
Load and Page Statistics Memory and CPU Usage in Linux
published.
CloudStats.me – Monitors Your Linux 4 Ways to Disable Root Account in
Servers and Websites from the Cloud Linux

How to Monitor System Usage, Outages How to Encrypt and Decrypt Files and
and Troubleshoot Linux Servers – Part 9 Directories Using Tar and OpenSSL

How to Check Integrity of File and Find Top 15 Processes by Memory


Directory Using “AIDE” in Linux Usage with ‘top’ in Batch Mode

All You Need To Know About Processes How to Set or Change System
in Linux [Comprehensive Guide] Hostname in Linux
Name *

Best
EmailLinux
* Tools

Best Command Line HTTP Clients for Linux


Website
10 Tools to Take or Capture Desktop Screenshots in Linux
Save my name, email, and website in this browser for
13
theMost UsedI Microsoft
next time comment. Of�ce Alternatives for Linux

16 Best RSS Feed Readers for Linux in 2021 


Notify me of followup comments via e-mail. You can also

30 of 31
8 Best PDF Document Viewers for Linux Systems

23 Best Open Source Text Editors (GUI + CLI) in 2021

Donate to TecMint Contact Us Advertise on TecMint Linux Services Copyright Policy


Privacy Policy Career Sponsored Post

Tecmint: Linux Howtos, Tutorials & Guides © 2021. All Rights Reserved.
The material in this site cannot be republished either online or of�ine, without our permission.

Hosting Sponsored by : Linode Cloud Hosting

31 of 31

You might also like