Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-02-2011, 10:02 AM
|
#1
|
Member
Registered: Apr 2006
Location: Athens, Greece
Distribution: slackware, debian, ubuntu
Posts: 667
Rep:
|
using locate with rm
Hello everyone,
does anyone know how can I use locate with rm?
rm `locate "some file"`
does not work when my pathnames occasionally contain:
-spaces and other characters (like + or possibly others that need escaping)
-greek characters
how can I grab line-by-line the output from locate and wrap quotes"" around the paths??
Thank you for your help
|
|
|
03-02-2011, 10:07 AM
|
#2
|
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
locate "some file" | sed 's/.*/"&"/' | xargs rm
Locate will also return files where "some file" is a part of the filename. Be carefull. Try it without the xargs command first.
locate usually is configured for system files, not files under /home. The find command may be better to use.
example:
find music/ -iname "some file" -print0 | xargs -0 rm
Last edited by jschiwal; 03-02-2011 at 10:08 AM.
|
|
1 members found this post helpful.
|
03-02-2011, 11:07 AM
|
#3
|
Member
Registered: Apr 2006
Location: Athens, Greece
Distribution: slackware, debian, ubuntu
Posts: 667
Original Poster
Rep:
|
i'm on a preconfigured system running busybox .. and find is not the standard find, not all options are enabled unfortunately.
it's also pain to search through 3.6TB of data with find ...
you are correct about being extra careful when deleting with locate and find. I did check the output of locate thoroughly before piping to xargs rm..
your command works wonderfully. truth is I should have thought about it but i'm not very keen on the use of sed yet.
Thank you
|
|
|
03-02-2011, 11:25 AM
|
#4
|
Senior Member
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339
|
Just to note, that the locate database is usually rebuild each night by a cron-job. Hence the output you get might not reflect necessarily the actual list of files.
|
|
|
03-02-2011, 11:27 AM
|
#5
|
Member
Registered: Apr 2006
Location: Athens, Greece
Distribution: slackware, debian, ubuntu
Posts: 667
Original Poster
Rep:
|
i'm aware..
and have altered it to update the index every few hours.
at any rate for up to date info I run 'updatedb' directly
|
|
|
03-02-2011, 11:27 AM
|
#6
|
LQ Veteran
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,336
|
check the locate manpage for passing it regex - you can be *very* specific if you wish.
|
|
|
All times are GMT -5. The time now is 08:21 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|