Copying Files

As I mentioned before, the "cp" command uses the same syntax as the "mv" command. The difference being that while "mv" moves the original file, "cp" creates a second file with the same contents.

To demonstrate, I'll make a copy of the Tested.txt file, and name it TestedBackup.txt. First, I need to move up a level by typing "cd .." and pressing Enter.

The command I'll use is this: "cp Tested.txt TestedBackup.txt"

Now, if I type "ls" we'll see both files in this directory, and we can also see the change in the Finder. Typing both "less Tested.txt" and "less TestedBackup.txt" show that they contain the same information.

Note: In this series I'll predominantly use "Camel Case" for file and folder names. In "Camel Case", the first letter of each word is capitalized and no spaces are used. I'll explain more about why I choose do that in a later video.

Deleting Files with rm

Deleting files is an even easier command (for better or for worse.) The syntax is simply "rm ". So, let's use it to delete the TestedBackup.txt file.

The command I'll use is this: "rm TestedBackup.txt"

Now, when we use the "ls" command, you'll see that the TestedBackup.txt file is gone.

You'll notice that there is no prompt to confirm the deletion of the file. This means that if you type the wrong file name, or need a file back, there's no way to get it back. The command line doesn't have a trash can or recycle bin like most GUIs do. Once you press Enter, the file is gone forever. So, use this command with extreme caution!

One way to protect yourself from accidentally deleted files is to have a version control system in place. One such system is Git. Git has become the most widely adopted version control system for software development, and is the version control system that Drupal uses on Drupal.org. To learn more about Git, checkout the Git series on this site.

For more information on the rm command, there's a great article on computerhope.com