Register
It is currently Wed Sep 17, 2014 5:35 pm

find function and inodes


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sun Sep 27, 2009 2:25 pm   

Joined: Sun Sep 27, 2009 2:17 pm
Posts: 1
I am trying to write a program that finds files with multiple names. I am using the find function but Im having trouble formatting the output. I would like it to print the inode number in the first line, then all the names of the file in the following lines.
like this:
inode1;
filename1
filename2
filename3
inode2;
filename1
filename2

This is my code so far:

Code:
#!/bin/bash

dir=$1

find $1 ! -type d -links +2 -printf "%i;\\n  %p\\n" 2</dev/null | sort


Top
 Profile  
 PostPosted: Sun Sep 27, 2009 10:13 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
I think you could do something clever, like put the inode number in front of each filename, then sort, then remove the prepended inode numbers with sed.

Code:
#!/bin/bash

dir=$1

find $1 ! -type d -links +2 -printf "%i;\\n%i::%p\\n" 2</dev/null | sort | sed -e 's/[0-9]+:://'


This might end up sorting the inodes after the filenames, so you might have to stick some extra characters in there and remove them. Try this out and let me know if it works. (I didn't test it :) )

-thobbs


Top
 Profile  
 PostPosted: Mon Sep 28, 2009 10:18 pm   
User avatar

Joined: Sat Jun 13, 2009 8:53 pm
Posts: 73
Location: Texas!
Oops, I forgot that you should use the unique switch for sort, -u. This will get rid of the inode number being repeated a bunch of times.

Code:
#!/bin/bash

dir=$1

find $1 ! -type d -links +2 -printf "%i;\\n%i::%p\\n" 2</dev/null | sort -u | sed -e 's/[0-9]+:://'


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP