Chapter 1 · Lesson 3
Beginner
1 min read
Create, Read, Copy and Move Files
Overview
Linux file commands separate creating directories, reading data, copying entries and removing entries. The key safety rule is to confirm the exact source and destination before an operation.
Detailed Notes
Create directories and files
bash
mkdir -p ~/linux-practice/files
touch ~/linux-practice/files/notes.txt
ls -l ~/linux-practice/files
touch creates an empty file if it does not exist. It updates timestamps if the file already exists.
Write and read text
bash
printf 'First line
Second line
' > ~/linux-practice/files/notes.txt
cat ~/linux-practice/files/notes.txt
head -n 1 ~/linux-practice/files/notes.txt
tail -n 1 ~/linux-practice/files/notes.txt
>replaces the destination file.>>appends to the destination.catprints the complete file.lessprovides interactive paging.headprints the beginning.tailprints the end.
Copy and move
bash
cp notes.txt notes-copy.txt
cp -r folder-1 folder-2
mv notes-copy.txt ../notes-copy.txt
cpcopies a file.cp -rrecursively copies a directory.mvmoves or renames.
Remove carefully
bash
rm notes.txt
rmdir empty-folder
rm -r unwanted-folder
Before removing:
- Print the absolute path with
pwd. - List the target with
ls -ld TARGET. - For
rm -r, verify the directory contents first. - Prefer moving uncertain files into a backup location.
Some commands support -i for confirmation. rm -i FILE asks before removal.
Common Interview Questions
Finished this lesson?
0 of 25 lessons done · 0% of the course

