Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

ASIC/FPGA Design and Verification Out Source Services

Using find command to recursively compare directory

This page shows a nice way to compare many files. The source and destination have the same directory files.
Running this script will result in a summary of all changes, which can later, if needed, can be used by a graphical program, like gvimdiff, to farher inspect the changes.
The output summary is appended to a file named cmp_diff_log.txt. So you may, in some cases first delete the old report.
PERL script is at :cmp_diff.pl.
A few ways may be used to invoke the script:

find . -name "*.e" | xargs -n1 | xargs -i= perl ~/bin/cmp_diff.pl ../dir_1/ =

All e files created 60 minutes ago.

find . -name "*.e" -mmin -60 | xargs -n1 | xargs -i= perl ~/bin/cmp_diff.pl ../dir_1/ =

To show files, which were modified today, you may chose to:
find . -maxdepth 1 -type f -mtime -1

If you don't need to pipe the output to some other program, than you have also the choice ls command:
ls -al --time-style=+%D | grep `date +%D`

One can create a bash script to do the job for multiple file suffixes. The script will also check, that at least one parameter is enetered for the target directory. If more options are entered the script will override its default suffixes list and use whatever is specified on the command line. In that case bash unset command is used to delete the first argument of the array.

  1. #!/bin/bash
  2. if [ -e "cmp_diff_log.txt" ] ; then
  3.   rm -f cmp_diff_log.txt
  4. fi
  5. array=("$@")
  6. arg=${#array[*]}
  7. if [ "$arg" -eq "0" ] ; then
  8.   echo "no target directory"
  9.   exit
  10. fi
  11. if [ "$arg" -eq "1" ] ; then
  12.   array=(.c .cc .h .hpp .v .vhd .vh .sv .txt .lst .vf .tcl .mk .pl .unx .var)
  13. else
  14.   unset array[0]
  15. fi
  16. for f in "${array[@]}"; do
  17.   echo "working on "$f
  18.   find -L . -name "*$f" -exec perl ~/bin/cmp_diff.pl {} $1 \;
  19. done
  20. find -L . -name "Makefile" -exec perl ~/bin/cmp_diff.pl {} $1 \;

  21. or
    for f in `find . -type f| grep -v "\.[a-zA-Z0-9]"` ;do echo $f; done



The result summary report can be colored by vim, to better see the differences. A syntax for vim coloring is shown below:

syntax match vhd_file /[a-zA-Z0-9_]*\.vhd/
hi vhd_file guibg=lavender guifg=orange

syntax match e_file /[a-zA-Z0-9_]*\.e/
hi e_file guibg=beige guifg=orange

syntax match change /^[<>] *[^ ].*/
hi change guibg=white guifg=orange

syntax match file_name /^FILE/
hi file_name guibg=lavender guifg=orange

To find all files, which were changed today, type:
find ~ -type f -mtime 0

To compress files use find in the following way:
find . -type f | zip back -@
find . -type f | xargs tar -zcf files.tar.gz

Changing permission:
find . ! -perm 775 -exec chmod 775 {} \;
or
find . ! -perm 775 | xargs chmod 775 *

To find all my directories only in the current directory:
find . -type d -maxdepth 1 -user krengelp

To do a combined find and grep command, one can do the following:
for f in `find . -type f`; do grep -l "list.*Check" $f; done
for f in `find . -name "*.e"`; do grep -l "list.*Check" $f; done

find ../../../ -name "*.cfg" -exec grep -l DDR3 {} \;
find ../../../ -name "*.cfg" -exec grep '"DDR3"' {} \;

To find all c++ project files, using find in regular expression mode:

find -regex ".*\.\(c\|h\|hpp\|cc\|cpp\)"
find -regex ".*[ch][cph]*"
  ...


Also available on this project:


Home

Download Area

Specman: how code style affects performance








Search This Site


Feedback This Site




new pages on this site