|
scripts
One-sentence summary of this page.
Various scriptsThis page contains scripts or settings wich are useful to me(may be useful to you too). 1) Mirroring two subversion repositories located on different serverscd ~/perlhobby ;svn update; cd ~/firepower_repo/google_code_repo;svn update; rsync -avr --exclude .svn --delete ~/perlhobby/ ~/firepower_repo/google_code_repo/ svn add * cd ~/firepower_repo/google_code_repo; svn commit -m ""; 2) Bash Function to get your ip from console and put it in your clipboardmyip () {
sudo ifconfig | perl -ple 'print $_ if /inet addr/ and $_ =~ s/.*inet addr:((?:\d+\.){3}\d+).*/$1/g ;$_=""' | grep -v ^\s*$ | head -1 | xsel -i
}3) Move all files containing a certain word to a directory created with the name of that wordselect_and_move () {
perl -e 'my $a= shift @ARGV; @stuff = `find | grep -i $a | cut -b3-`;$stuff[$_]=~s/^(.*)\n$/\"$1\"/g for 0..@stuff-1;`mkdir $a`;`mv $_ $a` for @stuff;' $1
}
Application : Classifying very fast large ammounts of unstructured/unsorted files which are sitting in one place. 4) Searching recursively in a directory for a file that contains a patterngrep -r pattern * Variation (Only see the files in which at least one match occurs) : grep -lir pattern * 5) Zipping the current directory and sending it to the desktop of some computer#just zips the whole project , transfers it to the laptop #for easy reach rm project.zip cd .. svn export duplicate_file_eraser /tmp/duplicate_file_eraser cd duplicate_file_eraser/ zip -r project.zip /tmp/duplicate_file_eraser/ rm -rf /tmp/duplicate_file_eraser scp project.zip stef@laptop:~/Desktop/ rm project.zip 6) Unpacking the contents of a tar directly from a computer to the otherDescription of the problem:You have two machines. On one of them(A) you have a big archive. On the other(B) you have enough space to store the unpacked contents of the archive. We consider for the purpose of the example the biggest file in archive located on A. Solution:on B do: sudo nc -l -p 100 > biggest_file_in_archive on A do: tar Oxvf bigarchive.tar biggest_file_in_archive | nc Ip_of_B 100 This will pipe(redirect) all STDOUT from tar output to the nc which will send them to B,on B we have a server opened that writes everything to disk in a file called biggest_file_in_archive References http://drkmario.blogspot.com/2007/02/using-netcat.html 7) Sending as attachment to separate emails the files in a directoryls | perl -ne '$a=$_;chomp $a;$b="mutt -s \"poza $a\" -a $a <email> < message.txt\n";print $b;`$b`' 8) A totally fast ,lame and unsecure way to quickly ssh when ssh keys are not working(for whatever reasons)echo "use the clipboard" echo "<password>" | xsel -i ssh -X -p 22 root@<IP_OF_MACHINE_TO_CONNECT> 9) using rsync over a custom portrsync -av --progress --inplace --rsh='ssh -p<port>' user@host:<remote_path> <local_path> other thingsfor finding the length of a file without downloading itcurl -I <url to file> all cpan mirrors and how to modify the currently set mirrorallot of mirrors can be found here get in /etc/perl/CPAN/Config.pm and see under urllist 10) Using screen with horizonta/vertical splitsInstructions on how to get and install screen with vertical split http://scie.nti.st/2008/8/22/gnu-screen-with-vertical-split-support Or you can just get the binary here (and hopefully it'll work) Advantage: allows to see the output of many console applications at the same timeDrawback : the layout of the vertical/horizontal splits is not preserved throughout sessionsScreen detach/attaches screen -x
At reference 3) there is a non-working way for preserving layout of a screen. References
11) Converting djvu->pdf and splitting pdfsconverting djvu->pdf: aptitude install djvulibre-bin libtiff-tools libtiff-dev ddjvu -format=tiff file.djvu file.tiff tiff2pdf -o file.pdf file.tiff splitting pdfs pdftk file.pdf cat begin_page-end_page output output_file.pdf (you can also use "end" instead of end_page) converting pdf -> jpg convert -resize 1600x1200 -density 500 file.pdf file.jpg 12) Have bash tell you how much emails you received exactly after you log onprint_email_count_in_folder() {
echo -e "\E[35m { "`find ~/mail/ | grep new | grep $1 | perl -ne '$a = $_;chomp $a; print $_ unless -d $a' | wc -l`" new emails in folder [$1] }"
tput sgr0
}
check_emails() {
print_email_count_in_folder "directory_name1"
print_email_count_in_folder "director_name2"
}13) Replace occurences of strings in multiple filesperl -pi -e 's/searched_string/replacement_string/' *.ext Note: recursive search&replace find * | xargs perl -p -i -e s/OldText/NewText/g or perl -p -i -e 's/search_string/replace_string/g' `grep -ril search_string *` recursive search&replace of filenames find ./ -exec rename 's/pattern/replacement/' * "{}" \;14) Some vim tips1 chaning from string1 -> string2 and string2 -> string1s/string1\|string2/\=submatch(0) == "string1" ? "string2" : "string1"/g shortcuts
ctagsrequirements:
15) Converting chm to pdfinstructions on how to install chm2pdf 16) Some settings from Debian
17) Tightvnc settingsYou need two packages tightvncserver,vnc4server and vncconfig iconic=true nowin=true -display localhost:<display_number> This setting is for making the clipboard guest-host OS transfer work. You can find the display number with ps xau | grep `whoami` | grep Xtightvnc You can start the vnc server with vncserver -compatiblekbd and it will tell you what display number it has associated (the switch is for alt-key problems) and then connect to it with vncviewer by writing vncviewer < ip_address > : < display_number> Note: if you have scroll lock pressed your alt key may not work 18) Mirroring websitesMirror starting from a location and not going more than 3 links deep,disabling the possibility to go on different sites/domains/tld httrack --depth=3 --ext-depth=0 --stay-on-same-dir --stay-on-same-tld --stay-on-same-domain <link> 19) Finding out what application binds a specific portAs root run netstat -plant | grep ':<port_number>' 20) Renaming a group of filesfind . -exec mv {} {}.<new_extension> \;21) Getting peak-hours for irssi logscat \#perl.log | perl -ne '/^(\d{2}):/; $hour[$1]++; END{ print "$_: $hour[$_]\n" for sort {$hour[$a] <=> $hour[$b]} 0..23; }'
|
Sign in to add a comment