1 | 2 | 3 | 4 | Current Level: 5 | 6 | 7
cpSuppose you have a file named quotes.txt and want to make a copy in the thesis folder with a new name:
cp quotes.txt thesis/quotations.txt
Check that both files exist:
ls quotes.txt thesis/quotations.txt
Output:
quotes.txt thesis/quotations.txt
Copy the entire thesis directory and its contents to a new folder called thesis_backup:
cp -r thesis thesis_backup
Confirm the contents of both directories:
ls thesis thesis_backup
Output:
thesis:
quotations.txt
thesis_backup:
quotations.txt
-rTry copying a directory without the -r option:
cp thesis thesis_backup
This will result in an error:
cp: -r not specified; omitting directory 'thesis'
Use -r when copying directories to ensure everything inside is copied.
You created a file called statstics.txt, but realize it’s misspelled. Here are some ways to fix it:
mv statstics.txt statistics.txt # Renames the file
cp statstics.txt statistics.txt # Copies the file under a new name
mv is the correct command if you want to fix the name without keeping the original.
Given this sequence of commands:
pwd
# /Users/jamie/data
ls
# proteins.dat
mkdir recombined
mv proteins.dat recombined/
cp recombined/proteins.dat ../proteins-saved.dat
ls
Final output of ls:
proteins-saved.dat recombined
cp require -r when working with folders?cp versus mv?