Count number of lines in a file

find . -type f -exec cat {} ; | wc -l

and if you don’t want repeats

find . -type f -exec cat {} ; | egrep \S | wc -l

I even thought about cat, but I ended up doing something like:

total=0
for i in $( find -H . -type f ); do
  temp=$( wc -l "$i" | cut -f 1 -d  )
  if [ $temp > 0 ]; then
    total=$(($total+$temp))
  fi
  echo $total
done
echo $total

mounting partitions from a disk image

My laptop drive recently died on me. Of course, this is the one machine that I don’t have good backups on. After various passes of dd_rescue (forward and backward) I had a pretty good disk image. Now I wanted to mount a partition. Problem is, I had an image.

The first step is to identify where the partitions are.

# fdisk -l /mnt/backup/brian/brian.iso 

Disk /mnt/backup/brian/brian.iso: 250 GB, 250056737280 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

                      Device Boot      Start         End      Blocks   Id  System 
/mnt/backup/brian/brian.iso1               1           6       48163   de  Dell Utility
/mnt/backup/brian/brian.iso2   *           7       30009   240991065    7  HPFS/NTFS
/mnt/backup/brian/brian.iso3           30010       30401     3140707    f  Extended LBA

Notice the cylinder size (512) and where the partitions are.

TODO: fix this. The -u option should be used so fdisk specifies cylinders. then it can be mounted with loop and offset.

Follow

Get every new post delivered to your Inbox.