This is a discussion on find and cp in one command... within the HP-UX Operating System forums, part of the Unix Operating Systems category; --> This is my find: find ./ -name "*" -mtime -1 I need to pipe that to cp to move ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| "Robert Hicks" <sigzero@gmail.com> writes: > find ./ -name "*" -mtime -1 > > I need to pipe that to cp to move it to /tmp/20060810LK78 mv `find . -name "*" -mtime -1` /tmp/20060810LK78 If this gives you "command line too long", then find . -name "*" -mtime -1 | xargs -i mv {} /tmp/20060810LK78 Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
| |||
| Paul Pluzhnikov wrote: > "Robert Hicks" <sigzero@gmail.com> writes: > > > find ./ -name "*" -mtime -1 > > > > I need to pipe that to cp to move it to /tmp/20060810LK78 > > mv `find . -name "*" -mtime -1` /tmp/20060810LK78 > > If this gives you "command line too long", then > > find . -name "*" -mtime -1 | xargs -i mv {} /tmp/20060810LK78 > > Cheers, > -- > In order to understand recursion you must first understand recursion. > Remove /-nsp/ for email. Thanks! I can pipe some things but others throw me. Robert |
| |||
| "OldSchool" <scott.myron@fds.com> writes: > find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 \; This works too, but is much less efficient than the xargs solution, because it fork()s/exec()s for each matching file. This may matter if you want to move a couple thousands of files. Cheers, -- In order to understand recursion you must first understand recursion. Remove /-nsp/ for email. |
| |||
| · Paul Pluzhnikov <ppluzhnikov-nsp@charter.net>: > "OldSchool" <scott.myron@fds.com> writes: > >> find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 \; > > This works too, but is much less efficient than the xargs solution, > because it fork()s/exec()s for each matching file. Yep. Because of that, it's better to do find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 + xargs isn't needed. Alexander Skwar -- Zeichnen ist Sprache für die Augen, Sprache ist Malerei für das Ohr. -- Joseph Joubert |
| |||
| Paul Pluzhnikov <ppluzhnikov-nsp@charter.net> writes: > "Robert Hicks" <sigzero@gmail.com> writes: > > > find ./ -name "*" -mtime -1 > > > > I need to pipe that to cp to move it to /tmp/20060810LK78 > > mv `find . -name "*" -mtime -1` /tmp/20060810LK78 > > If this gives you "command line too long", then > > find . -name "*" -mtime -1 | xargs -i mv {} /tmp/20060810LK78 Q: Trying that on Linux, option "-i" caused xargs to create a command for every input line. Same for HP-UX? > xargs -i echo '{}' 4 1 <--- input 1 4 --> output 2 <--- input 2 4 --> output 3 <--- input 3 4 --> output ^D Regards, Ulrich |
| |||
| Alexander Skwar <alexander@skwar.name> writes: > · Paul Pluzhnikov <ppluzhnikov-nsp@charter.net>: > > > "OldSchool" <scott.myron@fds.com> writes: > > > >> find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 \; > > > > This works too, but is much less efficient than the xargs solution, > > because it fork()s/exec()s for each matching file. > > Yep. Because of that, it's better to do > > find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 + > > xargs isn't needed. Unless "mv" is a find built-in, it's more inefficient than using xargs (despite of the issue mentioned in my previous post on this thread). Ulrich |
| |||
| Ulrich Windl <Ulrich.Windl@RZ.Uni-Regensburg.DE>: > Alexander Skwar <alexander@skwar.name> writes: > >> · Paul Pluzhnikov <ppluzhnikov-nsp@charter.net>: >> >> > "OldSchool" <scott.myron@fds.com> writes: >> > >> >> find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 \; >> > >> > This works too, but is much less efficient than the xargs solution, >> > because it fork()s/exec()s for each matching file. >> >> Yep. Because of that, it's better to do >> >> find ./ -name "*" -mtime -1 -exec mv {} /tmp/20060810LK78 + >> >> xargs isn't needed. > > Unless "mv" is a find built-in, it's more inefficient than using xargs Why? -exec cmd True if the executed cmd returns a zero value as exit status. The end of cmd must be punctuated by a semicolon ( (+) (semicolon and plus are special to the shell and must be escaped). When + is used, cmd aggregates a set of path names and executes on the set. Any command arguments between the first occurrence of {} and + are ignored. The reason for preferring + to a ; is vastly improved performance. Any command argument {} is replaced by the current path name. cmd may contain supplementary code set characters. However, my command won't work But please explain why "find . -exec mv {} /foo +" is inefficient. Alexander Skwar -- 94% of the women in America are beautiful and the rest hang out around here. |
| ||||
| Alexander Skwar <alexander@skwar.name> writes: [...] > But please explain why "find . -exec mv {} /foo +" is inefficient. Simple: Consider 15000 files. Then your command will invoke "mv" 15000 times, while an "xargs" solution will invoke "mv" more infrequently. Now if you trace one start of "mv" you can guess how many CPU and I/O cycles you are wasting. Regards, Ulrich > > Alexander Skwar > -- > 94% of the women in America are beautiful and the rest hang out around here. |
| Thread Tools | |
| Display Modes | |
|
|