Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, November 22, 2011

Find all Hard Links to a File

While writing a wrapper to submit files for batch processing I found a need to find all the hard links to a file. Like so many things in Linux, the solution turns out to be simple -- once I found it.

Use the find command

$ find <dir to start search in> -xdev -samefile <path to file>

For example, to find all the hard link to the file /home/buser/chosen.one.txt on the home partition, use:

$ find /home -xdev -samefile /home/buser/chosen.one.txt

The switch -xdev means to only search on the original volume. It can be omitted but, because a hard link cannot cross volume boundaries, the switch will save time by not searching where a linked file cannot be anyways.

Monday, May 17, 2010

Not Just Another RKBA Blog

This blog was not intended to be RKBA all the time even though, lately, it seems that way. In that spirit here are a some simple bash scripts for email administrators who need to check mail the queue

See summaries for all mail for today
DATE=$(date|awk '{printf"%s %s\n",$2,$3}')
mailq|grep -A 2 "$DATE"

See subject lines for today's mail (root requried)
DATE=$(date|awk '{printf"%s %s\n",$2,$3}')
LIST=$(mailq|grep "$DATE"|sed -s 's/\([0-9A-F]*\).*/\1/')
for QUID in $LIST; do
  echo -n "$QUID: "
  postcat -q $QUID|grep -m 1 'Subject:'
done

View subject line in MAILER-DAEMON messages (root required)
LIST=$(mailq|grep MAILER|sed -e 's/^\([0-9A-F]*\) .*/\1/')
for QUID in $LIST; do
  echo -n "$QUID: "
  postcat -q $QUID|grep -m 1 "Subject:"
done

On my outgong gateway, almost everything in the queue from MAILER-DAEMON is a "Out of Office" notification not going back to a spammer. To delete these (root required and be careful with this one
mailq| grep MAILER|sed -e "s/^\([0-9A-F]*\) .*/\1/"|postsuper -d -