LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-28-2005, 02:06 AM   #1
smshuja
LQ Newbie
 
Registered: Dec 2005
Posts: 4

Rep: Reputation: 0
find and delete files - stupid question though


Hi All,
i am very new to linux. we have some files like
!2005-somefile.php
!somefile.fla

how can i find all files that have "!" in the beginning and delete them all from a particular directory like /home/sam

any help would be greatly appreciated.

thanks
shuja
 
Old 12-28-2005, 02:20 AM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
You can either wrap the filename in single quotes like: rm '!2005-somefile.php'
or, escape the ! with: rm \!2005-somefile.php

To find all of these files that are in or under /home/sam you can use something like:
find /home/sam -name '!*' -exec ls -l {} \; # This will display each file - no delete
find /home/sam -name '!*' -exec rm -i {} \; # This will delete each file after you confirm the delete
find /home/sam -name '!*' -exec rm -f {} \; # This will delete each file without confirmation
 
Old 12-28-2005, 02:57 AM   #3
smshuja
LQ Newbie
 
Registered: Dec 2005
Posts: 4

Original Poster
Rep: Reputation: 0
thanks a million, gilead
 
Old 12-28-2005, 03:20 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
No problem - glad it did the job :-)
 
Old 12-29-2005, 12:59 AM   #5
smshuja
LQ Newbie
 
Registered: Dec 2005
Posts: 4

Original Poster
Rep: Reputation: 0
it did delete the files but didnt delete the folders which contain "!" at the beginning.
is there a way to do that?

thanks a lot for the help
shuja
 
Old 12-29-2005, 02:21 AM   #6
nitinatindore
Member
 
Registered: Dec 2004
Location: India
Distribution: Mandrake, Mandriva, PclinuxOS
Posts: 114

Rep: Reputation: 15
The same good old rm command(which gilead had already had rightly said ); you just need to append with -r option.The command below will remove all files with "!*" without confirmation

find /home/sam -name '!*' -exec rm -rf {} \;

In case you are just want to delete directories, not files than use (NOTE: it will only delete empty directories)

find /home/sam -name '!*' -exec rmdir -v {} \;
 
  


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
Cron Question - Delete files in a dir older than 48 hours? t3___ Linux - Newbie 5 10-11-2011 04:42 AM
Stupid, stupid question; I lost Klaptop. :( Surfrider Slackware 2 08-31-2005 10:12 PM
Just one more Stupid Question Uninstall Files?? ddrfreak Mandriva 5 12-12-2004 12:05 PM
Stupid Dumb Stupid Question... drigz Linux - Software 3 09-23-2004 04:09 PM
How to delete the destination files while the source files deleted in cp -u ? myunicom Linux - General 4 09-26-2003 02:13 PM


All times are GMT -5. The time now is 08:43 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration