Day 3: Basic Linux Commands

Working with files is an essential part of using a computer, especially if you're in the field of DevOps. In this tutorial, I will go through some of the most common file operations, including viewing file contents, changing access permissions, removing directories, comparing files, and more. I'll be using Ubuntu Linux for all of these commands.

To View What's Written in a File:

The cat command is used to display the contents of a file on the terminal. For example, to view the contents of a file named fruits.txt, run the following command:

COPY

cat fruits.txt

To Change the Access Permissions of Files:

The chmod command is used to change the access permissions of files. For example, to give the owner of a file read, write, and execute permissions and everyone else only read and execute permissions, run the following command:

COPY

chmod 755 filename

To Check Which Commands You Have Run Till Now:

The history command is used to show a list of all the commands you have run in the current terminal session. For example:

COPY

history

To Remove a Directory/Folder:

The rmdir command is used to remove an empty directory or folder. For example, to remove a directory named abhi, run the following command:

COPY

rmdir abhi

To Create a Fruits.txt File and to View the Content:

The touch command is used to create a new file. For example, to create a file named fruits.txt, run the following command

COPY

touch fruits.txt

You can use the cat command to view the contents of the newly created file:

COPY

cat fruits.txt

To Add Content in devops.txt (One in Each Line):

The echo command is used to add content to a file. For example, to add the words "Apple", "Mango", "Banana", "Cherry", "Kiwi", "Orange", and "Guava" to the file named devops.txt, one on each line, run the following commands:

COPY

echo "Apple" >> devops.txt
echo "Mango" >> devops.txt
echo "Banana" >> devops.txt
echo "Cherry" >> devops.txt
echo "Kiwi" >> devops.txt
echo "Orange" >> devops.txt
echo "Guava" >> devops.txt

To Show Only Top Three Fruits from the File:

The head command is used to display the first few lines of a file. For example, to show only the top three fruits from the devops.txt file, run the following command:

COPY

head -n 3 devops.txt

To Show Only the Bottom Three Fruits from the File:

The tail command is used to display the last few lines of a file. For example, to show only the bottom three fruits from the devops.txt file, run the following command:

COPY

tail -n 3 devops.txt

To Create Another File Colors.txt and to View the Content:

You can create another file named Colors.txt using the touch command:

COPY

touch Colors.txt

To view the contents of the newly created file, use the cat command:

COPY

cat Colors.txt

To Add Content in Colors.txt (One in Each Line)

Use the echo command to add the words "Red", "Pink", "White", "Black"

Thanks for reading :)

Shubham Jangale