Avoid enter key in cp -i

command linecp

I often need to selectively archive a long list of files using cp -iar, or similar, and to speed up the process I would like to press just one key instead of y or n followed by ENTER on every file. In other words I want to avoid having to press ENTER as well as y or n. Of course I would happily use different keys instead of y or n.

Is there a way to do this?

Best Answer

I think that what you need is a file manager, like midnight commander. In mc you can select several files with insert or + and realize operations on them, like deleting, moving or copying. A full set of instructions and tips can be found in the Tutorial.

If you give it a try to pure shell commands (no gui), suppose you have file0 to file10 but wants to copy only file1 and file3:

cp file1 file3 directory/

Of course, you can use the shell to help yourself:

cp file{1,3} directory/

but what about consecutive ones? file5 through file10?

cp file{5..10} directory/

You can also use find to help, if you want something more advanced, for example:

find Downloads -name "*.cfg" -exec cp {} directory \;

will do this:

copy Downloads/file(6).cfg to directory
copy Downloads/file(7).cfg to directory
copy Downloads/file(1).cfg to directory
copy Downloads/file.cfg to directory
copy Downloads/file(2).cfg to directory
copy Downloads/file(4).cfg to directory
copy Downloads/file(3).cfg to directory
copy Downloads/file(5).cfg to directory

you can verify the files to be copied removing the -exec ... part. You can also use -exec echo cp ... in case you want to know what find will do.