LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 02-09-2010, 02:56 PM   #1
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Rep: Reputation: 16
loop through a DIR to delete files by inode


I have a directory that contains some files (over a 1,000) that have a '\' in the filename. There are also some good files that I need to keep. therefore I need a script to delete based on inode.

What I have thus far:
list="$(ls -il /opt/PC/log/*RPOUT*.xml)" #this gives me the list
# I need to get the inode of.
for i in $list
do
find . -inum $i -exec rm -i {} \;
echo "delete file" $i >> /home/me/tmp/del_inode.txt
done
echo 'completed'

I know this is not right ... what I know is is the 'find' is. I need to loop through the $list gleaning inodes to get all the files with '\' delete. I'm not sure how. The $i gives me the whole line. I just want the first position.
set $() does not seem to work ... any ideas?
 
Old 02-09-2010, 03:13 PM   #2
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora, Lubuntu, FreeBSD
Posts: 3,930
Blog Entries: 5

Rep: Reputation: Disabled
That approach seems overly complicated to me. Have a look at this:
Code:
$ touch foo 'ba\r' baz 'b\o\o'

$ ls
ba\r  baz  b\o\o  foo

$ rm *\\*

$ ls
baz  foo
P.S. Before attempting to delete anything, take backups of the directory.
 
Old 02-09-2010, 03:24 PM   #3
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
Wink I'll be ... loop was way too complicated

Thanks anomie.

I was way over thinking this. That worked like a champ.

Thank you!!! you get a gold star for the day ...
 
Old 02-09-2010, 03:39 PM   #4
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
rm: Argument list too long

what about:

-bash: /bin/rm: Argument list too long

is there a solution for that? It appears to be a limitation for rm as there is a very large list of files.
 
Old 02-09-2010, 03:57 PM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Perhaps this will work.
Code:
find . -name "*\\\*" -delete
Of course, don't add the -delete option until after you've confirmed which files it will be deleting.
 
Old 02-09-2010, 04:05 PM   #6
j-me
Member
 
Registered: Jan 2003
Location: des moines, ia
Distribution: suse RH
Posts: 123

Original Poster
Rep: Reputation: 16
Wink rm - Argument list too long

You guys are just awesome with solutions. There was 12137 files and rm puked but find worked fine.

Thanks!!!
 
  


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 On
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 03:42 AM
Delete files matching text - using a loop anjanesh Linux - General 3 09-26-2009 03:19 AM
Can delete files in one smb share but not in another - using cifs.mount in active dir Lordandmaker Linux - Server 4 02-12-2009 05:34 AM
Command to display /dir, /dir/sub, /dir/sub/files knockout_artist Linux - Newbie 9 10-25-2007 02:57 PM
Recursive Delete DIR and Sub Dir with CONTENTS jCash Linux - Newbie 1 05-14-2007 05:54 PM


All times are GMT -5. The time now is 08:08 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