Basic Linux Commands

Basic Linux Commands

#90DaysOfDevOps

What is Linux command to:-

To view what's written in a file-

Linux command to view what's written in a file is the cat command. The 'cat' command is the most versatile and effective tool. It is regarded as one of the most commonly used commands. It can display the contents of a file, copy the contents of one file to another, concatenate the contents of multiple files, display the line number, display $ at the end of the line, and so on.

To change the access permissions of files-

The command to change the access permissions of a file is chmod command in Linux.

  • chmod +rwx filename to add permissions

  • chmod -rwx directory name to remove permissions.

  • chmod +x filename to allow executable permissions.

  • chmod -wx filename to take out write and executable permissions.

Note that “r” is for read, “w” is for write, and “x” is for execute.

To check which commands you have run till now-

The history command is the command to check which commands we have run till now.

To remove a directory/Folder-

To remove an empty directory use rmdir command as shown in the below image.

To remove a file or directory with its content including subdirectories and files, we use the rm command in Linux.

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

We use the touch command to create an empty file in Linux and the cat command to view its content.

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

Firstly we will create a devOps.txt file using the touch command. After creating the file we will open the file using the vi editor and will add content to it.

To show only the top three fruits from the file-

To show only the top three items from the devops.txt file we will use the head command with the -n option.

To show only the bottom three fruits from the file-

To show only the bottom three items from the devops.txt file we will use the tail command with the -n option.

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

We will use the vi command to create a Colors.txt file and We will use the cat command to see its content.

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

We will use the vi command to add content in the Colors.txt file.

To find the difference between devops.txt and Colors.txt files-

The diff command can be used to find the difference between the devops.txt and Colors.txt files.

Thanks for giving your valuable time to read my blog. If you want to read more blogs like this kindly follow me.

~Prabhakar Yadav