LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-28-2006, 02:34 AM   #1
crazydrve
LQ Newbie
 
Registered: Oct 2003
Distribution: linux mandrake 9.1
Posts: 10

Rep: Reputation: 0
deleting multiple files with # in name


ok people i could use some help here.

what i want to do is delete many files like the following
but only delete the files with the (#) in the name.

i cant seem to get wildcards to work.

Safetec
Safetec_#63
Sam Spade Features email lookup_#12
Samoyeds_#12
Samoysdfgaeds_#12
Samoawefrgyeds_#12
Samoyeds_#12
Samoyg5gf4seds_#12
Samoyg5gf4seds
Samoyeds_#12
Samogfvrgyeds_#12
Samoyeds_#12
Samoyeds

i hope u get the idea.

could someone please help.
 
Old 02-28-2006, 03:28 AM   #2
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,492

Rep: Reputation: 50
have you tried enclosing the "#" in square brackets??

e.g try "ls -l *[#]*"

that should just list the ones with "#"

of course you can use rm
 
Old 02-28-2006, 04:21 AM   #3
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683Reputation: 683
If none of the names had whitespace in them then a "rm *_#[[:digit:]][[:digit:]]" command would do it.

For the one example you have "Sam Spade Features email lookup_#12" this won't work, because the spaces will cause the shell to consider them to be separate filenames: Sam, Spade, Features, email and lookup_#12.

Another potential problem is if you have something like 30,000 filenames that could contain the pattern. That would cause a memory error when expanded on the command line for "rm".

You can solve both problems using find and xargs. The -print0 option of find, causes it to separate each result with a null character instead of a line return. The -0 option of xargs tells it to read in arguments that are separated with the null character.

find ./ -name "*_#[[:digit:]][[:digit:]]" -print0 | xargs -0 rm

If the current directory contains subdirectories that you don't want to traverse, then you need to add the '-maxdepth 1' argument.
find ./ -maxdepth 1 -name "*_#[[:digit:]][[:digit:]]" -print0 | xargs -0 rm

Look in the man page of xargs. There are different options on how to limit the size of the input.

The find example I used assumed you wanted to start in the current directory. You could use something like "$HOME/Documents/" instead.

Last edited by jschiwal; 02-28-2006 at 04:22 AM.
 
Old 02-28-2006, 11:20 PM   #4
crazydrve
LQ Newbie
 
Registered: Oct 2003
Distribution: linux mandrake 9.1
Posts: 10

Original Poster
Rep: Reputation: 0
Fortuanely I found a Windows quick solution.
the files I wanted to keep didnt have the # sign or numbers.
so I bascially searched for files that had the # sign.
and that did it. Shut I have been working on this since last summer.
I feel reaaly stupid considering I have a computer science degree.

doah.

Now would there be a way in linux to just search for 1 wildcard like the # sign?

thanks for the help everybody.
 
Old 03-01-2006, 01:47 AM   #5
satinet
Senior Member
 
Registered: Feb 2004
Location: England
Distribution: Slackware 14.2
Posts: 1,492

Rep: Reputation: 50
what do you mean "#"? it isn't a wild card.

if you tried what i suggested you would have found only files with "#" in them...

Last edited by satinet; 03-01-2006 at 03:02 AM.
 
Old 03-01-2006, 02:41 AM   #6
kevkim55
Member
 
Registered: Dec 2005
Location: Edmonton
Distribution: BLFS, Gentoo
Posts: 353

Rep: Reputation: 32
Why don't you try Find Files in kde or even gnome which has a similar interface as that of Windoz if, all that you looking for is an easy and minimum keystroke gui app ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting files in C monil Programming 4 03-13-2005 10:33 AM
Deleting files! a_priebe47 Slackware 6 10-17-2004 09:58 PM
deleting recent files Santas Linux - General 2 01-19-2004 06:26 AM
Deleting files ShakyJake Linux - Newbie 12 05-08-2003 03:07 PM
Deleting files Tingle Linux - Newbie 4 01-16-2003 04:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration