Level 1
0 / 100 XP

Creating and Deleting Files

In this lesson, you will learn how to manipulate files on a Linux/Unix system. We will cover essential commands for creating, reading, and modifying files.

Creating Files

touch (Create Empty File)

The touch command is used to create empty files. If the file already exists, it updates the file's modification timestamp.

touch filename.txt

mv (Move/Rename Files)

The mv command is used to move or rename files and directories. It can be used to change the location or name of a file.

Bash
mv oldfile.txt newfile.txt # Renames a file mv file.txt /path/to/directory # Moves a file

cp (Copy Files)

The cp command is used to copy files and directories. It creates a duplicate of the source file in the specified location.

cp sourcefile.txt destination/

rm (Remove Files)

The rm command is used to remove files and directories. Be cautious when using it, as deleted files are not recoverable by default.

rm file.txt

echo (Write to File)

The echo command is used to write text to a file. It can be used to create or append text to a file.

Bash
echo "test" > test.txt # Create a file with "test" content echo "more text" >> test.txt # Append text to an existing file

we covered:

  1. touch : Create or update empty files.
  2. mv : Move or rename files and directories.
  3. cp : Copy files and directories.
  4. rm : Remove files (and directories with -r).
  5. echo : Write or append text to a file.

See you in the next lesson!