Linux Fundamental for DevOps Engineer

Linux Fundamental for DevOps Engineer

In this article, we will focus on Linux fundamentals which are very important for a DevOps engineer. We will see all the basic commands in this article with examples and in the next section I will come up with Advanced Linux.

I am going to use an Ubuntu machine and I would suggest you all use the same operating system so that you can connect and follow along. So here are commands which I will demonstrate one by one along with an explanation.

pwd (Present Working Directory)

If we want to check the current directory where we are then we can simply write this command to get the details. if you see the below snap then it's showing that I am inside the home and then in the Ubuntu directory. Please note: here ubuntu is a user name but it acts as a directory as well where we can create/store data.

ubuntu@ip-172-31-7-130:~$ pwd
/home/ubuntu

How to Create a File?

We have multiple commands to create a file like touch, vi, vim etc.

Touch- If we use the touch command then an empty file will be created.

vi/vim- If we use this command then it will create a file and also it will open an editor to add some input to the file.

Let's have a look.

ubuntu@ip-172-31-7-130:~$ touch file_1.tx
ubuntu@ip-172-31-7-130:~$ ls
file_1.txt
(ls commnd is use to view the files/directories)
ubuntu@ip-172-31-7-130:~$ vi file_2.txt
(now once you will hit enter, an editor will open where you can add some data. after that enter this command :wq and hit enter to save and exit)
ubuntu@ip-172-31-7-130:~$ ls
file_1.txt  file_2.txt

cat- To see the content of a file.

ubuntu@ip-172-31-7-130:~$ cat file_2.txt 
hello world

mkdir- to create the directory

ubuntu@ip-172-31-7-130:~$ mkdir Linux_Dir
ubuntu@ip-172-31-7-130:~$ ls
Linux_Dir

cd- To change/switch into a different directory

ubuntu@ip-172-31-7-130:~$ cd Linux_Dir/
ubuntu@ip-172-31-7-130:~/Linux_Dir$

Copy - cp command is used to copy the files.

I am creating some files with the touch command to demonstrate the cp command.

root@ip-172-31-7-130:/home/ubuntu# ls
Linux_Dir  testfile.txt
root@ip-172-31-7-130:/home/ubuntu# ls Linux_Dir/
root@ip-172-31-7-130:/home/ubuntu# cp testfile.txt Linux_Dir/
root@ip-172-31-7-130:/home/ubuntu# ls Linux_Dir/
testfile.txt

Move- mv command is used to move the file/directory.

root@ip-172-31-7-130:/home/ubuntu# ls
Linux_Dir  testfile.txt
root@ip-172-31-7-130:/home/ubuntu# mv testfile.txt Linux_Dir/
root@ip-172-31-7-130:/home/ubuntu# ls Linux_Dir/
testfile.txt
root@ip-172-31-7-130:/home/ubuntu# ls
Linux_Dir

Rename- mv command is used to rename.

root@ip-172-31-7-130:/home/ubuntu# ls
Linux_Dir
root@ip-172-31-7-130:/home/ubuntu# mv Linux_Dir UbuntuFile
root@ip-172-31-7-130:/home/ubuntu# ls
UbuntuFile
root@ip-172-31-7-130:/home/ubuntu#

Delete- rm command is used to delete a file.

root@ip-172-31-7-130:/home/ubuntu# ls
UbuntuFile  rmfile.txt
root@ip-172-31-7-130:/home/ubuntu# rm rmfile.txt
root@ip-172-31-7-130:/home/ubuntu# ls
UbuntuFile
root@ip-172-31-7-130:/home/ubuntu#

Delete a directory- rm-rf command is used to delete a directory.

root@ip-172-31-7-130:/home/ubuntu# ls
UbuntuFile
root@ip-172-31-7-130:/home/ubuntu# rm -rf UbuntuFile/
root@ip-172-31-7-130:/home/ubuntu# ls
root@ip-172-31-7-130:/home/ubuntu#

View files/directory- ls command is used to view the files.

root@ip-172-31-7-130:/home/ubuntu# touch file.txt
root@ip-172-31-7-130:/home/ubuntu# ls
file.txt
root@ip-172-31-7-130:/home/ubuntu#

To see the detailed view, we can use ls -la
root@ip-172-31-7-130:/home/ubuntu# ls -la
total 36
drwxr-x--- 4 ubuntu ubuntu 4096 Apr  5 20:36 . (Hidden)
drwxr-xr-x 3 root   root   4096 Apr  2 04:04 ..
-rw------- 1 ubuntu ubuntu  833 Apr  3 12:11 .bash_history
-rw-r--r-- 1 ubuntu ubuntu  220 Jan  6  2022 .bash_logout
-rw-r--r-- 1 ubuntu ubuntu 3771 Jan  6  2022 .bashrc
drwx------ 2 ubuntu ubuntu 4096 Apr  2 04:04 .cache
-rw-r--r-- 1 ubuntu ubuntu  807 Jan  6  2022 .profile
drwx------ 2 ubuntu ubuntu 4096 Apr  2 04:04 .ssh
-rw-r--r-- 1 ubuntu ubuntu    0 Apr  2 04:04 .sudo_as_admin_successful
-rw------- 1 ubuntu ubuntu  744 Apr  3 11:48 .viminfo
-rw-r--r-- 1 root   root      0 Apr  5 20:36 file.txt
root@ip-172-31-7-130:/home/ubuntu#

. > here single dot indicates to hidden files/directory.
wit -la we can view the detailed view along with hidden files.

Add User-

root@ip-172-31-7-130:/home/ubuntu# useradd LinuxMachine -m
root@ip-172-31-7-130:/home/ubuntu# ls /home/
LinuxMachine  ubuntu
root@ip-172-31-7-130:/home/ubuntu#

when we write -m it creates a directory as well with same user name.

Thanks for your time, please follow me on Hashnode to get more articles on DevOps.