Nishikant Jain
Nishikant Jain

Reputation: 141

How can i copy only files which are owned by some user in Linux/unix

How can i only copy files which are owned by some user. is there a way to specify user name in copy command? i have few files in my home direct which are owned by some other user, i want to copy only those files to some other directory.How to filter it.

Upvotes: 2

Views: 4230

Answers (1)

Hemang
Hemang

Reputation: 410

You can find the files owned by user with find command and then use cp to copy your files.

Example:

find all .txt files from user:

find /path/to/directory -user <username> -name "*.txt"

You can pipe it with the cp command to copy.

Or a one liner with find:

find /var/www -user vivek -name "*.pl" -exec cp -f source dest

Upvotes: 2

Related Questions