Manipulating Files

In the preceding sections, you looked at listing files and viewing their content. In this section, you will look at copying, renaming, and removing files using the cp, mv, and rm commands.

Copying Files (cp)

The cp command (short for copy) is used to make a copy of a file. The basic syntax of the command is

cp src
							dest
						

Here src is the name of the file to be copied (the source) and dest is the name of the copy (the destination). For example, the following command creates a copy of the file fruits in a file named fruits.sav:

$ cp fruits fruits.sav

If dest is the name of a directory, a copy with the same name as src is created in dest. For example, the command

$ cp fruits Documents/

creates a copy of the file fruits in the ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.