Important Linux Commands for DevOps

Important Linux Commands for DevOps

3rd Blog

Hey folks, I hope you enjoyed my previous blog about YAML for DevOps. In this blog, I'm going to list out all the essential Linux commands for DevOps that I've learned in the last week. I've already gone through the Linux commands required through Kunal Kushwaha's youtube video. But, in that video, he taught Linux commands in the Zsh shell and I've observed that some of the commands in the Ubuntu terminal are different from the Zsh shell. So in the last week, I again went through Linux commands in the Ubuntu terminal through Edureka's youtube course.

Why is LINUX used in DevOps?

Since every organization needs to run applications, tasks and services, they need operating systems to do it. And every organization does things differently, so you might find that some teams use Linux exclusively because we all know what it can offer. Linux is an added advantage to DevOps.

Linux Commands:

Getting started with basic commands:

  • whoami - shows the current user

  • compgen -u - lists all the users

  • man (command name) - it's a guide with information about any command

  • echo "Hello world" - prints Hello world

  • echo "Hello" > filename → adds the text into the mentioned file

  • history - list of all commands we used till now

  • history 10 - list of the last 10 commands used

  • df -h - shows the disk-free space

Working with directories:

  • ln -s /mnt/c/Users/Chris/Desktop - changes the directory to desktop

  • pwd - shows the current directory

  • cd - changes to the home directory

  • cd Desktop - changes to sub-directory

  • cd .. - changes to the parent directory

  • cd ~ - to go back to the default directory

Working with Files:

  • touch demo.txt - creates a text file named demo in the current directory

  • touch (file1 name) (file2name)....(fileN name) - creates N number of files at a time in the current directory

  • ls - lists out all the files and folders in the current directory

  • cat demo.txt - opens a file

  • nano demo1.txt - creates a new file and also can modify the existing file.

  • vi demo.txt - modifies the contents of a file

  • less - opens a file in another window(same as nano)

Advanced Commands(Files):

  • lsof - lists out all the open files

  • lsof -u [username] - lists out all the open files in a specific user

  • ls -a → list of all the files and folders including all hidden files and folders

  • cat -b (filename) - gives line numbers to lines only with text

  • cat -n (filename) - gives line numbers to even empty lines and to all lines with text in it

  • grep cH [file name] - returns the whole word containing that string or character mentioned in the command but case sensitive

  • grep -i cH [file name] - returns case insensitive

  • sed 's/chris/cgirs/' [file name] - replaces a word with another word within the command line only

  • sort (file name) - returns all the lines in alphabetical order of starting letters

  • sort -r (file name) - returns in reverse order

  • sort -n (file name) - returns in numerical order

  • cut -c1-2 (file name) - returns only the first 2 columns in a file

  • tar -cvf (filename) (source-folder) - to zip a .tar format file

  • tar -xvf (tar-file) - to unzip a .tar format file

To know more about ls commands, please click here

To know more about cat commands, please click here

Modifying file's/folder's directories:

  • cp demo.txt Desktop - copies the mentioned file into the mentioned directory

  • mv demo.txt Desktop - moves the mentioned file to the mentioned directory and deletes it from the current directory

  • rm demo.txt - removes a file from the current directory(deletes)

    Note: once used an rm command to remove a file, you can't undo it because there's no recycle bin in Linux. So please use the rm command carefully

  • mkdir (folder name) - creates a new directory(folder)

  • rmdir (folder name) - removes a directory(folder) only which is empty

  • rm -r (folder name) - removes a non-empty directory with its contents

Files and their Permissions:

  • There are three types of permission:

    • read (r)

    • write (w)

    • execute (x)

    • These are generally represented as in rwx

  • These permissions affect three groups of owners:

    • user/owner (u)

    • group (g) → an entity among a user group

    • guests or other people (o)

  • ls -l <filename> - shows the file permissions for that mentioned file

ls -l demo.txt
-rw-r--r-- 1 chris chris 75 Nov 29 22:34 demo.txt

  • chmod (+x or +w or +r) [file name] - changes any one of the permissions of a file

  • chmod u=rwx,g=rx,o=rw [filename] - changes all the permissions of a file at a time

  • chmod 777 [file name] - changes all permissions of a file to rwx

  • chown (username) [file name] - changes the owner of the file to that mentioned username

To know in detail about File Permissions, please click here

  • id - will return the UserId, GroupId, groups belonging to the user etc

  • id -u (username) - will return only the UserId of that user

  • id -g (username) - will return only the GroupId of that user

Some of the commands with sudo:

We use sudo when we are accessing root permissions

  • sudo bash - changes the author to root

  • su (user name) - gets back to the user as author

  • sudo apt-get install package - installs a package

  • sudo useradd (username) - adds a new user

  • sudo passwd (username) - adds a password to the user

  • sudo userdel (username) - deletes a user

  • sudo groupadd (group name) - adds a group of users

  • sudo groupdel (group name) - deletes a group of users

Networking commands:

  • ifconfig - shows the ip address and some of the addresses of our device

  • ifconfig -a - shows all the interfaces in our device

  • ifconfig (port which we want to see) - shows the information only about port mentioned

  • ping google.com - checks whether google.com can communicate with us or not

  • ping (Ip addrs) - checks whether our system can communicate with ip addrs mentioned of another device connected to the same network as ours

  • wget (url) - will download the file in the url to the current directory only from http and https

  • curl (url) - to transfer data to or from a server, using any of the supported protocols (HTTP, FTP, IMAP, POP3, SCP, SFTP, SMTP, TFTP, TELNET, LDAP, or FILE).

  • nslookup google.com - will show the ip address and server address of google.com

I followed Edureka's Youtube playlist - Linux Administration Course

That's it for the blog guys. I hope you loved the reading!

Thank you 😊