To copy a file in linux, we use a command called "cp". We need atleast two things to copy a file. One is the file or folder that we want to copy. The second one is the place where we want to save that file.
We are going to copy a file "/course/cat/catsample1.txt" into a directory "/backup"
I didn't have /backup directory that is why I am creating the directory at first.
source file is /course/cat/catsample1.txt
Destination directory=> /backup
We are going to copy a file "/course/cat/catsample1.txt" into a directory "/backup"
I didn't have /backup directory that is why I am creating the directory at first.
source file is /course/cat/catsample1.txt
Destination directory=> /backup
Rename the destination file name while copying .
we are copying a file /course/cat/catsample1.txt to /backup and renaming it into cat1.txt
we are copying a file /course/cat/catsample1.txt to /backup and renaming it into cat1.txt
Copy the entire directory
To copy an entire directory from one location to another we should use a switch "-r" with cp.
"-r" switch means recursive
copying the directory "/sampledata" into /backup/data/
1. Creating the directory /backup/data
To copy an entire directory from one location to another we should use a switch "-r" with cp.
"-r" switch means recursive
copying the directory "/sampledata" into /backup/data/
1. Creating the directory /backup/data
2. Listing Contents inside /sampledata.
3. Copying the entire directory /sampledata into /backup/data
4. Confirming that the copying was successful.
we can see a copy of "/sampledtat" inside /backup/data
we can see a copy of "/sampledtat" inside /backup/data
Copying all the contents from a directory instead of copying the entire directory
Copying all data from "/sampledata" to "/backup/mydata"
"*" Means that all files, /sampledata/* means all files from /sampledata
Copying all data from "/sampledata" to "/backup/mydata"
"*" Means that all files, /sampledata/* means all files from /sampledata
Copying a directory and save with another name
In step 2 we copied a directory called /sampledata and saved its copy as /mydata.
In step 2 we copied a directory called /sampledata and saved its copy as /mydata.