Pipe results of locate into rm
I tried running
locate *.orig | xargs rm
but it said No such file or directory
I've seen ways to do it with find
but locate returns the full path to the object so it should be possible
bash gnome-terminal rm
add a comment |
I tried running
locate *.orig | xargs rm
but it said No such file or directory
I've seen ways to do it with find
but locate returns the full path to the object so it should be possible
bash gnome-terminal rm
add a comment |
I tried running
locate *.orig | xargs rm
but it said No such file or directory
I've seen ways to do it with find
but locate returns the full path to the object so it should be possible
bash gnome-terminal rm
I tried running
locate *.orig | xargs rm
but it said No such file or directory
I've seen ways to do it with find
but locate returns the full path to the object so it should be possible
bash gnome-terminal rm
bash gnome-terminal rm
edited Oct 22 '10 at 19:35
soldier.moth
asked Oct 22 '10 at 19:24
soldier.mothsoldier.moth
132111
132111
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
If filenames contain spaces you should use
locate -0 $something | xargs -0 rm
From locate
man page:
-0
,--null
Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).
or
locate $something | while read f; do rm "$f"; done
Also, you should protect *.orig
with quotes, to avoid the shell expansion, and pass it to locate untouched.
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use| while read
since my home directory is full of files with spaces.
– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern*.orig
, the shell will expand the pattern to, say,file1.orig file2.orig ...
, so thatlocate
will not see the exact string*.orig
as it should.
– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can thentr 'n' ''
.
– Pablo Bianchi
Jan 2 at 19:13
add a comment |
It's xargs
not xarg
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
add a comment |
The command locate *.orig | xargs rm
does work actually but what was happening was that locate
was finding *.orig
files in the trash can and rm
spits out the error No such file or directory
when trying to delete files in the trash can.
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
add a comment |
locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.
Just use
locate .orig
and if that gets you what you need
locate .orig | xargs rm
or, as enzotib mentioned
locate -0 .orig | xargs -0 rm
if you have Whitespace in the filenames.
add a comment |
A trick : Save all paths in tmp file . then , Loop on it:
#!/bin/bash
locate .orig /tmp/tmp.txt
while read line
do
pth=$line
rm "$pth"
done < /tmp/tmp.txt
rm -rf /tmp/tmp.txt
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f8933%2fpipe-results-of-locate-into-rm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
If filenames contain spaces you should use
locate -0 $something | xargs -0 rm
From locate
man page:
-0
,--null
Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).
or
locate $something | while read f; do rm "$f"; done
Also, you should protect *.orig
with quotes, to avoid the shell expansion, and pass it to locate untouched.
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use| while read
since my home directory is full of files with spaces.
– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern*.orig
, the shell will expand the pattern to, say,file1.orig file2.orig ...
, so thatlocate
will not see the exact string*.orig
as it should.
– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can thentr 'n' ''
.
– Pablo Bianchi
Jan 2 at 19:13
add a comment |
If filenames contain spaces you should use
locate -0 $something | xargs -0 rm
From locate
man page:
-0
,--null
Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).
or
locate $something | while read f; do rm "$f"; done
Also, you should protect *.orig
with quotes, to avoid the shell expansion, and pass it to locate untouched.
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use| while read
since my home directory is full of files with spaces.
– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern*.orig
, the shell will expand the pattern to, say,file1.orig file2.orig ...
, so thatlocate
will not see the exact string*.orig
as it should.
– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can thentr 'n' ''
.
– Pablo Bianchi
Jan 2 at 19:13
add a comment |
If filenames contain spaces you should use
locate -0 $something | xargs -0 rm
From locate
man page:
-0
,--null
Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).
or
locate $something | while read f; do rm "$f"; done
Also, you should protect *.orig
with quotes, to avoid the shell expansion, and pass it to locate untouched.
If filenames contain spaces you should use
locate -0 $something | xargs -0 rm
From locate
man page:
-0
,--null
Separate the entries on output using the ASCII NUL character instead of writing each entry on a separate line. This option is designed for interoperability with the --null option of GNU xargs(1).
or
locate $something | while read f; do rm "$f"; done
Also, you should protect *.orig
with quotes, to avoid the shell expansion, and pass it to locate untouched.
edited Jan 2 at 18:28
Pablo Bianchi
2,4451530
2,4451530
answered Oct 22 '10 at 19:39
enzotibenzotib
63k6132154
63k6132154
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use| while read
since my home directory is full of files with spaces.
– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern*.orig
, the shell will expand the pattern to, say,file1.orig file2.orig ...
, so thatlocate
will not see the exact string*.orig
as it should.
– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can thentr 'n' ''
.
– Pablo Bianchi
Jan 2 at 19:13
add a comment |
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use| while read
since my home directory is full of files with spaces.
– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern*.orig
, the shell will expand the pattern to, say,file1.orig file2.orig ...
, so thatlocate
will not see the exact string*.orig
as it should.
– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can thentr 'n' ''
.
– Pablo Bianchi
Jan 2 at 19:13
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
What do you mean by "shell expansion"?
– soldier.moth
Oct 22 '10 at 20:58
+1 for your second example. I always use
| while read
since my home directory is full of files with spaces.– matpie
Oct 22 '10 at 21:35
+1 for your second example. I always use
| while read
since my home directory is full of files with spaces.– matpie
Oct 22 '10 at 21:35
@Soldier.moth: if in the current folder there are files corresponding to the pattern
*.orig
, the shell will expand the pattern to, say, file1.orig file2.orig ...
, so that locate
will not see the exact string *.orig
as it should.– enzotib
Oct 23 '10 at 5:39
@Soldier.moth: if in the current folder there are files corresponding to the pattern
*.orig
, the shell will expand the pattern to, say, file1.orig file2.orig ...
, so that locate
will not see the exact string *.orig
as it should.– enzotib
Oct 23 '10 at 5:39
Also to grep locate output you can then
tr 'n' ''
.– Pablo Bianchi
Jan 2 at 19:13
Also to grep locate output you can then
tr 'n' ''
.– Pablo Bianchi
Jan 2 at 19:13
add a comment |
It's xargs
not xarg
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
add a comment |
It's xargs
not xarg
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
add a comment |
It's xargs
not xarg
It's xargs
not xarg
answered Oct 22 '10 at 19:30
macomaco
12.5k32334
12.5k32334
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
add a comment |
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
That's what I meant was typing question from memory thank you though.
– soldier.moth
Oct 22 '10 at 19:35
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
Oh, ok. It looked like the error you'd get putting an incorrect command after |
– maco
Oct 22 '10 at 19:45
add a comment |
The command locate *.orig | xargs rm
does work actually but what was happening was that locate
was finding *.orig
files in the trash can and rm
spits out the error No such file or directory
when trying to delete files in the trash can.
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
add a comment |
The command locate *.orig | xargs rm
does work actually but what was happening was that locate
was finding *.orig
files in the trash can and rm
spits out the error No such file or directory
when trying to delete files in the trash can.
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
add a comment |
The command locate *.orig | xargs rm
does work actually but what was happening was that locate
was finding *.orig
files in the trash can and rm
spits out the error No such file or directory
when trying to delete files in the trash can.
The command locate *.orig | xargs rm
does work actually but what was happening was that locate
was finding *.orig
files in the trash can and rm
spits out the error No such file or directory
when trying to delete files in the trash can.
answered Oct 22 '10 at 21:20
soldier.mothsoldier.moth
132111
132111
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
add a comment |
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
You should add information as a "comment" to the original answer, or you can edit the original answer. This is not an answer to your own question.
– enzotib
Oct 23 '10 at 5:57
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
It is an answer to my question the reason I was getting the error was because locate was finding *.orig files in the trash can and rm couldn't delete them. I accepted your answer and voted up both other answers because they were well written and might help someone who comes along later.
– soldier.moth
Oct 23 '10 at 6:25
add a comment |
locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.
Just use
locate .orig
and if that gets you what you need
locate .orig | xargs rm
or, as enzotib mentioned
locate -0 .orig | xargs -0 rm
if you have Whitespace in the filenames.
add a comment |
locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.
Just use
locate .orig
and if that gets you what you need
locate .orig | xargs rm
or, as enzotib mentioned
locate -0 .orig | xargs -0 rm
if you have Whitespace in the filenames.
add a comment |
locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.
Just use
locate .orig
and if that gets you what you need
locate .orig | xargs rm
or, as enzotib mentioned
locate -0 .orig | xargs -0 rm
if you have Whitespace in the filenames.
locate doesn't do the globbing, but the shell does. The shell expands *.orig to what it finds in the current directory which matches *.orig.
Just use
locate .orig
and if that gets you what you need
locate .orig | xargs rm
or, as enzotib mentioned
locate -0 .orig | xargs -0 rm
if you have Whitespace in the filenames.
answered Mar 20 '11 at 0:11
user unknownuser unknown
4,87122151
4,87122151
add a comment |
add a comment |
A trick : Save all paths in tmp file . then , Loop on it:
#!/bin/bash
locate .orig /tmp/tmp.txt
while read line
do
pth=$line
rm "$pth"
done < /tmp/tmp.txt
rm -rf /tmp/tmp.txt
add a comment |
A trick : Save all paths in tmp file . then , Loop on it:
#!/bin/bash
locate .orig /tmp/tmp.txt
while read line
do
pth=$line
rm "$pth"
done < /tmp/tmp.txt
rm -rf /tmp/tmp.txt
add a comment |
A trick : Save all paths in tmp file . then , Loop on it:
#!/bin/bash
locate .orig /tmp/tmp.txt
while read line
do
pth=$line
rm "$pth"
done < /tmp/tmp.txt
rm -rf /tmp/tmp.txt
A trick : Save all paths in tmp file . then , Loop on it:
#!/bin/bash
locate .orig /tmp/tmp.txt
while read line
do
pth=$line
rm "$pth"
done < /tmp/tmp.txt
rm -rf /tmp/tmp.txt
answered Mar 23 '14 at 18:29
Abdennour TOUMIAbdennour TOUMI
5,09743345
5,09743345
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f8933%2fpipe-results-of-locate-into-rm%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown