LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Searching for files with special characters (https://www.linuxquestions.org/questions/linux-newbie-8/searching-for-files-with-special-characters-598151/)

Yig 11-08-2007 03:37 PM

Searching for files with special characters
 
Hi,

I'm trying to do a search for files whose name start with #.

All the files look like this:

#cvs.rfl.castor-srvr4.benchmarkcanada.com.19844

Only thing that change is the number at the end.

Problem is, if I go in a directory where I know one of those file is, if I do a find -name #cvs it does not work. I tried to put it between "" but that didn't work either.

Those files are CVS lock files.

So, what is the command I need to execute to find them?

Thanks!

griffey 11-08-2007 03:59 PM

You might try "locate."

Depending on whether or not the mlocate database has been created/updated, you might have to run "updatedb" as root first.

I created a file "#myfile" and updated the database, and typed

locate "#"

(I had to use the quotes) and it admittedly found all files with # anywhere in them (so you may get more back than you bargained for).

If you're better with regular expressions than I am you might have better luck. (Something like \#[A-Za-z0-9]+ ??)

Good luck.

G.--

Yig 11-08-2007 04:06 PM

Great! That worked!

Thanks a lot!

Is there a way to search and delete those files in one step?

Something like

rm 'locate "#cvs.rfl"'

Would that work?

griffey 11-08-2007 04:13 PM

Heh. I don't think so. :)

I'm sure there are WAY more clever ways of doing this, but what I would do in this situation is output that list of files to a text file first.

locate "#" >> cat mylist.txt

Then I would cheat and copy that file to my Mac and search-and-replace all instances of a carriage return and change each carriage return to carriage return + "rm ". You'd have to manually add the "rm " at the first line.

Then you should have a text file with all of the files listed, with "rm " in front of them.

Copy that back to the linux box, make the file executable (chmod +x mylist.txt), and then execute it (./mylist.txt).

Or something like that.

Someone else might (hopefully) have a more clever way of doing it, but that's probably what I would try.

Good luck!

G.--

peart 11-08-2007 05:53 PM

find . -name "#cvs*" -exec rm {} \;


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