O'Reilly logo

Raspberry Pi For Dummies by Mike Cook, Sean McManus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Copying and Renaming Files

One of the fundamental things you’ll want to do with your files is copy them, so take a look at how to do that. The command you need to use is cp, and it takes this form:

cp [options] copy_from copy_to

Replace copy_from with the file you want to copy, and copy_to for where you want to copy it to.

For example, if you wanted to copy the file config.txt from the /boot directory to your home directory (~) so you can safely play with it, you would use

cp /boot/config.txt ~

If you wanted to copy the file into your current working directory, wherever that is, you could use

cp /boot/config.txt .

You can also specify a path to an existing folder to send the file to

cp /boot/config.txt ~/files/

Your original file and the copy don’t have to have the same name. If you specify a different filename, the copy takes that name. For example:

cp /boot/config.txt ~/oldconfig.txt

That copies config.txt from the /boot directory to your home directory and renames it as oldconfig.txt. This same technique enables you to keep a safe copy of a file you’re working on, in case you want to revert to an old version later. The paths are optional, so if you were in your home directory, you could create a backup copy of the file timeplan.txt there using

cp timeplan.txt timeplan.bak

You can use several options with cp, some of them familiar from the rm command. The cp command overwrites any files in its way without asking you, so use the -i option to force it to ask you before it ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required