Basic Linux Commands ๐Ÿง๐Ÿ’ป

ยท

3 min read

Basic Linux Commands ๐Ÿง๐Ÿ’ป

What is the Linux command to:

To view what's written in a file.

To view what's written inside a file, you can use the cat command.

cat filename.txt

To change the access permissions of files.

In Linux, chmod command is used to change the access permissions of files.

chmod 777 [file_name]

To check which commands you have run till now.

To check how many commands you had run till now, use history command. This command is used to view the previously executed commands.

history

To remove a directory/ Folder.

To remove a directory/folder in Linux you can use rm command with -r option. This -r is used to remove or delete a folder permanently.

rm -r myfiles

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

To create a file use touch command and to view the content use cat command.

touch fruits.txt
cat fruits.txt

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

To add the content "Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava" in "devops.txt" with each fruit on a new line, you can use the cat command.

cat >> devops.txt
Apple
Mango
Banana
Cherry
Kiwi
Orange
Guava

To Show only top three fruits from the file.

To show only top three fruits from the file you can use head command with -n option.

head -n 3 devops.txt
Apple
Mango
Banana

To Show only the bottom three fruits from the file.

To show only the bottom three fruits from the file you can use the tail command with -n option. For example tail -n 3 devops.txt. This command will display the last three lines (fruits) from the "devops.txt" file:

tail -n 3 devops.txt
Kiwi
Orange
Guava

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

To create another file again use the touch command to create a "colors.txt" file and to view the content inside it, use cat command.

touch Colors.txt
cat Colors.txt

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

To add content in Colors.txt (One in each line) you can use the cat command.

cat >> Colors.txt
Red
Pink
White
Black
Blue
Orange
Purple
Grey

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

To find the differences between the "fruits.txt" and "Colors.txt" files and display the differences, you can use the diff command.

diff fruits.txt Colors.txt

I hope you like my blog..!!

Stay Connected with me for more interesting articles on DevOps, if you like my blog follow me on Hashnode and Linkedin (https://www.linkedin.com/in/som-shanker-pandey/)

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!

ย