cp copies a file. The first argument is the file to copy, the source. The last argument is where the copy goes, the destination. The source stays where it is.
cpcommandprices.txtsource: the file to copyprices.bakdestination: the new copy
Copy to a new name
Make a copy before you change a file. If something goes wrong, you still have the original:
text
learner@tidepool:~/shop$ cp prices.txt prices.bak
learner@tidepool:~/shop$ ls
prices.bak prices.txtThe two files have the same text.
Copy into a directory
When the destination is a directory that exists, the copy goes into it and keeps its name:
text
learner@tidepool:~/shop$ cp prices.txt backup
learner@tidepool:~/shop$ ls backup
prices.txtGive more than one source to copy them all into the directory. The directory is always the last argument:
text
learner@tidepool:~/shop$ cp monday.txt tuesday.txt backupcp writes over files with no question
If the destination file exists, cp replaces its text with the text of the source. It does not ask, and it does not warn you.