Photo by Gabriel Heinzer on Unsplash
Mastering Basic Linux Commands: A Journey into Efficiency and Control
Introduction: In the realm of operating systems, Linux has garnered immense popularity for its versatility, security, and open-source nature. Whether you're a seasoned developer or a curious enthusiast, understanding the basic Linux commands is crucial for efficient navigation and management. In this blog, we will embark on a journey to explore and master essential Linux commands through a series of practical tasks.
Task 1: Viewing the Contents of a File The command cat filename
allows you to view the contents of a file directly in the terminal. For example, to view the contents of a file named file.txt
, you would use the command cat file.txt
. This command displays the entire text within the file on the terminal screen.
Task 2: Changing Access Permissions of Files The chmod
command is used to modify the access permissions of files and directories in Linux. By specifying numeric or symbolic values, you can grant or restrict read, write, and execute permissions for the owner, group, and others. For example, chmod 644 filename
sets read and write permissions for the owner and read-only permissions for the group and others.
Task 3: Checking Command History To view the list of commands you have executed so far, you can use the history
command. It displays a numbered list of previously executed commands, making it easy to reference and reuse them when needed.
Task 4: Removing a Directory/Folder The rm -r directory_name
command allows you to remove a directory or folder in Linux. Be cautious when using this command, as it permanently deletes all files and subdirectories within the specified directory. For example, to remove a directory named my_folder
, you would use the command rm -r my_folder
.
Task 5: Creating and Viewing the Content of a File To create a file, you can use the touch filename
command. For instance, to create a file named fruits.txt
, you would enter touch fruits.txt
. To view the content of the file, you can use the cat
command mentioned in Task 1.
Task 6: Adding Content to a File To add content to a file, you can use the echo
command followed by the desired text. For example, to add fruits to devops.txt
, you would use the command echo "Apple" >> devops.txt
. Repeat this command for each fruit, replacing "Apple"
with the respective fruit name.
Task 7: Displaying Top Three Fruits from the File To display the top three fruits from the fruits.txt
file, you can use the head -n 3 filename
command. For instance, head -n 3 fruits.txt
will display the first three fruits from the file.
Task 8: Displaying Bottom Three Fruits from the File To display the bottom three fruits from the fruits.txt
file, you can use the tail -n 3 filename
command. For instance, tail -n 3 fruits.txt
will display the last three fruits from the file.
Task 9: Creating and Viewing Content of Another File To create the Colors.txt
file, you can use the touch Colors.txt
command. Afterward, you can use the cat
command (Task 1) to view its content.
Task 10: Finding the Difference Between Two Files To find the differences between the fruits.txt
and Colors.txt
files, you can use the diff file1 file2
command. For example, diff fruits.txt Colors.txt
will display the contrasting lines between the two files.