Showing posts with label mac osx. Show all posts
Showing posts with label mac osx. Show all posts

md5 checksum for multiple files

create the checksum and verify them.
Example: file1.txt file2.txt file3.txt

# Linux
anthony.chin@jump.noc:~$ touch file{1,2,3}.txt
anthony.chin@jump.noc:~$ ll
total 129532
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file1.txt
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file2.txt
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file3.txt
anthony.chin@jump.noc:~$ for i in `ls file?.txt`; do md5sum $i > $i.md5; done
anthony.chin@jump.noc:~$ ll
total 129544
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file1.txt
-rw-r--r-- 1 anthony.chin anthony.chin        44 Feb 10 07:07 file1.txt.md5
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file2.txt
-rw-r--r-- 1 anthony.chin anthony.chin        44 Feb 10 07:07 file2.txt.md5
-rw-r--r-- 1 anthony.chin anthony.chin         0 Feb 10 07:06 file3.txt
-rw-r--r-- 1 anthony.chin anthony.chin        44 Feb 10 07:07 file3.txt.md5
anthony.chin@jump.noc:~$ md5sum -c *.md5
file1.txt: OK
file2.txt: OK
file3.txt: OK

# OSX
$ brew install cfv

$ touch file{1,2,3}.txt
$ ll
total 0
-rw-r--r--  1 anthony.chin  admin  0 Feb 10 15:12 file1.txt
-rw-r--r--  1 anthony.chin  admin  0 Feb 10 15:12 file2.txt
-rw-r--r--  1 anthony.chin  admin  0 Feb 10 15:12 file3.txt

$ for i in `ls file?.txt`; do md5 $i > $i.md5; done
$ ll
total 24
-rw-r--r--  1 anthony.chin  admin   0 Feb 10 15:12 file1.txt
-rw-r--r--  1 anthony.chin  admin  51 Feb 10 15:13 file1.txt.md5
-rw-r--r--  1 anthony.chin  admin   0 Feb 10 15:12 file2.txt
-rw-r--r--  1 anthony.chin  admin  51 Feb 10 15:13 file2.txt.md5
-rw-r--r--  1 anthony.chin  admin   0 Feb 10 15:12 file3.txt
-rw-r--r--  1 anthony.chin  admin  51 Feb 10 15:13 file3.txt.md5$ cfv *.txt
file1.txt.md5: 1 files, 1 OK.  0.000 seconds, 11.1K/s
file2.txt.md5: 1 files, 1 OK.  0.000 seconds, 18.8K/s
file3.txt.md5: 1 files, 1 OK.  0.000 seconds, 14.4K/s
3 files, 3 OK.  0.001 seconds, 7.6K/s

# if the md5 was incorrect:
$ vi file3.txt.md5
$ cfv *.txt
file1.txt.md5: 1 files, 1 OK.  0.000 seconds, 11.3K/s
file2.txt.md5: 1 files, 1 OK.  0.000 seconds, 17.6K/s
file3.txt : crc does not match (b026324c6904b2a9cb4b88d6d61c81d2!=b026324c6904b2a9cb4b88d6d61c81d1)
file3.txt.md5: 1 files, 0 OK, 1 badcrc.  0.000 seconds, 19.4K/s
3 files, 2 OK, 1 badcrc.  0.001 seconds, 7.8K/s


MAC OSX Terminal hostname auto-complete

The following script uses a function call to autocomplete hostnames dynamically, and fetches hostnames from the ~/.ssh/known_hosts, ~/.ssh/config and system-wide /etc/hosts file.
In MAC OSX, append below into your user's ~/.bash_profile, save and use new login session to take effect
_complete_hosts () {
     COMPREPLY=()
     cur="${COMP_WORDS[COMP_CWORD]}"
     host_list=`{ 
         for c in /etc/ssh_config /etc/ssh/ssh_config ~/.ssh/config
         do [ -r $c ] && sed -n -e 's/^Host[[:space:]]//p' -e 's/^[[:space:]]*HostName[[:space:]]//p' $c
         done
         for k in /etc/ssh_known_hosts /etc/ssh/ssh_known_hosts ~/.ssh/known_hosts
         do [ -r $k ] && egrep -v '^[#\[]' $k|cut -f 1 -d ' '|sed -e 's/[,:].*//g'
         done
         sed -n -e 's/^[0-9][0-9\.]*//p' /etc/hosts; }|tr ' ' '\n'|grep -v '*'`
     COMPREPLY=( $(compgen -W "${host_list}" -- $cur))
     return 0
 }
 complete -F _complete_hosts ssh
 complete -F _complete_hosts host

Mac OSX cmd auto tab completion

create or edit the ~/.inputrc

set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete

 open a new terminal session, and use tab to try the auto-completion