How to copy a file with unique name without navigating to directory

commandcpfile-copyfilenames

Let's say I have a file with a unique name (e.g.Screenshot20180509143013.png) that I wish to copy to /media/SD256.

The file /media/drive1/Users/name/Pictures/Screenshots/Screenshot20180509143013.png is tangled in some sub-directory levels, and I wish not to navigate to /media/drive1/Users/name/Pictures/Screenshots/ to find that file with the unique name.

Instead, I wish to run a command while my working directory is /media/drive1/, which looks similar to:

copy --find-filename-then-copy Screenshot20180509143*3.png /dev/media/SD256/DestinationFolder

Is there such a command that can first find the file and then copy?

Best Answer

Using find:

find . -type f -name Screenshot20180509143013.png -exec cp {} /dev/media/SD256/DestinationFolder ';'

This would find all regular files in or below the current directory, whose names are exactly Screenshot20180509143013.png. The found files would be copied to /dev/media/SD256/DestinationFolder. If there are multiple files with the same name (which you say there aren't), the files would overwrite each other in the destination directory.

Related Question