Can anyone help with understand wildcards in the command line?

I am on step 4 on this page:

Could anyone help me understand, why on this step the command “cp * satire”, outputs:
cp: -r not specified; omitting directory ‘satire’
cp: -r not specified; omitting directory ‘slapstick’

I don’t understand why the command doesn’t also copy these files.

The command doesn’t copy “satire” and “slapstick” because they are not files, they are directories. And even though in Linux generally there is no difference between a file and a directory, for the command line this distinction is important.

The output “cp: -r not specified” tells you what you have to do: you have to use the command cp with the -r flag. The flag stands for recursive. And if, and only if, recursive is specified, folders will also be copied/affected. This is also true for other commands like rm (remove).

You can check this by typing man cp, which should have a similar output to this online manual page.


Wow thank you that is a really good answer! Could you also show me how i would use the -r flag in this situation?

1 Like

Well, to solve the exercise, you don’t need to use it. As stated in point four:

You should see a copy of the files the_office.txt and shrek.txt in this directory.

Note how only the copying of the files, not the folders, is required.

If you still would like to copy over files and directories (folders) then you would have to enter the following command:

cp -r * satire/

But wait, this would be met with an error message:

cp: cannot copy a directory, ‘satire’, into itself, ‘satire/satire’

Why? Because you can’t copy a directory (folder) into itself. A more likely scenario where you would want to use the -r flag would be when copying a folder and all its subfolders to a mounted USB drive. Assume you are in a picture folder on your system, and you want to copy this folder and all subfolders (e.g., vacation_pictures/, work_pictures/ etc.) to a USB drive mounted at /media/usb-drive:

cp -r * /media/usb-drive/

Would copy every picture (and every other file) and every subfolder including every file in subfolders to said USB stick.

1 Like

Oh ok awesome, thanks :smile: