You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Now that you can navigate the filesystem, it is time to learn how to create, copy, move, rename, and delete files and directories. These are the fundamental operations you will use every day.
touch newfile.txt # create an empty file
touch file1.txt file2.txt # create multiple files
touch -m existingfile.txt # update modification time only
echo "Hello, Linux" > hello.txt # create/overwrite file with content
echo "Another line" >> hello.txt # append to file
cat > notes.txt # type content, then Ctrl+D to save
| Editor | Description | Install |
|---|---|---|
| nano | Simple, beginner-friendly terminal editor | Usually pre-installed |
| vim | Powerful, modal editor (steep learning curve) | sudo apt install vim |
| vi | Older version of vim, always available | Pre-installed on all systems |
nano notes.txt # open in nano (Ctrl+O to save, Ctrl+X to exit)
vim notes.txt # open in vim (i to insert, Esc then :wq to save and quit)
mkdir projects # create a single directory
mkdir -p projects/web/src # create nested directories (-p = parents)
mkdir -m 755 shared # create with specific permissions
mkdir docs logs config # create multiple directories
cp source.txt dest.txt # copy a file
cp source.txt /tmp/ # copy to a directory
cp -r src_dir/ dest_dir/ # copy a directory recursively
cp -i file.txt /backup/ # prompt before overwriting (-i = interactive)
cp -u *.txt /backup/ # copy only if source is newer (-u = update)
cp -v file.txt /tmp/ # verbose output
cp -a /data /backup/ # archive mode (preserves permissions, timestamps, links)
Key flags:
| Flag | Meaning |
|---|---|
-r | Recursive (required for directories) |
-i | Interactive (prompt before overwrite) |
-u | Update (only copy if source is newer) |
-v | Verbose (show what is being copied) |
-a | Archive (preserve all attributes) |
-p | Preserve permissions and timestamps |
mv oldname.txt newname.txt # rename a file
mv file.txt /tmp/ # move to /tmp/
mv file.txt /tmp/newname.txt # move and rename
mv dir1/ dir2/ # rename a directory
mv -i file.txt /backup/ # prompt before overwriting
mv -v *.log /var/log/archive/ # move with verbose output
Tip:
mvworks the same for both files and directories — no-rflag needed.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.