I copied some file from source folder into destination folder by using bellow command line in terminal.
sudo cp From_SOURCE/* To_DESTINATION/
Now I want to undo this command.
If I understand well, the following is the case:
The script below looks in the original (source) directory and lists those files. Then it looks into the directory you copied the files to, and removes only the listed files, as they exist in the source directory.
How to use
First try on a test directory if I understood well what you need to achieve!
If the sourcedirectory is "flat"
In case the source directory has no sub-directories, the script can even be simpler:
If the copy action overwrote (replaced) a similarly named file in the destination, the file will be removed, but the original file will (of course) not be brought back by the script. The assumption is that there are no name clashes.
All files that are present in both
For a step-by-step, explanation, see below.
Simplifying the problem:
To understand what the command we want to undo actually did, we start by simpifying it:
The command we want to undo is
For understanding how to undo,
I'll use the directory names
Now, our command is:
Without options like
That means, we have only copied simple files, and no directories, to
Deciding which files to remove:
Possibly there were files in
Regarding the files that are there, we want to remove only files that have been copied over. These files exist in both directories, with the same name, and the same content.
So we look for these files:
Then, we list all files in src:
and, for each file found, use
Removing the files, carefully:
These files are the ones we want to remove. But to be sure, we move them into a different directory first - and take a look at the commands before running them:
Looks good! Now we can leave out the
All the files from
This is old, but I just wanted to post a pure bash answer:
First change to the directory where you copied the files.