OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Copying Files

Next, let's get some data into our playground. We'll do this by copying a file. Using the cp command, we'll copy the passwd file from the /etc directory to the current work- ing directory:



[me@linuxbox playground]$ cp /etc/passwd .

[me@linuxbox playground]$ cp /etc/passwd .


Notice how we used the shorthand for the current working directory, the single trailing period. So now if we perform an ls, we will see our file:


[me@linuxbox playground]$ ls -l

total 12

drwxrwxr-x 2 me me 4096 2016-01-10 16:40 dir1

drwxrwxr-x 2 me me 4096 2016-01-10 16:40 dir2

-rw-r--r-- 1 me me 1650 2016-01-10 16:07 passwd

[me@linuxbox playground]$ ls -l

total 12

drwxrwxr-x 2 me me 4096 2016-01-10 16:40 dir1

drwxrwxr-x 2 me me 4096 2016-01-10 16:40 dir2

-rw-r--r-- 1 me me 1650 2016-01-10 16:07 passwd


Now, just for fun, let's repeat the copy using the “-v” option (verbose) to see what it does:



[me@linuxbox playground]$ cp -v /etc/passwd .

`/etc/passwd' -> `./passwd'

[me@linuxbox playground]$ cp -v /etc/passwd .

`/etc/passwd' -> `./passwd'


The cp command performed the copy again, but this time displayed a concise message indicating what operation it was performing. Notice that cp overwrote the first copy without any warning. Again this is a case of cp assuming that you know what you’re are doing. To get a warning, we'll include the “-i” (interactive) option:


[me@linuxbox playground]$ cp -i /etc/passwd .

cp: overwrite `./passwd'?

[me@linuxbox playground]$ cp -i /etc/passwd .

cp: overwrite `./passwd'?


Responding to the prompt by entering a “y” will cause the file to be overwritten, any other character (for example, “n”) will cause cp to leave the file alone.


Top OS Cloud Computing at OnWorks: