 |
|
 |
|
11-02-05 10:56 PM
Hello,
Is there any easy way to move or copy files *only* if a certain bit
(execute bit, in my case) is set? Basically "mv [all files with execute
bit set] /tmp".
I'm sure I could whip something up in C to read the permissions and then
move them. But I'm guessing that there must be a quick and simple way
to do this in a shell script.
I've done a Google search, but it's kind of a hard topic to search on,
so I haven't come up with anything useful.
Thank you in advance,
--
Sean
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-02-05 10:56 PM
On Wed, 02 Nov 2005 14:01:36 -0500, Fao, Sean wrote:
> Hello,
>
> Is there any easy way to move or copy files *only* if a certain bit
> (execute bit, in my case) is set? Basically "mv [all files with execu
te
> bit set] /tmp".
>
> I'm sure I could whip something up in C to read the permissions and then
> move them. But I'm guessing that there must be a quick and simple way
> to do this in a shell script.
man find
> I've done a Google search, but it's kind of a hard topic to search on,
http://groups.google.com/advanced_group_search
find perm mv in the first box and
asterisk linux asterisk in the Newsgroup box aught to do it.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-02-05 10:56 PM
On 2005-11-02, Fao, Sean <enceladus311@yahoo.comI-WANT-NO-SPAM> wrote:
> Hello,
>
> Is there any easy way to move or copy files *only* if a certain bit
> (execute bit, in my case) is set? Basically "mv [all files with execu
te
> bit set] /tmp".
find(1) is your friend.
heh - sorry, couldn't say that with a straight face. but still, probably the
best way to do this without hand-coding something in C is to use find.
#find regular files with any execute bit set and move to /tmp
find -type f -mode +0111 -exec mv {} /tmp \;
You should probably check the manpage - in particular, it can be done more
efficiently with + instead of \; on some systems, but not all, and particula
rly
not gnu. Also check xargs(1).
> I'm sure I could whip something up in C to read the permissions and then
> move them. But I'm guessing that there must be a quick and simple way
> to do this in a shell script.
>
> I've done a Google search, but it's kind of a hard topic to search on,
> so I haven't come up with anything useful.
>
> Thank you in advance,
>
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-02-05 10:57 PM
Fao, Sean wrote:
> Hello,
>
> Is there any easy way to move or copy files *only* if a certain bit
> (execute bit, in my case) is set? Basically "mv [all files with execu
te
> bit set] /tmp".
Erg...I feel like such an idiot! I've used find in the way you both
suggested and I knew exactly how to do it, but I was being stupid. Oh
well...
Thank you both very much for your help. I'll attempt to not be such a
dummy in the future!
--
Sean
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-02-05 10:57 PM
LS0tLS1CRUdJTiBQR1AgU0lHTkVEIE1FU1NBR0Ut
LS0tLQ0KSGFzaDogU0hBMQ0KDQpKb3JkYW4g
QWJlbCA8am1hYmVsQHB1cmR1ZS5lZHU+ICgwNS0x
MS0wMiAxOToyMDo1NCk6DQoNCj4gI2ZpbmQg
IHJlZ3VsYXIgZmlsZXMgICB3aXRoIGFueSBleGVj
dXRlIGJpdCBzZXQgICBhbmQgbW92ZSB0byAv
dG1wDQo+IGZpbmQgICAgICAgICAtdHlwZSBmICAg
ICAgICAgICAgICAgIC1tb2RlICswMTExICAg
LWV4ZWMgbXYge30gL3RtcCBcOw0KDQoNCkV2ZW4g
ZWFzaWVyIHZlcnNpb246DQoNCiAgY3AgJChm
aW5kIC10eXBlIGYgLW1vZGUgLi4uKSBERVNUSU5B
VElPTg0KICBtdiAkKGZpbmQgLXR5cGUgZiAt
bW9kZSAuLi4pIERFU1RJTkFUSU9ODQoNCkFzIGFs
cmVhZHkgc2FpZCwgY2hlY2sgb3V0IHRoZSBt
YW5wYWdlIGZvciBob3cgdG8gdXNlIHRoZSAtbW9k
ZSBvcHRpb24uDQoNClJlZ2FyZHMuDQoNCg0K
LSAtLSANCihoa3ApIHN1YmtleXMucGhwLm5ldCAo
bGRhcCkga2V5c2VydmVyLnBncC5jb20gKGh0
dHApIHd3dy5rZXlzZXJ2ZXIuZGUNCklEOiBDRTQw
MjAxMiAoMEYxMiAwOTEyIERGQzggMkZDNSBF
MkI4ICBBMjNFIDZCQUMgOTk4RSBDRTQwIDIwMTIp
DQoNCi0tLS0tQkVHSU4gUEdQIFNJR05BVFVS
RS0tLS0tDQpWZXJzaW9uOiBHbnVQRyB2MS40LjEg
KEdOVS9MaW51eCkNCg0KaUQ4REJRRkRhVXFI
YTZ5WmpzNUFJQklSQXFPQUFLQ2hMVzFTcHRBY0JY
dm4zeGczVXMwNFdkam95d0NhQXQxYw0KQU1R
MGM0SWdjOTI2SXJLN2pDL0xuTjg9DQo9WldMRw0K
LS0tLS1FTkQgUEdQIFNJR05BVFVSRS0tLS0t
DQo=
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-03-05 07:50 AM
On 2005-11-02, Ertugrul Soeylemez wrote:
>
> Jordan Abel <jmabel@purdue.edu> (05-11-02 19:20:54):
>
>
>
> Even easier version:
>
> cp $(find -type f -mode ...) DESTINATION
> mv $(find -type f -mode ...) DESTINATION
Both of which will fail if any filenames contain spaces.
> As already said, check out the manpage for how to use the -mode option.
The -mode option is non-standard.
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-03-05 12:50 PM
"Chris F.A. Johnson" <cfajohnson@gmail.com> (05-11-02 23:54:05):
> On 2005-11-02, Ertugrul Soeylemez wrote:
>
> Both of which will fail if any filenames contain spaces.
The former version would fail as well. You have to enclose '{}' in
quotes. At least this version is much faster, because it doesn't call
cp/mv 100 times for 100 files.
>
> The -mode option is non-standard.
I don't even have that option. I'd have used -perm, if I had to do it
with 'find'.
That's why I love zsh. In zsh I'd have done that via normal filename
generation, which also doesn't suffer from the delimiting problem:
# zsh-only: copy all owner-executable files in current directory and
# all subdirectories
cp **/*(#q.*) DESTINATION
Regards.
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-03-05 10:57 PM
On 2005-11-03, Ertugrul Soeylemez <never@drwxr-xr-x.org> wrote:
> "Chris F.A. Johnson" <cfajohnson@gmail.com> (05-11-02 23:54:05):
>
>
>
> The former version would fail as well. You have to enclose '{}' in
> quotes. At least this version is much faster, because it doesn't call
> cp/mv 100 times for 100 files.
Why do you need to enclose {} in quotes? find doesn't run its -exec arg
uments
through a shell.
To get even more non-standard, you could -exec mv {} /tmp +
the real "portable" solution is -print0 and xargs
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-03-05 10:57 PM
Jordan Abel wrote:
> To get even more non-standard, you could -exec mv {} /tmp +
Assuming you refer to the "+" above, it absolutely is standard. It's a
relatively recent addition to SUS and one could argue that it's not
sufficiently portable for that reason. But it *is* standard.
HT
[ Post a follow-up to this message ]
|
|
|
 |
|
 |
|
 |
|
|
 |
Re: mv/cp Only Certain Files |
 |
 |
|
|
11-03-05 10:57 PM
On 2005-11-03, Jordan Abel wrote:
> On 2005-11-03, Ertugrul Soeylemez <never@drwxr-xr-x.org> wrote:
>
> Why do you need to enclose {} in quotes? find doesn't run its -exec a
rguments
> through a shell.
>
> To get even more non-standard, you could -exec mv {} /tmp +
That IS standard, but not portable; some unices have included it
for a while. GNU has included it recently.
> the real "portable" solution is -print0 and xargs
That is neither standard nor portable.
--
Chris F.A. Johnson | Author:
<http://cfaj.freeshell.org> | Shell Scripting Recipes:
Any code in this post is released | A Problem-Solution Approach,
under the GNU General Public Licence | 2005, Apress
[ Post a follow-up to this message ]
|
|
|
 |
|
|
|
|
Sponsored Links |
 |
 |
|
|
 |
All times are GMT. The time now is 03:11 PM. |
 |
|
|
 |
|
 |
|
|
 |
|
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
|
|
|
|
Medical and Health forum | Computer Games Reviews | Graphics design forum
|
 |
|
 |
|