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.
Top comments (0)