1.3 Mastering the Basics: Unveiling the Power of Essential Linux Commands Part-2

1.3 Mastering the Basics: Unveiling the Power of Essential Linux Commands Part-2

In this article, we will explore various file and directory manipulation tasks in a Linux-based terminal.

  • Viewing File Contents: To view what's written in a file (fruits.txt)
[~]$ cat fruits.txt

Changing Access Permissions: To change the access permissions of files (for example, make the file executable only for the owner)

[~]$ chmod u+rwx,g-rwx,o-rwx filename # Replace 'filename' with the actual file name
[~]$ chmod 700 filename # Replace 'filename' with the actual file name
BitPurposeOctal Value
rRead4
wWrite2
xExecute1
💡
while using octal code like xyz, where x gives permission for the user or owner, y talks about group & z tells about others.

Examples for more clarity:

  • Full access for Owner, add read, remove execute for group and no access for others
[~]$ chmod u+rwx,g+r-x,o-rwx test-file
  • Provide full access to Owners, group and others
[~]$ chmod 777 test-file
  • Provide Read and execute access to Owners,groups and others
[~]$ chmod 555 test-file
  • Read and Write access for Owner and Group, No access for others.
[~]$ chmod 660 test-file
  • Full access for Owner, read and execute for group and no access for others.
[~]$ chmod 750 test-file

  • Checking Command History: To check which commands you have run till now
[~]$ history
  • Removing a Directory/Folder: To remove a directory/folder (for example, remove a directory named 'my_folder')
[~]$ rm -r my_folder
  • Creating and Viewing fruits.txt:
[~]$ echo "Apple Mango Banana Cherry Kiwi Orange Guava" > fruits.txt
[~]$ cat fruits.txt
  • Adding Content to devops.txt: Add content in devops.txt (One in each line) - Apple, Mango, Banana, Cherry, Kiwi, Orange, Guava:
[~]$ echo -e "Apple\nMango\nBanana\nCherry\nKiwi\nOrange\nGuava" > devops.txt
  • Showing Top Three Fruits:
[~]$ head -n 3 devops.txt
  • Showing Bottom Three Fruits
[~]$ tail -n 3 devops.txt
  • Creating and Viewing Colors.txt
[~]$ echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt

[~]$ cat Colors.txt
  • Adding Content to Colors.txt: Add content in Colors.txt (One in each line) - Red, Pink, White, Black, Blue, Orange, Purple, Grey:
[~]$ echo -e "Red\nPink\nWhite\nBlack\nBlue\nOrange\nPurple\nGrey" > Colors.txt
  • Finding Differences Between Files: To find the difference between fruits.txt and Colors.txt file
[~]$ diff fruits.txt Colors.txt

"Choose a job you love, and you will never have to work a day in your life." - Confucius

💡
Happy learning!!!

Did you find this article valuable?

Support Vijay Kumar Singh by becoming a sponsor. Any amount is appreciated!