Remove the same files in two folders

有時在整理照片或文件時, 需要比對2個資料匣, 把重覆的檔案拿掉. Dwonload Source Here function usage(){ echo "Find the same file in two folders and remove it." echo "usage : ./comp-rm.sh target-dir source-dir" echo "remove the same files in target-dir." } if [ $# -ne 2 ]; then usage exit 1 fi target_dir=$1 source_dir=$2 f_list1=$(find "$target_dir" -type f) f_list2=$(find "$source_dir" -type f) for i in $f_list1; do echo $f_list2 | grep $(basename $i) >/dev/null && hit_str+=$i";" done if [ -z $hit_str ]; then echo "list is empty.." exit 0 fi export IFS=";" count=0 for hit_file in $hit_str; do echo "$hit_file" let count++ done echo "Do you want to remove these files ($count)?" read -p "Press 'Ctrl+C' stop, 'Enter' key to continue..." for hit_file in $hit_str; do echo "removing... $hit_file" rm -f $hit_file done exit 0

June 19, 2013 · 1 min · oopsmonk

Raspberry Pi Setup

Install Raspbian “wheezy” image Download image from Raspberry Pi offical website Mount HOME to HDD Copy HOME data to disk $ sudo mkdir /media/new_home $ sudo mount /dev/sda1 /media/new_home $ sudo rsync -aXS /home/. /media/new_home/. $ sudo umount /media/new_home fstab #get disk UUID $ sudo blkid /dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="936C-7122" TYPE="vfat" /dev/mmcblk0p2: UUID="c1198422-7a7c-4863-8a8f-45a1db26b4f2" TYPE="ext4" /dev/sda1: UUID="2cd990b5-6c27-4933-95d0-fd00b000fe77" TYPE="ext4" #modify fstab $ echo "UUID=2cd880b5-6c27-4933-95d0-fd00b000fe77 /home ext4 defaults 0 2" | sudo tee --append /etc/fstab #mount HOMW without reboot. $ sudo mount -a Create a sudo user #create user with HOME directory $ sudo useradd -m oopsmonk #add user to sudo group $ sudo adduser oopsmonk sudo #set password $ sudo passwd oopsmonk Install necessary packages $ sudo aptitude full-upgrade -y $ sudo aptitude install tmux vim git python-setuptools -y $ sudo easy_install pip SAMBA server $ sudo aptitude install samba $ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak $ sudo vi /etc/samba/smb.conf enable sucurity user # security = user [rpi] comment = raspberry-pi path = /home/oopsmonk/ browseable = yes writable = yes read only = no #add smaba user and restart samba server $ sudo pdbedit -a -u oopsmonk $ sudo service samba restart Configre default editor $ echo "export EDITOR=vim" >> ~/.bashrc $ echo "export GIT_EDITOR=vim" >> ~/.bashrc $ echo "export TERM=screen-256color" >> ~/.bashrc $ echo "alias tmux='tmux -2'" >> ~/.bashrc $ source ~/.bashrc Boot from USB Disk Use dd or Win32DiskImager dump image to both SD card and USB Disk. ...

June 15, 2013 · 5 min · oopsmonk