Unlocking Linux Mastery: Advanced Commands for Power Users
Day 3: Basic Linux Commands

To View the contents of a file
Cat - This Linux command allows you to view the contents of a file
Simply type
cat filenameand PressEnterReplace "filename" with the name of the file you want to view.
Change access permissions of files
chmod -To modify the access permissions of a file, use the chmod command followed by the permission code and the file name.
The permission code consists of three digits representing read (4), write (2), and execute (1) permissions for the owner, group, and others, respectively.
Simply type
chmod 644 filenameand PressEnterFor example - Here 735 is represented as,
7: Hundred's place denotes owner permission
3: Ten's place denotes group permission
5: Unit's place denotes everyones permission
Furthermore, chmod digits give the following kind of permissions:
1 = Execute
2 = Write
3 = Write & Execute
4 = Read
5 = Read & Execute
6 = Read & Write
7 = Read, Write & ExecuteNow, when we put it all together, we can see what the chmod 735 command means and what it will do to your file permissions:
7: Owner can read, write and execute
3: Group can write and execute
5: Everyone can read and execute
Check your command history
history -To view the list of commands you have run in the terminal session history.
Simply type
historyand PressEnterThis will display a numbered list of commands you executed during the current session.
Remove a directory/folder
rm - To remove a directory/ Folder.
Simply type
rm filename/directorynameand PressEnter
Create an animals.txt file and view its content
touch - To create an empty file named "animal.txt,"
cat -To view the contents of the file (we discussed earlier)
Simply type
touch filenameand PressEnterthen ,type
cat filenameand PressEnter
Add content in animals.txt
Vim - To open a file to add content
Simply type
vim filenamePressEnterInserting Text: To start inserting or editing text within the file, press
ifor insert mode. You can then type or modify text as needed.Saving and Exiting: To save the changes and exit vim, press
Escto ensure you are in normal mode, and then type:wqorZZ (Shift + zz)PressEnter
To Show only the top five animals from the file
head - To display the top lines of the file
Simply type
head -5 filenamePressEnteryou can also use the
headcommand with the-noption
To Show only the bottom five animals from the file
tail -To display the last lines of the file,
Simply type
tail -5 filenamePressEnteryou can also use the
tailcommand with the-noption
To create another file with content in flowers.txt and to view the content.
We already discussed this earlier
touch,vimandcatcommand
To find the difference between animals.txt and flowers.txt file
diff - To compare the contents of two files and find the differences
Simply type
diff filename1 filename2PressEnterThe
diffcommand will display the lines that are different between the two files, if any.
Conclusion
In summary, mastering a few fundamental Linux commands empowers users to efficiently manage files and directories within the terminal. Commands like cat allow for easy viewing of file contents, while chmod facilitating the adjustment of access permissions, ensuring secure file management. Monitoring and reviewing past commands is made simple by history providing a comprehensive list of previous actions within the session.
Basic file operations, such as creation, editing, and deletion, are streamlined through commands like touch, vim, and rmenabling users to manipulate files swiftly and effectively. Furthermore, commands like 'head' and 'tail' offer quick insights by displaying the top or bottom lines of a file, respectively. For more advanced tasks, such as comparing file contents, diff provides a straightforward solution, highlighting any discrepancies between files. By familiarizing oneself with these commands, users gain greater control and efficiency in navigating the Linux environment.
I hope you found this blog helpful!
Happy learning!



