Basic UNIX Commands for Beginners: How to Copy, Move or Delete UNIX Files
How to Copy a UNIX FileYou may want to make a copy of a file before making changes to it or for a variety of other reasons.
The cp command is used to make a copy of a file, and uses the following syntax:
$ cp source-filename destination-filenameTwo freqently used copy command options are the -p and -R options. -p is used to preserve the file attributes (e.g., file permissions and date), and -R is used to copy directories recursively.
[ If you are new to UNIX and need an overview of important UNIX commands and concepts, check out our Basic UNIX Commands and Concepts Tutorial for Beginners ]TIP: If you wanted to copy a file to a different directory, you would replace the destination-filename with the absolute or relative path to the directory.
How to Move a UNIX FileThe mv command is used for moving or renaming files.
The syntax is the same as the copy (cp) command:
$ mv source-filename destination-filenameThere's really not too much more to say about the move command.
TIP: If you wanted to move a file to a different directory, you would replace the destination-filename with the absolute or relative pathname to the directory. If you are renaming the file, you will need to add the new name for the file to the end of the absolute or relative pathname.
How to Delete a UNIX FileThe command to delete a file is rm (remove). The syntax of the rm command is:
$ rm filenameThe -f (force) option is often used when deleting files with rm. This causes the command to never ask if you really want to delete the file.
WARNING: Be extremely careful when using the remove command because once the file is gone it can be very difficult to get back. You may be able to have the file restored from an offline backup, assuming that regular backups for the system you work on are being performed. Even if it can be restored, it may not be an up-to-date version of the file.
*Like ALL UNIX commands which are new to you, it is wise to read through the command's man page (e.g., man cp) prior to running the command against production data.
Do you need to learn UNIX or Linux, including how to read and write shell scripts? If you are ready to move past the basics, either of these online courses is a good place to start...
UNIX and Linux Operating System Fundamentals contains a very good "Introduction to UNIX Shell Scripting" module, and should be taken if you are new to the UNIX and Linux operating system environments or need a refresher on key concepts.
UNIX Shell Scripting is a good option if you are already comfortable with UNIX or Linux and just need to sharpen your knowledge about shell scripting and the UNIX shell in general.
Both courses include access to an Internet Lab system for completing the course's hands-on exercises, which are used to re-enforce the key concepts presented in the course. Any questions you may have while taking the course are answered by an experienced UNIX technologist.