Linux command to various Tasks with command examples.

Linux command to various Tasks with command examples.

1-To change access permission in file command in Linux.

To change the access permission of a file in Linux, you can use the chmod command. For example, to give read, write, and execute permission to the owner of a file called “example.txt”, you would use the command:

chmod u+rwx example.txt

2-To check which command you have run till now in Linux.

To check which command you have run till now in Linux, you can use the history command. The command will display a list of the commands that you have recently run in the terminal.

3-To remove files or Directory in Linux with an example

The 'rm' command is used to remove files or directories in Linux.

Examples:

  1. To remove a single file, use the command 'rm filename.txt':
  • rm filename.txt
  1. To remove multiple files, use the command 'rm file1.txt file2.txt':
  • rm file1.txt file2.txt
  1. To remove an entire directory, use the command 'rm -r directory name:
  • rm -r directory name

4-To create a fruit.txt file and to view content in the Linux by command

  1. To create a fruit.txt file in the current working directory, type the following command:
  • touch fruit.txt
  1. To view the content of the file, type the following command:
  • cat fruit.txt

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

Type the command

  • echo "Apple" >> fruits.txt

  • echo "Mango" >> fruits.txt

  • echo "Banana" >> fruits.txt

  • echo "Cherry" >> fruits.txt

  • echo "Kiwi" >> fruits.txt

  • echo "Orange" >> fruits.txt

  • echo "Guava" >> fruits.txt

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

To see the top 3 and bottom 3 fruit in the file in the Linux command line: follow the command-

For top.

  • head -n 3 fruits.txt

-The result will be shown.

  • Apple

  • Mango

  • Banana

For bottom.

  • tail -n 3 fruits.txt

-The result will be shown.

  • Cherry

  • Kiwi

  • Orange

7 -to create file color.txt and view content in the Linux command line

  1. To create the file, enter the following command:
  • touch color.txt
  1. To view the contents of the file, enter the following command:
  • cat color.txt

8 - Add content in color.txt (one in each line) -Red, Pink, White, Black, Orange, Purple, and Grey.

  • echo "Red" >> color.txt

  • echo "Pink" >> color.txt

  • echo "White" >> color.txt

  • echo "Black" >> color.txt

  • echo "Orange" >> color.txt

  • echo "Purple" >> color.txt

  • echo "Grey" >> color.txt

9 - What is the command in Linux to find the difference in color.txt and fruit.txt

The command to find the difference between color.txt and fruit.txt would be:

  • diff color.txt fruits.txt

The diff command will show the differences between the two files, including which lines are different or the same. It will show the lines that are different between the two files and which lines are the same. This is because diff works by comparing the two files line by line and reporting any differences it finds. It will show the lines that are unique to each file, and the lines that are the same.

For Example - both color.txt and fruits.txt have one content same as each other, Which is it if you guess. Yes, it's Orange. Now when you run diff command it will show all the other content except Orange will be shown in a different alphanumeric way. for example like- 7a7 or 6o7p. which will help you identify the difference.

  • Thank you, I hope this helps you a little in understanding the Basic commands. This was a Basic task that can be performed as a Beginner, I myself learning and wants to share my learning experience with all.