Linux:Exploring the Fundamentals and Common Commands

As a DevOps enthusiast, I am embarking on a journey to become a skilled DevOps Engineer, and I plan to share my learning experiences through blog posts. As a DevOps Engineer, my primary goal is to bridge the gap between development and operations teams by leveraging automation, collaboration, and communication to streamline software development and deployment processes. I recognize that DevOps is not just a set of tools and technologies but also a cultural shift that emphasizes collaboration, agility, and a customer-centric approach. Therefore, in addition to technical skills, I will also focus on soft skills such as communication, teamwork, and problem-solving.
Through my blog posts, I aim to share my journey, insights, challenges, and successes as I navigate the world of DevOps. My goal is to provide value to my readers by offering practical advice, tips, and tricks, and inspiring them to embark on their own DevOps journey.
Linux Fundamentals
Linux is a free and open-source operating system that was initially created by Linus Torvalds in 1991. It is based on the Unix operating system and is widely used in servers, supercomputers, and embedded systems. Linux is known for its stability, security, and flexibility, as well as its ability to run on a wide range of hardware platforms.
One of the unique features of Linux is that it is distributed under a license that allows users to modify and distribute the source code of the operating system. This has led to the development of many different distributions of Linux, each with its own set of features and tools. Some of the most popular Linux distributions include Ubuntu, Debian, Fedora, and CentOS.
Linux has become a popular choice for businesses and individuals who require a stable and secure operating system that is both affordable and customizable. It is also widely used in the development of software applications and in scientific research. With its many advantages and the vibrant open-source community behind it, Linux is likely to remain a major force in the world of computing for many years to come.
Here are some fundamental concepts of Linux:
Kernel: The kernel is the core of the operating system, responsible for managing hardware resources, running processes, and providing various system services.
Shell: The shell is a command-line interface that allows users to interact with the operating system. The default shell in most Linux distributions is the bash shell.
Filesystem: Linux uses a hierarchical filesystem structure, where all files and directories are organized in a tree-like structure, with the root directory at the top.
Permissions: Linux uses a permission-based security model, where each file and directory has a set of permissions that define who can access, modify, and execute it.
Users and Groups: Linux supports multiple users and groups, with each user having its own set of permissions and access rights.
Processes: Processes are running instances of a program or command. Linux provides various tools for managing processes, such as the
psandkillcommands.Package Management: Linux provides a package management system, which allows users to easily install, update, and remove software packages. Popular package managers include apt, yum, and pacman.
Networking: Linux provides a robust networking stack, with support for various protocols and technologies. Linux also provides various tools for network configuration and troubleshooting, such as the
ipandnetstatcommands.Services: Linux supports various system services, which are background processes that provide various functions such as network access, printing, and time synchronization.
Scripting: Linux supports various scripting languages, such as bash, Python, and Perl, which allow users to automate tasks and customize their system to their needs.
These are just some of the fundamental concepts of Linux. There is a lot more to learn, but these concepts should provide a good foundation for understanding how Linux works.
Basic Commands
pwd command
The pwd command stands for "Print Working Directory". It is a basic command used in Unix-based operating systems (like Linux, macOS, and Ubuntu) that displays the current working directory in the terminal.
When you open a terminal window, you are usually placed in your home directory, which is the default directory for your user account. You can navigate to different directories using the cd command.
To use the pwd command, simply type pwd in the terminal and press Enter. The command will output the full path of the current directory you are in. For example, if you are in the directory /home/user/Documents, the pwd command will output /home/user/Documents.
The pwd command can be useful when you are working with files and need to know the exact directory you are in. It is also useful when you want to specify the full path of a file or directory in a command.
pwd [-options]
Here are some common options that can be used with the pwd command:
-L: Displays the logical path of the current directory.-P: Displays the physical path of the current directory.--help: Displays the help information for thepwdcommand.--version: Displays the version information for thepwdcommand.
cd command
The cd command is used to change the current working directory in a Linux or Unix-based operating system. When you open a terminal window, you start in your home directory, which is usually /home/username or /Users/username depending on your operating system. The cd command allows you to navigate to other directories on your file system.
Syntax:
cd [directory]
Where [directory] is the name or path of the directory you want to change to.
Examples:
To change to the root directory:
cd /This will change the current directory to the root directory (
/).To change to the home directory:
cd ~This will change the current directory to your home directory.
To change to a subdirectory:
cd Documents/This will change the current directory to the
Documentsdirectory, which is located in the current directory.To change to a directory using an absolute path:
cd /home/user/Documents/This will change the current directory to the
Documentsdirectory located at/home/user/Documents/.To change to the previous directory:
cd -This will change the current directory to the previous directory you were in.
Note that you can use the cd command with relative or absolute paths to change to any directory on your file system. Also, the cd command only changes the current working directory for the current terminal session. When you open a new terminal window, you will start in your home directory again.
ls command
The ls command is used to list the files and directories in a directory. It is one of the most frequently used commands in Unix-based operating systems such as Linux and macOS.
Syntax:
ls [options] [directory]
Where [options] are the command options you want to use, and [directory] is the name or path of the directory you want to list files from. If you don't specify a directory, ls will list the files and directories in the current directory.
Examples:
To list the files and directories in the current directory:
lsThis will list all the files and directories in the current directory.
To list the files and directories in a specific directory:
ls /home/user/Documents/This will list all the files and directories in the
Documentsdirectory located at/home/user/Documents/.To list the files and directories in a long format:
ls -lThis will list the files and directories in a long format, including the file permissions, owner, group, file size, and last modified time.
To list all files and directories, including hidden files:
ls -aThis will list all files and directories, including hidden files (files and directories that start with a dot
.).To list files and directories sorted by modification time:
ls -tThis will list the files and directories in order of their last modification time, with the most recently modified files or directories appearing first.
These are just a few of the many options that can be used with the ls command. You can use a combination of these options to list files and directories in various formats and orders.
mv command
mv Command: The mv command is used to move or rename files and directories in a Linux or Unix-based operating system.
Syntax:
mv [options] source_file(s) target_file_or_directory
Where [options] are the command options you want to use, source_file(s) are the file or files you want to move or rename, and target_file_or_directory is the target file or directory you want to move or rename the source file(s) to.
Examples:
To rename a file:
mv old_file_name new_file_nameThis will rename
old_file_nametonew_file_name.To move a file to a new location:
mv file_name /path/to/new/location/This will move
file_nameto the directory located at/path/to/new/location/.To move multiple files to a new location:
mv file1 file2 file3 /path/to/new/location/This will move
file1,file2, andfile3to the directory located at/path/to/new/location/.To move a directory and its contents to a new location:
mv /path/to/source/directory/ /path/to/new/location/This will move the entire directory located at
/path/to/source/directory/and all its contents to the directory located at/path/to/new/location/.
touch Command: The touch command is used to create an empty file or update the last modified time of an existing file.
Syntax:
touch [options] file_name(s)
Where [options] are the command options you want to use, and file_name(s) are the name or names of the file(s) you want to create or update.
Examples:
To create a new empty file:
touch new_file.txtThis will create a new empty file called
new_file.txt.To update the last modified time of an existing file:
touch existing_file.txtThis will update the last modified time of
existing_file.txt.To create multiple files:
touch file1.txt file2.txt file3.txtThis will create three new empty files called
file1.txt,file2.txt, andfile3.txt.
mkdir command
mkdir Command: The mkdir command is used to create a new directory.
Syntax:
mkdir [options] directory_name(s)
Where [options] are the command options you want to use, and directory_name(s) are the name or names of the directory(s) you want to create.
Examples:
To create a new directory:
mkdir new_directoryThis will create a new directory called
new_directory.To create a nested directory:
mkdir -p parent_directory/child_directoryThis will create a new directory called
child_directoryinside a directory calledparent_directory, even ifparent_directorydoes not yet exist.To create multiple directories:
mkdir directory1 directory2 directory3This will create three new directories called
directory1,directory2, anddirectory3.
These are just a few of the many options that can be used with the mv, touch, and mkdir commands. You can use a combination
rm command
The rm command stands for "remove" and is used to delete files and directories in a Linux or Unix-based operating system.
Syntax:
rm [options] file_or_directory
Where [options] are the command options you want to use, and file_or_directory is the name or path of the file or directory you want to delete.
Examples:
To delete a file:
rm file.txtThis will delete the file called
file.txtfrom the current directory.To delete a directory:
rm -r directory/This will delete the entire directory and all its contents. The
-roption is used to recursively delete all files and subdirectories within the directory.To force delete a file:
rm -f file.txtThis will forcefully delete the file called
file.txtwithout prompting for confirmation.To delete multiple files:
rm file1.txt file2.txt file3.txtThis will delete three files called
file1.txt,file2.txt, andfile3.txt.To delete files matching a pattern:
rm *.txtThis will delete all files in the current directory that have a
.txtextension.
It's important to exercise caution when using the rm command, as deleted files cannot be recovered easily. Always double-check the file or directory you're about to delete and make sure you're not accidentally deleting important files. You can also use the -i option to prompt for confirmation before deleting each file or directory.
I hope that you've found the information presented in this blog post to be useful in your understanding of Linux basics commands. Whether you're a beginner or experienced with Linux, It offers a wealth of possibilities and commands to explore, and I encourage you to keep experimenting with this powerful operating system.
Happy Learning 😄
Bhaktiben Kadiya




