LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-25-2022, 11:51 AM   #1
NewRH
LQ Newbie
 
Registered: Sep 2022
Posts: 18

Rep: Reputation: 0
Find command issue


Hello,

I have checked for a while now but cannot see the mistake in the syntax of this command

I need to find all files owned by user 1 and copy them to the directory /tmp/copy1

This is what I am entering

find / -type f -user user1 -exec cp {} /tmp/copy1 \

I get the error message: missing argument to `-exec'

But is the argument nor "cp"?

Thank you for your help!
 
Old 10-25-2022, 11:58 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,357
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
Three things could be adjusted there.

Code:
find / -path /tmp/copy1 -prune -o -type f -user user1 -exec cp {} /tmp/copy1/ \;
First, a -prune is needed to skip copying the destination directory. It is under / after all.

Then for precision, there ought to be a trailing slash / in the destination to ensure that it is treated as a directory. Otherwise, if it does not already exist, it will be treated as a file.

Lastly, the -exec option needs either a semicolon ; or a plus + to indicate the end of the option. Since a semicolon has meaning in the shell itself, using a backslash \ will ensure that it is passed verbatim to find
 
1 members found this post helpful.
Old 10-25-2022, 12:34 PM   #3
NewRH
LQ Newbie
 
Registered: Sep 2022
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Turbocapitalist View Post
Three things could be adjusted there.

Code:
find / -path /tmp/copy1 -prune -o -type f -user user1 -exec cp {} /tmp/copy1/ \;
First, a -prune is needed to skip copying the destination directory. It is under / after all.

Then for precision, there ought to be a trailing slash / in the destination to ensure that it is treated as a directory. Otherwise, if it does not already exist, it will be treated as a file.

Lastly, the -exec option needs either a semicolon ; or a plus + to indicate the end of the option. Since a semicolon has meaning in the shell itself, using a backslash \ will ensure that it is passed verbatim to find
Thank you! It is working with these additions
 
Old 10-25-2022, 12:47 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,357
Blog Entries: 3

Rep: Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767Reputation: 3767
No problem. But be sure to take another look at the manual page for find and review those options, especially the -o option. The idea is not so much to memorize anything as it is to become familiar with knowing where and how to look things up on demand.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bind issue? DNS issue? Domain provider issue? Cannot reach Apache virtual hosts internally. rnturn Linux - Networking 5 01-26-2020 10:35 AM
Is there software to find network issue? Possible packets dropped or similar issue xmrkite Linux - Software 7 03-17-2015 06:33 PM
[SOLVED] Bash Issue with Find Script: find paths must precede expression: *.txt JockVSJock Programming 4 01-06-2014 09:03 PM
an important issue in find command any help pleas :) bhb Linux - Newbie 3 05-18-2010 06:36 PM
Postfix issue ; Must issue a STARTTLS command first after forcing TLS sarajevo Linux - Server 3 05-14-2009 08:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration