LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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
 
LinkBack Search this Thread
Old 11-01-2005, 11:16 PM   #1
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Rep: Reputation: 15
Deleting backup files in my system.


Hey, I dont know how to do it... I really dont like that my system start populating of:

filex.sss~
cuacua.sxcv~


I have tryied to do a simple thing

Code:
ls -a -p --recursive| grep "~"
with that I will get all the archives that have a ~... bu by the way, also if they start or have a intermediate ~ in the name (I guess).. wich is the correct way for find the backup files???

And wich is the correct way of do some like:

Code:
ls -a -p --recursive| grep "~" | rm
 
Old 11-02-2005, 12:06 AM   #2
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
You could do something like...

Code:
find -name "*~" | xargs rm
that will remove all files matching the pattern "*~" (all files ending with a ~) recursively, from the current directory onward... so... excercise caution.
 
Old 11-02-2005, 12:20 AM   #3
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Original Poster
Rep: Reputation: 15
Thx for the tip, I have finded a problem, it delete the files that dosent contain spaces, so for example:

Code:
rea@linux:/pro_extern/txl10.4a.linux/ChallengeFiles> ls
cal.Txl        expression.cal  Input3.tu   questions 1.txt   t1.2.Txl  t1.Txl    t2.3.Txl  t3.Txl
cha1.Txl       Input1.tu       Input4.tu   questions 1.txt~  t1.3.Txl  t2.1.Txl  t2.Txl    Turing.Grm
Challenge.txt  Input2.tu       Prueba.Txl  t1.1.Txl          t1.4.Txl  t2.2.Txl  t3.1.Txl  Turing.Txl
rea@linux:/pro_extern/txl10.4a.linux/ChallengeFiles> find -name "*~" | xargs rm
rm: no se puede borrar «./questions»: No existe el fichero o el directorio
rm: no se puede borrar «1.txt~»: No existe el fichero o el directorio
I see that is taking the space like a separator, is is "questions 1.txt" not "questions" "1.txt"... , thx by the way .



EDIT:


Like I see now, xargs pass arguments... I guess that is passing questions 1.txt... I have tryied enter the command manually, and I see that for pass the space, there should be an backslash "\" before the space char, some like instead of pass questions 1.txt, pass questions\ 1.txt, now is that possible?????

Last edited by hgb; 11-02-2005 at 12:29 AM.
 
Old 11-02-2005, 12:44 AM   #4
zhangmaike
Member
 
Registered: Oct 2004
Distribution: Slackware
Posts: 376

Rep: Reputation: 31
Hmmm...

Code:
find -name "*~"  -printf "\"%p\"\n" | xargs rm
will do the same thing, but because of the -printf option, it will print each filename within quotes... which may do the trick.

EDIT: Ah... okay... make sure the -printf option is LAST! (... if it isn't, it will delete all files recursively)

Last edited by zhangmaike; 11-02-2005 at 12:51 AM.
 
Old 11-02-2005, 12:59 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
How about:

Code:
find -type f -name "*~" -exec rm "{}"  \;

Cheers,
Tink
 
Old 11-06-2005, 04:46 PM   #6
hgb
Member
 
Registered: Jun 2004
Distribution: Mandrake 10, SUSE 10.x, DEbian
Posts: 125

Original Poster
Rep: Reputation: 15
Hi there, thx for the suguestionts, they work like a charm.

I have now tryied delete a specific dirs and its contents recursively, for example CVS folders in a project.


Tought I havent finded a good way of do it, also dont know if will work if the files or the directoires contain spaces....

And is a thing of 2 +1 steps....

Step 1) Write this (for delete CVS folders and contents):


Code:
find -type d -name "CVS"  -printf "\"%p\"\n" | xargs ls | xargs
After that, there will be a output like

Code:
./CVS: Entries Repository Root ./etc/CVS: Entries Repository Root ./etc/interface/CVS: Entries Repository Root

Step 2) copy the output (dont a nice way.. but work... :S)



Step 3) run deleter [paste here the output] OR in this case #deleter ./CVS: Entries Repository Root ./etc/CVS: Entries Repository Root ./etc/interface/CVS: Entries Repository Root

Where deleter is the name of the program output of the following code....

Code:
#include <stdio.h>
#include <string.h>

#define MAX_BUFFER 1024
int main(int argCount, char *argStringList[]){
	int i=0, lenOfCurDir=0;
	char dirString[MAX_BUFFER*2];
	char dirString2[MAX_BUFFER*2];
	char fString[MAX_BUFFER*2];
	dirString[0] = '\0';
	while(i < argCount -1){
		if( (char) argStringList[i+1][0] == '.'){
			if( strlen(dirString) != 0){
				sprintf(dirString2, "rmdir %s", dirString);
				system(dirString2);
			}
			lenOfCurDir = strlen(argStringList[i+1]);
			argStringList[i+1][lenOfCurDir-1] = '/';
			sprintf(dirString, "%s", argStringList[i+1]);
		}else{
			sprintf(fString, "rm %s%s", dirString, argStringList[i+1]);
			system(fString);
		}
		i++;
	}
	return 0;
}
That will delete the files and dirs using system thing... also dont know if this will work if the dirs or files have a space(s) in the name.


But at less have worked OK here...

Last edited by hgb; 11-06-2005 at 04:49 PM.
 
Old 11-07-2005, 12:15 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,950
Blog Entries: 11

Rep: Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860Reputation: 860
find -type d -name "CVS" -exec rm -rf "{}" \;


Cheers,
Tink
 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are 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
X server deleting system files bkersey Linux - Software 3 11-02-2003 09:52 PM
Deleting files ShakyJake Linux - Newbie 12 05-08-2003 03:07 PM
Deleting files Tingle Linux - Newbie 4 01-16-2003 04:19 PM


All times are GMT -5. The time now is 02:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration