Thunder
Thunder

Reputation: 10986

How to move files with find and head

I am trying to find any random 1 file and move to a different location using commandline. The following command displays the file,

find . -maxdepth 1 -type f -name '[!.]*' | head -n 1

Now i am trying to use it to move the file to a different location eg /home/etl in the given example. However I am getting the error head: invalid option -- 'e'

find . -maxdepth 1 -type f -name '[!.]*' | head -n 1 -exec mv {} /home/etl

Could you please correct me.

Upvotes: 0

Views: 817

Answers (1)

Stefan Hegny
Stefan Hegny

Reputation: 2187

The find command ends with the pipe symbol | so you can't continue to use the -exec which is a find parameter behind that. You can use xargs to do something similar.

find . -maxdepth 1 -type f -name '[!.]*' | head -n 1 |xargs -I'{}' mv {} /home/etl

Upvotes: 1

Related Questions