gc

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, January 8, 2013

Find and delete duplicate files from nautilus


( warning: backup the directory and files first, cause Im not responsible for any use of this script and losing data )
 
command from application that I use:
- fdupes
- notify-send
- zenity

operating system: Ubuntu linux 10.04

1. create /tmp/fD.sh file and add :
#!/bin/bash -x

OUTFILE=/tmp/fdups.out
LOGFILE=/tmp/fdups.log
DUPDIR=/tmp

function ntfy {
    `which notify-send` "fdups" "$MSG" --icon=dialog-information --expire-time=7000
}
function emsg {
    echo "$MSG"
    echo "    [i] $MSG" >> $LOGFILE;
}

[ ! -f $LOGFILE ] && touch $LOGFILE
echo "====================" >> $LOGFILE
echo `date` >> $LOGFILE
echo "cmd: $0 $*" >> $LOGFILE
echo "====================" >> $LOGFILE
echo . >> $LOGFILE

case "$1" in
            fdel)
                [ ! "$2" ] && { echo "use: $0 fdel <directory> "; exit; }
                DUPS=`$0 $2 | grep "Count of Duplicates" | cut -d":" -f2 | sort`;
                cat $OUTFILE;
                [ $DUPS -eq 0 ] && { MSG="no duplicate found in $2, exiting ..."; emsg; ntfy; exit; } || { MSG="total: $DUPS files found"; emsg; ntfy; }
                gedit $OUTFILE <&- 1>/dev/null 2>&1 &
                zenity --text "Delete $DUPS (leave 1 only for each) duplicate file in $2 (see output file in gedit editor)" --title "fdupes" --question;
                [ $? -eq 0 ] && { fdupes -rdN $2 >> $LOGFILE; } || { emsg; exit; }
            ;;
            fdelgui)
                [ ! "$2" ] && { echo "use: $0 fdel <directory> "; exit; }
                DUPS=`$0 gui $2 | grep "Count of Duplicates" | cut -d":" -f2 | sort`;
                DUPS=`cat ./DUPS`
                rm ./DUPS -fr;
                [ $DUPS -eq 0 ] && { MSG="no duplicate found in $2, exiting ..."; emsg; ntfy; exit; } || { MSG="total: $DUPS files found"; emsg; ntfy; }
                gedit $OUTFILE <&- 1>/dev/null 2>&1 &
                zenity --text "Delete $DUPS (leave 1 only for each) duplicate file in $2 (see output file in gedit editor)" --title "fdupes" --question;
                [ $? -eq 0 ] && { fdupes -rdN $2 >> $LOGFILE; } || { emsg; exit; }

            ;;
            gui)
                if [ "$1" ]; then
                (
                    echo "10" ; sleep 1
                    echo "# begin searching of duplicate file";
                    dupdir=$2
                    startdt=`date +%s`
                    echo "20" ;
                    echo "# running fdupes"; sleep 1
                    fdupes --recurse ${dupdir} > $OUTFILE
                    echo "70" ;
                    enddt=`date +%s`
                    ((diff_sec=enddt-startdt))
                    runtime=(`echo - | awk '{printf "  %d:%d:%d","'"$diff_sec"'"/(60*60),"'"$diff_sec"'"%(60*60)/60,"'"$diff_sec"'"%60}'`)
                    echo "# runtime: $enddt : $runtime"; sleep 1
                    echo "80" ; sleep 1
    echo "Total Runtime: ${runtime}"
                    grep ${dupdir} $OUTFILE | wc -l > ./DUPS
                    cntOfDupes=`cat ./DUPS`
                    ((cntOfFD=`find ${dupdir} | wc -l`-1))   #subtract 1 as this counts the current dir
                    echo "# Count of Duplicates: ${cntOfDupes}"; sleep 1
                    echo "# Count of Files/Directories: ${cntOfFD}"; sleep 1
                    echo "99" ;
                    echo "# finish"; sleep 1
                    echo "100";
                    ) |
                    zenity --auto-close --progress \
                    --title="$0 $* ..." \
                    --text="Memulai...                                                          *" \
                    --percentage=0

                    if [ "$?" = -1 ] ; then
                        zenity --error --text="Process canceled."
                    fi
                else
                    exit;
                fi
            ;;
            *)
                dupdir=$1
                du -hs ${dupdir} 2>/dev/null
                startdt=`date +%s`
                fdupes --recurse ${dupdir} > $OUTFILE
                enddt=`date +%s`
                ((diff_sec=enddt-startdt))
                runtime=(`echo - | awk '{printf "  %d:%d:%d","'"$diff_sec"'"/(60*60),"'"$diff_sec"'"%(60*60)/60,"'"$diff_sec"'"%60}'`)
                echo "Total Runtime: ${runtime}"
                cntOfDupes=`grep ${dupdir} $OUTFILE | wc -l`
                ((cntOfFD=`find ${dupdir} | wc -l`-1))   #subtract 1 as this counts the current dir
                echo "Count of Duplicates: ${cntOfDupes}"
                echo "Count of Files/Directories: ${cntOfFD}"
                cat $OUTFILE
                ;;
esac
2. go to $HOME/.gnome2/nautilus-scripts and create file, example: "find_duplicate_file" ,and add this :
#!/bin/sh
`which notify-send` "Search for duplicate files" "$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS" --icon=dialog-information --expire-time=5000
exec /tmp/fD fdelgui '$NAUTILUS_SCRIPT_SELECTED_FILE_PATHS'

open nautilus, left click -> Scripts -> find_duplicate_file

don't forget to make this 2 file executable :
$ chmod u+x /tmp/fD.sh && chmod u+x $HOME/.gnome2/nautilus-scripts/find_duplicate_file

fin





Thursday, December 13, 2012

Copy an existing vbox file

To copy an existing vbox file (example name for existing file here, is example_file.vbox) to virtual box,

create new linux os "example_file.vbox" in virtual box,

then goto ~/.Virtualbox/example_file.vbox and copy or extract file to this directory

change UUID machine of the file with UUID from example_file.vbox.xml

remove example_file.vbox.xml and example_file.vbox.xml.prop
change the name of the file to example_file.vbox.xml and example_file.vbox.xml.prop

Gammu Using Huawei Modem


required usb modeswitch.
get and install it, then
~$ usb_modeswitch -c e173
and
~$ ls /dev/ttyU*
showing 3 ttyUSB (ttyUSB0 .. ttyUSB2)

now check module and gammu,
~$ lsmod | grep usbserial
~$ gammu --identify
send test message:
~$ echo "test" | gammu --sendsms TEXT <phone.number>
or, send message with:
~$ gammu-smsd-inject TEXT <phone_number> -text "your message"

Alternatively by using kalkun :
- get kalkun and install
- Activate kalkun
- goto http://<your kalkun installation path>/kalkun , and check the connection on the top left of the web page
- If the connection status is connected (green color), its ok to send messages, etc.



If usb port isn't detected, try
~$ umount /dev/sr1
unplug the phone / modem and plug it back,
reconnect.

sources and download:
wammu/gammu download page
gammu wiki

Not Realy Free Premium Domain