Copy file via terminal with wildcard in command like cp /path/*.dat /dist/path/

I want to copy a file via terminal using a command like

cp /path/*.dat 

As I don't know the full name of the file and I want to copy it to a certain path.

This is the command:

sudo cp /home/ubuntu/test/*.dat /opt/myAppFolder/License/

Will this command work?

0

2 Answers

Your syntax is okay:

cp /path/to/directory/of/file/*.dat /path/to/destination

But note make sure it's the only file with that .dat extension else all such files with that extension will be copied also.

Note:

  1. If already in the folder and the destination is outside that folder then the command would be [note without the "/"]:

    cp path/to/directory/of/file/*.dat /path/to/destination
    #or simply
    cp *.dat /path/to/destination
  2. If already in the folder and both file and destination folder are in same folder location then the command would be [note without the "/" on both source and destination]:

    cp path/to/directory/of/file/*.dat path/to/destination
    #or simply
    cp *.dat path/to/destination
0

It depends at what directory you are right now. If we are already at that directory, we do not need to include that into the path while using sudo cp command.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like