search for hardlinks based on filename via find command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers search for hardlinks based on filename via find command
# 1  
Old 03-25-2001
Error

I am using command substitution into a find command in a script where I have built a menu to do a bunch of tasks within my unix account. When I choose the options for to find a file/files that have the same inode of the entered filename, ie hardlinks, nothing shows up. When I choose the appropiate options to build my find command everything looks to be in order. I need to know how do I get the hard links to print out. Below is the segment of the menu that I use to build the find command for the find path -inum filename -print:

echo "\n Select the number of the search primary"

echo "\n 1) Search based on inodes (-inodes via filename)"

echo "\n Choice: \c"
read pchoice

case $pchoice in
1) srch_pri='-inum';;
esac

case $pchoice in
1) echo "Filename: \c";
read srch_arg;;
esac

echo "Select number of the action primary"

echo "\n 1) Display the current pathname (-print)"

echo "\n Choice: \c"
read achoice

case $achoice in
1) act_pri = '-print';;
esac

case $achoice in
1) act_arg='';;
esac

path =$HOME

find $path $srch_pri $srch_arg $act_pri $act_arg
# 2  
Old 03-25-2001
find &ltdir&gt ! -type d -links +1 -ls|sort -n

this will print all hardlinks in specified directory, sorted by files i-node.

the ! -type d is to avoid directories.
The -links +1 will find all files that have MORE than 1 link. Hardlinked files have a link count of at least two.
The -ls is used to view the inode number after find has found the file.
- The sort -n will sort the list by inode number showing you which files are hardlinked together.

This will only work if your search includes the directories that contain all of the hardlinked files.


here is anotherway

f=`ls -i $srch_arg |awk '{print $1}'`
find / -inum $f

this will search all system and print any files that is hardlinked with $srch_arg



[Edited by mib on 03-25-2001 at 06:05 AM]
# 3  
Old 03-27-2001
Thank you for your help mib

Thanks, that helped alot.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to find a file based on pattern & return the filename if found?

Hi all, I am a newbie here. I have this requirement to find a file based on a pattern then return the filename if found. I created a script based on online tutorials. Though, I am stuck & really appreciate if anyone can have a quick look & point me to the right direction? #Script starts... (10 Replies)
Discussion started by: buster_t
10 Replies

2. Shell Programming and Scripting

Find the latest file based on the date in the filename

Hi, We've a list of files that gets created on a weekly basis and it has got a date and time embedded to it. Below are the examples. I want to find out how to get the latest files get the date and time stamp out of it. Files are PQR123.PLL.M989898.201308012254.gpg... (1 Reply)
Discussion started by: rudoraj
1 Replies

3. Shell Programming and Scripting

Find command error having space in filename

Hi, I am working in solaris.I am using below script to copy the files from /usr/tmp to /usr/gm But while running this it is not considering the files list after the filename having space in them. Example:- compile_custom_pll.sh conv_data_sqlload.sh conv_sqlload.sh Copy of... (5 Replies)
Discussion started by: millan
5 Replies

4. Shell Programming and Scripting

Only filename from find command

Hi All When we use find command command in Unix we get the result as /home/user/folder/filename1 /home/user/folder/filename2 /home/user/folder/filename3 Is it possible that i only get the file name The expected output when using find command is filename1 filename2 filename3 I am... (13 Replies)
Discussion started by: parthmittal2007
13 Replies

5. Shell Programming and Scripting

Howto get only filename from find command in Linux?

Hi every body! I would like to get only filename in the result of find command in Linux but I don't know howto. Tks so much for your helps. (5 Replies)
Discussion started by: nguyendu0102
5 Replies

6. Shell Programming and Scripting

how to get only filename in a recursively find command

Hi i would like to ask on how to accomplish the FF: I want to execute a find command recursively and only get the filename something like i want only the last field set if is used ever the fieldvset as an redirection from the output of the find command For example: dir1/dir2/filename1... (2 Replies)
Discussion started by: jao_madn
2 Replies

7. UNIX for Dummies Questions & Answers

How to find function name based on word search

Hi All, I want to find out function name based on word. Here i ll give u one example I have several files based on below format. file will start and ends with same name only EX: file1.txt public function calculate1() { ---- ---- call Global Function1() ---- ---- } END... (9 Replies)
Discussion started by: spc432
9 Replies

8. UNIX for Advanced & Expert Users

Find and store files based on FileName and Modified Time

Hi, I am currently using the following command: files=(ls enuCPU??.????.exp ntuCPU??.????.exp) I need to now change the commmand to store the file names of files that have been modified before datetime equal to say '02/16/2008 20:30:00' What could I use? (2 Replies)
Discussion started by: edisonantus
2 Replies

9. UNIX for Dummies Questions & Answers

Using find command for timestamp based search

Hi, I am writing a script where i need to list all the files that have a scecific timestamp. I get this time stamp from another file. Is it possible to do this with 'find' command? Please let me know your valuable inputs. Thanks Sunny. (1 Reply)
Discussion started by: sunny_03
1 Replies

10. UNIX for Dummies Questions & Answers

find filename based on file content

:confused: There is a flat file on my system which contains email addreses of people in my company. This file is utilized when sending notifications for various things. However nobody knows where this file is located or what it is named. The only thing we know is the email address of a user who... (4 Replies)
Discussion started by: kollerj
4 Replies
Login or Register to Ask a Question