It’s now time to start getting creative and looking at how we can create, move, copy and delete files and directories.
Files
To start we will create a blank file using the touch command (this actually updates the modification time on a file, but if a file doesn’t exist creates one first).
touch myfile1
If we now want to make a copy of this file, we just use the cp (copy) command:
cp myfile1 myfile_copy
To rename a file, we just use the mv (move) command:
mv myfile_copy myfile2
And finally to delete a file we just use the rm (remove) command:
rm myfile2
Directories
Creating directories is slightly different to files and uses the mkdir (make directory) command:
mkdir junkdir
If we try removing this directory using the rm (remove) command we get an error:
rm: cannot remove `junkdir': Is a directory
So need to use the rmdir (remove directory) command:
rmdir junkdir
Summary of commands
rm |
Delete (remove) a file |
mv |
Move a file |
cp |
Copy a file |
mkdir |
Create (make) a directory |
rmdir |
Delete (remove) a directory |