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.txttofile2.txt.
π Move or Rename a File: mv
mv oldname.txt newname.txt
- Renames
oldname.txttonewname.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
qto quit.
π§ head and tail β View start/end of a file
head file.txt
tail file.txt
-
headshows the first 10 lines,tailshows the last 10. - Add
-nto 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.shexecutable.
π€ 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 withcatandless. - 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)