Learn Linux with Liko: Create, Copy, Rename and Delete Files
In the previous lesson, we used pwd, ls,
mkdir, and cd to work with directories. In this
second lesson of Liko Learns Linux, we’ll use four commands
to manage files from the terminal.
touchcreates a new empty file.cpcopies a file.mvmoves or renames a file.rmremoves a file.
Watch Liko type each command and use ls to show what changed.
Before you begin: Open a terminal in a fresh, empty practice directory so the example filenames won’t conflict with existing files.
1. Create a file with touch
touch notes.txt
ls
touch creates an empty file if the filename doesn’t already
exist. The ls output confirms that it’s there.
notes.txt
2. Copy a file with cp
cp notes.txt notes_backup.txt
ls
The first filename is the source and the second is the destination. The original stays in place and a copy appears alongside it.
notes.txt notes_backup.txt
3. Rename a file with mv
mv notes.txt linux_notes.txt
ls
Because both names refer to the same directory, mv renames
notes.txt to linux_notes.txt. The backup keeps its
original name.
linux_notes.txt notes_backup.txt
4. Delete a file with rm
Check the filename before pressing Enter.
rm bypasses the Trash, so you can’t restore the file from there.
rm notes_backup.txt
ls
The backup is removed, leaving only the renamed file.
linux_notes.txt
Try the complete sequence
Run these commands one line at a time and check the output after each
ls.
touch notes.txt
ls
cp notes.txt notes_backup.txt
ls
mv notes.txt linux_notes.txt
ls
rm notes_backup.txt
ls
Follow Liko Learns Linux for more beginner-friendly terminal lessons you can try yourself.
No comments:
Post a Comment