πŸ–₯️ Mastering Essential Linux Commands: Permissions, History & File Handling (Day 3)

πŸ–₯️ Mastering Essential Linux Commands: Permissions, History & File Handling (Day 3)

πŸ’»Essential Linux Commands Unlocked: Managing Permissions, History & Files

πŸš€ Introduction

Welcome to Day 3 of our Linux learning journey! Today, we’ll focus on three fundamental aspects of Linux:

βœ… File Permissions – Controlling who can access and modify files πŸ”
βœ… Command History – Viewing and reusing previously executed commands πŸ“œ
βœ… File Handling – Creating, copying, moving, and deleting files πŸ“‚

Mastering these commands will help you secure your system, improve efficiency, and manage files effortlessly. Let’s dive in! πŸš€


πŸ” Understanding File Permissions in Linux

In Linux, every file and directory has permissions that define who can read, write, and execute them. Think of it like a house where:

  • 🏠 Owner (User) – The person who owns the house can do everything.

  • πŸ‘¨β€πŸ‘©β€πŸ‘¦ Group – Family members can enter and use some rooms.

  • 🌍 Others – Visitors have limited access.

πŸ› οΈ Checking File Permissions

To check the permissions of a file, use:

ls -l filename

Example Output:

-rw-r--r-- 1 user user 1024 Feb 22 10:30 myfile.txt

πŸ“Œ Breaking it down:

  • rw- β†’ Owner can read & write

  • r-- β†’ Group can only read

  • r-- β†’ Others can only read


πŸ”§ Changing File Permissions

1️⃣ Grant Execute Permission (Make a File Executable)

chmod +x script.sh  # Now the script can run

2️⃣ Change File Ownership

chown new_owner filename  # Assign a new owner to the file

3️⃣ Modify Permissions Using Numbers

Each permission has a numerical value:

  • Read (r) = 4

  • Write (w) = 2

  • Execute (x) = 1

πŸ”Ή Example: Give the owner full rights (7), group read+execute (5), and others read-only (4)

chmod 754 filename

This means:

  • Owner: Read, Write, Execute (7)

  • Group: Read, Execute (5)

  • Others: Read Only (4)


πŸ“œ Command History: Never Repeat Yourself!

Have you ever run a long command and needed it again? Instead of retyping, Linux remembers everything!

πŸ•΅οΈ Viewing & Using Command History

πŸ”Ή View Past Commands

history | less

πŸ”Ή Re-run a Previous Command by Its Number

!123  # Runs command number 123 from history

πŸ”Ή Search Your History
Press Ctrl + R, then type a keyword to find a matching command. πŸ”Ž

πŸ”Ή Clear Your Command History

history -c  # Wipes your command history

πŸ“‚ File Handling in Linux

Linux provides various commands to manage files efficiently.

πŸ“ Creating Files

πŸ”Ή Create an Empty File

touch myfile.txt

πŸ”Ή Create a File & Write Content to It

echo "Hello World!" > myfile.txt

πŸ”Ή Open a File in an Editor

nano myfile.txt

πŸ“„ Copying, Moving & Renaming Files

πŸ”Ή Copy a File

cp oldfile.txt newfile.txt

πŸ”Ή Move or Rename a File

mv myfile.txt myfolder/   # Moves file to a folder  
mv oldname.txt newname.txt  # Renames the file

πŸ—‘οΈ Deleting Files & Directories

πŸ”Ή Remove a File

rm myfile.txt

πŸ”Ή Remove an Empty Directory

rmdir myfolder

πŸ”Ή Remove a Directory & Its Contents (Use with Caution!)

rm -r myfolder

🎯 Wrapping Up

Today, we covered:
βœ… File Permissions – Checking & modifying who can access files πŸ”
βœ… Command History – Reusing and clearing past commands πŸ“œ
βœ… File Handling – Creating, copying, moving, and deleting files πŸ“‚

Now you have a solid grasp of these essential Linux commands! πŸ’ͺ Stay tuned for Day 4, where we’ll dive into process management in Linux. πŸš€


πŸ’‘ Which Linux command do you use the most? Drop a comment below! πŸ’¬

Β