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?
02 Answers
Your syntax is okay:
cp /path/to/directory/of/file/*.dat /path/to/destinationBut note make sure it's the only file with that .dat extension else all such files with that extension will be copied also.
Note:
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/destinationIf 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
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.