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

18,892

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
    
Share:
18,892

Related videos on Youtube

Swapnil_Shelke
Author by

Swapnil_Shelke

Updated on September 18, 2022

Comments

  • Swapnil_Shelke
    Swapnil_Shelke almost 2 years

    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?