Day 3 - Linux Commands for devops

Task: What is the linux command to

To view what's written in a file.
The cat command in Linux is used to concatenate and display the contents of files.

cat <filename>

Example:

To change the access permissions of files.

The chmod command in Linux is used to change the access permissions of files and directories.

chmod <permissions> <filename>

Example:

Here, 644 means you can read and write the file or directory and other users can only read it.

To check which commands you have run till now.

The history command in Linux is used to display a list of previously executed commands from the command line.

history

Example:

To remove a directory/ Folder.

The rmdir command is used to remove an empty directory. It will only work if the directory is empty.

rmdir <directory name>

To remove non-empty directories. (-r means recursively)

rm -r <directory name>

Example:

To create a fruits.txt file and to view the content.

Touch: used to create new empty files.

Cat: used to concatenate and display the contents of files.

touch <filename>
cat <filename>

Example:

Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava.

First create a file with "touch" command.

Open file with vim editor

Press "i" to go into insert mode and add contents to the file. & press "Esc +:wq!" to save and exit from the file.

Example:

To Show only top three fruits from the file.

The head command in Linux is used to display the first few lines of a file or the beginning portion of a command output.

head <file name>

Example:

To Show only bottom three fruits from the file.

The tail command in Linux is used to display the last few lines of a file or the ending portion of a command output.

tail <file name>

Example:

To create another file Colors.txt and to view the content.

touch <filename>
cat <filename>

Example:

Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey.

Open colors.txt with vim editor.

Press "i" to go into insert mode and add contents to the file. & press "Esc +:wq!" to save and exit from the file.

Example:

To find the difference between fruits.txt and Colors.txt file.

The diff command in Linux is used to compare the contents of two files or directories and display the differences between them.

diff <file1> <file2>

Example:

Conclusion:

Mastering the basic Linux commands is the foundation of becoming proficient in working with Linux systems. This blog has provided an overview of essential commands for navigating the file system, managing files and directories, working with text files, process management, user and permission management, and networking. By acquiring these skills, you'll gain the confidence to explore and utilize Linux's immense power and flexibility. With practice and experience, you'll be on your way to becoming a Linux command-line guru.

Remember, this is just the beginning. The Linux command-line interface is vast and offers countless other commands and possibilities. So, keep exploring, experimenting, and expanding your knowledge to unleash the true potential of Linux. Happy command-line hacking!

0
Subscribe to my newsletter

Read articles from Vaishnavi Shivde directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vaishnavi Shivde
Vaishnavi Shivde

Aspiring DevOps Engineer | Linux | Git & Github | Shell Scripting | Docker | CI/CD Jenkins | Kubernetes | AWS | Terraform | JIRA | Python |