These commands are used to create, copy, move, and delete files and directories.
-
touch file.txt→ Creates a new empty file namedfile.txt. -
mkdir MyFolder→ Creates a new directory namedMyFolder. -
cp file1.txt file2.txt→ Copies the contents offile1.txtto a new file namedfile2.txt. -
mv old.txt new.txt→ Renames the fileold.txttonew.txt. It can also be used to move a file to a different directory:mv file.txt /path/to/new/directory/. -
rm file.txt→ Deletes the file namedfile.txt. Use with caution! -
rm -r foldername→ Deletes the directory namedfoldernameand all its contents (files and subdirectories). Use with extreme caution! The-rflag stands for recursive.
Create a project folder, add a Python file, copy it, rename the copy, and then delete the original file:
mkdir Projects
cd Projects
touch main.py
cp main.py backup.py
mv backup.py old_main.py
rm main.py