Welcome back to our Linux beginner series! In this part, we’ll explore how to work with files, read their contents, and understand Linux file permissions. Let’s dive right in!
📁 1. File Operations
➕ Create a File: touch
touch file.txt
- Creates an empty file named
file.txt
.
📝 Edit a File (Using nano
)
nano file.txt
- Opens a simple text editor in the terminal.
- Save with
CTRL + O
, then pressEnter
. - Exit with
CTRL + X
.
🗑️ Delete a File: rm
rm file.txt
- Deletes the specified file.
- ⚠️ Be careful! There's no recycle bin.
📝 Copy a File: cp
cp file1.txt file2.txt
- Copies
file1.txt
tofile2.txt
.
🔁 Move or Rename a File: mv
mv oldname.txt newname.txt
- Renames
oldname.txt
tonewname.txt
. - You can also move it to another folder.
📖 2. Viewing File Content
📄 cat
– Show file content
cat file.txt
- Displays the whole file in the terminal.
🔍 less
– View large files
less bigfile.txt
- Allows scrolling through the file.
- Use
q
to quit.
🧠 head
and tail
– View start/end of a file
head file.txt
tail file.txt
-
head
shows the first 10 lines,tail
shows the last 10. - Add
-n
to specify number of lines:
tail -n 20 file.txt
🔐 3. File Permissions
Every file and folder has permissions that control who can read, write, or execute them.
➤ See Permissions: ls -l
ls -l
You’ll see something like:
-rw-r--r-- 1 user group 123 Apr 24 08:00 file.txt
Let’s break it down:
-
-rw-r--r--
= permissions-
r
= read -
w
= write -
x
= execute
-
- First set is for owner, second for group, third for others.
🛠️ Change Permissions: chmod
chmod +x script.sh
- Makes
script.sh
executable.
👤 Change Ownership: chown
sudo chown tejaswini file.txt
- Changes the file’s owner to
tejaswini
.
🔁 Comparison with Windows
Task | Linux Command | Windows Equivalent |
---|---|---|
View file |
cat , less
|
Notepad, type
|
Create file | touch |
Right-click → New → Text file |
Change perm | chmod |
File properties → Security |
🎯 Practice Tips:
- Try making a text file, adding some text with
nano
, and viewing it withcat
andless
. - Experiment with changing permissions and making a script executable.
Next up in Part 3, we’ll explore process management, network commands, and a bit of package management! Stay tuned.