-1

I tried to redirect the result in a directory but it won't let me do it. What am I doing wrong ?

find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" > Poubelle/

bash: Poubelle/: Is a directory

What I'm trying to do is move the listed files in Poubelle.
Thank you in advance

Sandro
  • 3
  • 2
  • What do you want to achiev? The output of find is a list of files, which can be only redirected to a file. If you want to copy the results, you don't need redirection. – Ocaso Protal Oct 01 '19 at 08:27
  • 3
    Possible duplicate of [Find and copy files](https://stackoverflow.com/questions/5241625/find-and-copy-files) or https://stackoverflow.com/questions/17368872/how-to-move-or-copy-files-listed-by-find-command-in-unix or .... – Ocaso Protal Oct 01 '19 at 08:27
  • If you're trying to copy or move all the files that `find` lists, you need to use `-exec cp` or `-exec mv`. You might also want to look into using the `rsync` command. – Barmar Oct 01 '19 at 08:30

1 Answers1

0

Like @Barmar said in the comments you need to use exec command with mv and cp.

you can try using below command :

Moving files to Dir :

find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" -exec mv {} Poubelle/ \;

Copying files to Dir :

find Documents/ -type f -regextype posix-egrep -regex ".+\.(doc|err|out)$" -exec cp {} Poubelle/ \;

And you can also use rsync. A simpler form is :

rsync source destination 

For other options read here.

Pacifist
  • 3,025
  • 2
  • 12
  • 20