cp is perhaps one of the most used commands in a
console mode. cp copies a file or files from one location
to another. Since we created the file called log and it is
currently in the wrong directory, let us move it inside the photo
directory. You can do so by issuing cp log photo/ but
perhaps it is better to call the log file not just log but
log.txt, so that it would be obvious to a Windows user
that it is a text file. Type in
cp log photo/log.txt
and enter to execute the command.
You can go inside the photo directory and check if the
copying has been done properly. cd photo and then ls
. The file should be there. Let's add to the log file by saying that it
has been moved from Music to photo. Issuing
nano log.txt
will bring up the text. Add a line to say it has been moved, and
then save and quit the application by Ctrl+x.
Oh, but we forgot to delete the original log file in
the Music folder. Let's just get back to the Music
directory using cd .. and remove the log file
by issuing rm log. The rm command removes a
file or files. For example, if you would like to remove all photos with
.jpg extension but not with .png, you can issue a command something
like:
rm *.jpg
This will remove all the files with .jpg extension within the
directory you are in. Note that the rm command will not
ask you to confirm your order. It will just carry out your instructions
without further ado and once a file is removed, it is deleted forever.
You cannot recover it from the recycle bin.
In this example, we used cp to copy the log file and
then later on deleted it. Normally, this would be done by issuing a
mv command;
mv log photo/
You can also use the mv command to rename a file. Let's
say that you did not like the earlier decision to call the log file
log.txt and you now want to rename it as log again.
Type in
mv photo/log.txt photo/log
and execute the command. Now the file name has been changed back to
log.