π₯οΈ 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 & writer--
β Group can only readr--
β 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! π¬