How can I use cp rm or mv commands to manipulate files saved to a list, for example one made like so:

ls Downloads/ | grep example > example.tmp

The point is to be able to view/edit the file list in a file editor before making a final manipulation, and then deleting the tmp.

So for example, the following does not work:

mkdir example_dir && cp -t example_dir < example.tmp 

Is there a way that I could make this work?

Once I get that down, I'd like to simplify the whole process into fewer commands, but... I'm just trying to make it work (and see how it will work at this individual step) first.


Use bash's command substitution:

$ ls -1

Put only a, b, c into a list file.

$ ls -1 | grep -E "^[a-z]$" > list
$ cat list 

Edit the list file if you like, then copy the files:

$ mkdir foo
$ cp $(cat list) -t foo
$ ls foo/
a  b  c
  • would you mind if I asked you what the syntax "^[a-z]$" refers to specifically with what each part means? I understand all of the rest of your solution. Thank you. – Rulent Jan 21 at 9:25
  • We are looking for a set of characters, ^ means started with, [a-z] means from a to z (any of them), $: ended with the same character. It looks for all lines containing a character from a to z. – Ravexina Jan 21 at 23:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.