Linux Command Line
Master the Linux Command Line and Take Control of Your System

Anurag is a developer fueled by creating clean, efficient code. He's a quick learner who thrives in collaborative environments, constantly seeking out new technologies to conquer the next challenge.
Introduction
Welcome everyone! ๐๐ป
In the first part of this series, you learned about the boot process in Linux. In this part, you'll learn how to use the Linux command line and some basic commands.
The Linux command line is a powerful tool that allows you to control your system and perform tasks quickly and efficiently. It is used by system administrators, developers, and anyone else who needs to manage a Linux system.
To follow this blog, you'll need a working Linux environment. If you don't have one, you can install Linux by searching for "how to install Linux" on Google.
So what are you waiting for? Let's get started! ๐
The command line has been around since the early days of Linux. Back then, it was the only way to interact with the operating system. Today, most Linux distributions come with a graphical user interface (GUI), but there are still many reasons why you should learn about the command line.
Imagine you're working with Linux servers. There's no graphical user interface (GUI), so you can't use your mouse to interact with the system. You need to use the command line interface (CLI) to do everything. If you don't know how to use the CLI, you're going to be in a lot of trouble. You won't be able to do anything, and you'll be completely lost.
That's why it's important to learn the CLI. It's a powerful tool that can help you automate tasks, troubleshoot problems, and gain a deeper understanding of how Linux works. Whether you're a system administrator, developer, or just a curious user, learning the CLI is a valuable skill.
Starting a shell
The shell is a program that provides a user with a way to interact with the Linux system via the command line. It is a regular program that runs whenever a user logs in to a terminal. In most of the Linux distributions bash is the default shell.
To get started, open your terminal emulator. If you're using a graphical desktop environment (GUI), you can open it by searching for it in your application launcher. If you're using Linux without a GUI, you'll already have a terminal emulator open.
Below is a screenshot of a Linux bash shell using a terminal.

The prompt anurag@server1:~$ indicates the current user name (anurag), the system name (server1), the current working directory ~ (home), and $ indicates that the shell is waiting for a command. The prompt may be different in different distributions, but the idea remains the same.
Shell Commands
Now that you have a basic understanding of the shell, let's take a look at commands. With shell commands, you can do anything from navigating directories to running programs to managing your system.
Listing Files and Directories
- To list the files and directories in your current directory, run the
lscommand in your terminal.

In my case I've only one file in your case it may be different. By default ls doesn't list hidden files, so to list those files use the next command,
To list files and directories including hidden ones, run the
ls -acommand.
this time it lists all files and directories.
To list files and directories with more information, run the
ls -lorls -alcommand.

Let's break down the above information:
The long listing format lists each file and subdirectory on a single line, with additional useful information. The first line shows the total number of blocks contained within the directory. The following lines show information about each file (or directory), including:
File type: A character that indicates the type of file or directory, such as
dfor directory,-for file,lfor linked file,cfor character device, orbfor block device.Permissions: The permissions for the file or directory.
Owner: The owner of the file or directory.
Group: The group that owns the file or directory.
Size: The size of the file or directory in bytes.
Date and time: The date and time the file or directory was last modified.
Filename: The name of the file or directory.
Don't worry if you didn't understand all of that. We'll revisit this with more detail in upcoming blogs.
Sometimes you only want information for a specific file or a few files. To do this, you can filter the output of the
lscommand on the command line. You can also use regular expressions for more complex use cases.
File Handling
To create a file, run the
touchcommand followed by the name of the file you want to create. Thetouchcommand will create a new file with the specified name and assign your username as the file owner. It is important to note that thetouchcommand does not create a file with any content. It simply creates an empty file.
As you can see above, the file was created and its size is 0 bytes.
To delete a file, you can run the
rmcommand followed by the name of the file you want to remove. It is important to remember that there is no recycle bin in the terminal, so all actions are permanent.
To copy a file, you can run the
cpcommand followed by the source and destination name.
To rename or move a file, you can run the
mvcommand followed by the source and destination name.Rename a file:

Move a file to another location:

You will learn two commands to view the content of a file:
catandless. Later in this series, you will learn more advanced commands to do the same.Using the
catcommand:
Using the
lesscommand:
The
catcommand displays all the data inside a text file, whilelessprovides several handy features for scrolling through a text file, both forward and backwards, as well as some advanced searching capabilities.To view the type of a file, you can run the
filecommand followed by the file's name. This will help you avoid trying to view the content of a binary file, which may appear as gibberish on your monitor and may even freeze your terminal emulator.
As you can see above, the output of the
filecommand for a JSON, ASCII, and binary file is different.
You can use the
-ioption with themv, andcpcommands. This will prompt you before the command attempts to overwrite any pre-existing files.
Navigating the Filesystem
If you're new to Linux, you may be confused by how it references files and directories. Linux uses forward slashes (/) to separate directories, and it does not use drive letters in pathnames. This is unlike Windows, which uses backslashes (\) to separate directories and drive letters to identify different drives.
To find out your current working directory, you can run the
pwdcommand.
To change directories, run the
cdcommand followed by the directory name.

Running the
cdcommand without any arguments will take you to your home directory.
Running the
cdcommand with a dash (-) as an argument will take you to your previous working directory.
Stay tuned for upcoming blogs for advanced navigation.
Managing Directories
To create a new directory, run
mkdircommand followed by the directory name, you want to create.
The long listing shows a
dcharacter next to the name of thenew-directory. This indicates thatnew-directoryis a directory.To create directories and subdirectories in bulk, you can use the
mkdircommand with the-pargument. This will create the directories and subdirectories in a single step.
The
-Rargument to thelscommand lists directories recursively. This means that it lists all of the directories and files in the current directory, as well as all of the subdirectories of those directories. However, there is a better way to traverse directories. I will show you how to do this in an upcoming blog on advanced commands.To delete a directory, you can use the
rm -rcommand. This will recursively delete the directory, including all of the subdirectories and files it contains. It is a permanent operation, so be sure to back up any files that you want to keep before using this command.
To copy a directory, you can use the
cp -rcommand to copy a directory, followed by the source and destination name.
To rename or move a directory to a different location, use the
mvcommand the same way you would use it to rename or move a file.
Tip: Use the tab key to autocomplete commands, which can help you avoid typos.
That's all for this part. I hope you found this article informative and helpful. If you have any feedback, please feel free to share it in the comments below. Thank you for reading!
This is the second part of the Master Linux series, where you've learned about the Linux CLI and some basic commands. In the upcoming blogs, you will learn about advanced commands. Stay tuned!




