wils484
wils484

Reputation: 275

How to move all files with a specified owner in Unix?

I have a directory with a large number of files, and I need to separate them by owner. My instinct was to pipe ls output to mv, but I've seen that that is not recommended due to the possibility that filenames could contain special characters. In any case, the closest I can think of is:

ls -l | grep OWNER | find regex_for_filename | mv ../

but this does not work.

Note - I do have a reliable regex for files within the directory, but the ownership is scattered.

Upvotes: 0

Views: 1203

Answers (1)

Wrikken
Wrikken

Reputation: 70460

find -maxdepth 1 -user username -exec mv {} ../ \;

Omit the maxdepth if you need files from subdirectories.

Upvotes: 6

Related Questions