cksum – compare for multiple files.

If you have to compare cksum for couple of files, the you know how cumbersome it is. So, I wrote a simple script, wherein you can create a file called cksums in the current directory and copy paste the result of  “cksums *”  into this file, and then run this script. Cool 🙂

#!/bin/bash -
#===============================================================================
#
#          FILE: checkcksums.sh
#
#         USAGE: ./checkcksums.sh
#
#   DESCRIPTION: Compare cksums of multiple files.
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (),
#  ORGANIZATION:
#       CREATED: 02/22/2013 09:12:17 PM IST
#      REVISION:  ---
#===============================================================================

file=cksums
while read line
do
    a=( $(echo $line) )
    if [[ -f ${a[2]} ]]
    then
        b=( $(cksum ${a[2]}) )
        if [[ $a == $b ]]
        then
            echo "Cksum for ${a[2]} = ${a[0]} matches"
        else
            echo "Failed ::Cksum for ${a[2]} = ${a[0]} matches"
        fi
    else
        echo "Failed :: file ${a[2]} does not exist"
    fi
done < $file
Enhanced by Zemanta

Using file partially for filenames

There are some commands that take file name and there are some case where you need to give file name. But there are some cases where you want to modify the file before passing it to the command. What do you do in these case’s?

I had a file containing huge amount of data and for some testing I wanted to pass only the first few lines of the file and not the complete file.  And since the file only accepted filename and would not take any input from the STDIN so only option was to create a file with the required data in a temporary file. So, I sat back to figure out some way to do it and finally found I can use this:

testcommand -f<(head -1 )

The “testcommand” parameter “-f” requires a filename. And here we are passing the file to the command after filtering it with head command. You can use any bash command inside the <() combination.

Enhanced by Zemanta

function for copy files with progress bar (using pv – pipe viewer)

function for copy files with progress bar (using pv – pipe viewer)

1
 cp_p() { if [ `echo "$2" | grep ".*/$"` ]; then pv "$1" &gt; "$2""$1"; else pv "$1" &gt; "$2"/"$1"; fi; }

dont have to type new file name (it copy file under same name) and dont have to use ‘/’ in the end of destination folder (but you can if u want, its idiot proof)

* View this command to comment, vote or add to favourites * View all commands by chmurli

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/f3Uy8ZDqE8Q/function-for-copy-files-with-progress-bar-using-pv-pipe-viewer

Enhanced by Zemanta