Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction 🌼
2.
File Management Commands
2.1.
pwd Command
2.2.
cd Command
2.3.
ls Command
2.4.
touch Command
2.5.
cat Command
2.6.
mv Command
2.7.
cp Command
2.8.
mkdir Command
2.9.
rm Command
3.
Frequently Asked Questions 
3.1.
What is the shell?
3.2.
Is shell easy to learn?
3.3.
Is Linux based on C or C++?
3.4.
Differentiate between Bash and shell?
3.5.
Do programmers use Linux?
4.
Conclusion
Last Updated: Mar 27, 2024
Easy

Basic File Management Commands in Linux

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction 🌼

Linux is An Operating System similar to Unix based on the Linux kernel that directly handles the hardware and resources of a system, such as the CPU, memory, and storage. It lies between applications and hardware, connecting all of your software to the actual resources that do the work. 

Linus Torvalds introduced it in 1991, and Linux is usually distributed as a package. As it is an operating system, most operations are performed on the files. It has some Directories, also known as folders in Linux, that are organized in the form of a tree. These directories, however, are also a form of a file. There are three kinds of files in Linux: regular files, directories, and special files.

basic file management commands in linux og image

Let's learn some fundamental commands to perform operations on Linux file systems.

File Management Commands

pwd Command

Pwd returns the full path name of the current remote working directory. In the above example, the command output is /home/amisha_26, which implies that we are working in the amisha_26 directory, which is inside the home directory.

Syntax:

$ pwd -L: Prints the symbolic path.
$ pwd -P: Prints the actual path.

 

Example:

output

cd Command

The command cd also sometimes called as chdir , it allows you to move between directories. The cd command accepts an argument, generally the name of the folder to which you wish to move. Thus the entire command is cd your-directory.

Syntax :

$ cd <directory_name> (Will move to the desired directory)
$ Cd .. (will move back to the previous directory)

 

Example:

output

ls Command

The “ls” command lists files that present the directory you want to work with, except for hidden files.

In the above example, ls list all the files present in the directory named as amees.

Syntax :

$ ls


Example:

output

touch Command

The primary use of the touch command is to alter a timestamp. The function is commonly used for file creation, even though this is not its core role. The terminal program may modify and access times for any specified file. The touch command only creates a file if it does not already exist.

Syntax: 

$ touch <options> <file or directory name>

OPTIONS

MEANING

-a

Changes the access time

-c

if the file does not exist, do not create it

 

-d

 

update the access and modification times

-m

change the modification time only

 

-r

use the access and modification times of the file

 

-t

creates a file using a specified time

Example:

output

cat Command

Cat or concatenate is often used in Linux. It reads the files' content and gives the content's output on the terminal screen. In the above example, we used the command cat to read the file1.txt and you can see the In the above example, we used the command cat to read the file1.txt and see the output below the command.

Syntax: 

$ cat <filename>


Example:

output


mv Command

The mv command is often used in Linux; this command is used to move a file from one directory to another directory. There is also a second use of the mv command. We can change the name of any existing file to a new name, whichever we desire.

In the above example, we are changing the name of a.txt to b.txt.

Here we are using the mv command, which will change the name of the file a.txt to b.txt.

Syntax: 

$ mv <filename> <new file name>

 

Example:

output

cp Command

Cp means to copy. The command is used to copy files or groups of files. In the above example, we are using the cp command to copy the content of file3.txt and will paste it into the file named file1.txt.

Syntax:

cp <file/directory-sources> <destination>


Example:

output

mkdir Command

“mkdir”  also known as “ make directory”. This command is used to create single or multiple directories.

Syntax:

mkdir <options> <directories>

OPTION

MEANING

-v

print a message for each created directory 

-p 

no error if existing

Example:

output

rm Command

“rm”  also know as “remove”.This command is used to remove a file. If we use the rm command, the file will be permanently deleted. In GUIs, we got recycle bin and trash for recovering files. So we need to take extra care while using the rm command.

Example:

output

Read about: gzip command in linux

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Frequently Asked Questions 

What is the shell?

Shell is a command language interpreter. It executes commands read from input devices like keyboards or files.

Is shell easy to learn?

Shells allow users to communicate efficiently and directly with their operating systems. Shell scripting is not a single language, but because it uses some natural language commands, it's easy to learn, even without a programming background.

Is Linux based on C or C++?

Linux is written mainly in C programming language, with some parts in assembly-level language.

Differentiate between Bash and shell?

Bash stands for “Bourne Again SHell.” It is an improvement of the sh, which is the original Bourne shell. Shell scripting is in any shell, whereas Bash scripting is specifically for Bash. sh is a shell command-line interpreter of Unix/Unix-like operating systems.

Do programmers use Linux?

Many developers and programmers tend to choose Linux Operating systems over other Operating Systems. This is because it enables them to work more effectively and quickly. It will allow them to customize as per their needs and be innovative. A massive perk of using Linux is that it is free to use and open-source.

Conclusion

At the end of this article, we finish learning about basic file management commands in Linux. What’s next now?

File management commands are just a small part of Linux. Apart from it, there are lots more to learn about, but how will we do that?

Read more, Free Space Management in OS, Touch command in linux

Don’t worry, as Coding Ninjas has got you covered with the basics of Linux curated in one place, Coding Ninjas Studio

Check out this article - File System Vs DBMS

Apart from that, don’t forget to check out Data Structures and AlgorithmsCompetitive ProgrammingBasics of C++Data Structures and Algorithms in C++, and many more courses on Coding Ninjas.

Happy learning!

Previous article
How to Kill a Process in Linux
Next article
Linux Architecture
Live masterclass