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 usercompgen -u
- lists all the usersman (command name)
- it's a guide with information about any commandecho "Hello world"
- prints Hello worldecho "Hello" > filename
→ adds the text into the mentioned filehistory
- list of all commands we used till nowhistory 10
- list of the last 10 commands useddf -h
- shows the disk-free space
Working with directories:
ln -s /mnt/c/Users/Chris/Desktop
- changes the directory to desktoppwd
- shows the current directorycd
- changes to the home directorycd Desktop
- changes to sub-directorycd ..
- changes to the parent directorycd ~
- to go back to the default directory
Working with Files:
touch demo.txt
- creates a text file named demo in the current directorytouch (file1 name) (file2name)....(fileN name)
- creates N number of files at a time in the current directoryls
- lists out all the files and folders in the current directorycat demo.txt
- opens a filenano demo1.txt
- creates a new file and also can modify the existing file.vi demo.txt
- modifies the contents of a fileless
- opens a file in another window(same as nano)
Advanced Commands(Files):
lsof
- lists out all the open fileslsof -u [username]
- lists out all the open files in a specific userls -a
→ list of all the files and folders including all hidden files and folderscat -b (filename)
- gives line numbers to lines only with textcat -n (filename)
- gives line numbers to even empty lines and to all lines with text in itgrep cH [file name]
- returns the whole word containing that string or character mentioned in the command but case sensitivegrep -i cH [file name]
- returns case insensitivesed 's/chris/cgirs/' [file name]
- replaces a word with another word within the command line onlysort (file name)
- returns all the lines in alphabetical order of starting letterssort -r (file name)
- returns in reverse ordersort -n (file name)
- returns in numerical ordercut -c1-2 (file name)
- returns only the first 2 columns in a filetar -cvf (filename) (source-folder)
- to zip a .tar format filetar -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 directorymv demo.txt Desktop
- moves the mentioned file to the mentioned directory and deletes it from the current directoryrm 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 emptyrm -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 filechmod u=rwx,g=rx,o=rw [filename]
- changes all the permissions of a file at a timechmod 777 [file name]
- changes all permissions of a file to rwxchown (username) [file name]
- changes the owner of the file to that mentioned username
To know in detail about File Permissions, please click here
Commands related to User-Id's and stuff:
id
- will return the UserId, GroupId, groups belonging to the user etcid -u (username)
- will return only the UserId of that userid -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 rootsu (user name)
- gets back to the user as authorsudo apt-get install package
- installs a packagesudo useradd (username)
- adds a new usersudo passwd (username)
- adds a password to the usersudo userdel (username)
- deletes a usersudo groupadd (group name)
- adds a group of userssudo groupdel (group name)
- deletes a group of users
Networking commands:
ifconfig
- shows the ip address and some of the addresses of our deviceifconfig -a
- shows all the interfaces in our deviceifconfig (port which we want to see)
- shows the information only about port mentionedping google.com
- checks whether google.com can communicate with us or notping (Ip addrs)
- checks whether our system can communicate with ip addrs mentioned of another device connected to the same network as ourswget (url)
- will download the file in the url to the current directory only from http and httpscurl (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 😊