shellsnippets
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
shellsnippets [2008/06/11 10:22] – 78.161.77.23 | shellsnippets [2012/12/16 11:28] (current) – [Set system date by time from webserver] 2001:6f8:1c1a:0:922b:34ff:fe18:7138 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | < | + | ====== |
- | < | + | |
- | <SCRIPT language=JavaScript> | + | |
- | <!-- Begin | + | |
- | if (document.all) { | + | |
- | //Things you can alter | + | |
- | yourLogo | + | |
- | logoFont | + | |
- | logoColor | + | |
- | //Nothing needs altering below! | + | |
- | yourLogo | + | |
- | L = yourLogo.length; | + | |
- | TrigSplit | + | |
- | Sz = new Array() | + | |
- | logoWidth | + | |
- | logoHeight | + | |
- | ypos = 0; | + | |
- | xpos = 0; | + | |
- | step = 0.03; | + | |
- | currStep = 0; | + | |
- | document.write('< | + | |
- | for (i = 0; i < L; i++) { | + | |
- | document.write('< | + | |
- | +' | + | |
- | +' | + | |
- | } | + | |
- | document.write('</ | + | |
- | function Mouse() { | + | |
- | ypos = event.y; | + | |
- | xpos = event.x - 5; | + | |
- | } | + | |
- | document.onmousemove=Mouse; | + | |
- | function animateLogo() { | + | |
- | outer.style.pixelTop = document.body.scrollTop; | + | |
- | for (i = 0; i < L; i++) { | + | |
- | ie[i].style.top = ypos + logoHeight * Math.sin(currStep + i * TrigSplit * Math.PI / 180); | + | |
- | ie[i].style.left = xpos + logoWidth * Math.cos(currStep + i * TrigSplit * Math.PI / 180); | + | |
- | Sz[i] = ie[i].style.pixelTop - ypos; | + | |
- | if (Sz[i] < 5) Sz[i] = 5; | + | |
- | ie[i].style.fontSize = Sz[i] / 1.7; | + | |
- | } | + | |
- | currStep -= step; | + | |
- | setTimeout(' | + | |
- | } | + | |
- | window.onload = animateLogo; | + | |
- | } | + | |
- | // End --> | + | |
- | </ | + | ===== Useful standard utilities ===== |
- | <STYLE type=text/ | + | |
- | <body oncontextmenu=" | + | |
- | <p align=" | + | * [[man>sed]] -- regular expression replacing |
- | <meta http-equiv=" | + | * [[man>awk]] -- tokenizing strings |
- | <meta http-equiv=" | + | * [[man>seq]] -- returns a list of integers |
- | <script language=" | + | * [[man>cat]] -- read a file |
- | <!-- | + | * [[man> |
- | var left=">"; | + | |
- | var right="<"; | + | |
- | var msg="--- İnFerNo ---"; | + | |
- | var speed=200; | + | |
- | function scroll_title() { | + | |
- | document.title=left+msg+right; | + | |
- | msg=msg.substring(1, | + | |
- | setTimeout(" | + | |
- | } | + | |
- | scroll_title(); | + | |
- | // End --> | + | |
- | </ | + | |
- | <body text="# | + | |
- | <div align=" | + | |
+ | ===== Find space wasters ===== | ||
+ | This gives you a quick overview where the largest directories are | ||
+ | $> du --max-depth=3 -x / |sort -n | ||
+ | ===== Delete empty directories ===== | ||
+ | $> find . -type d -empty -delete | ||
+ | ===== Execute a local shellscript on a remote host ===== | ||
- | < | + | |
- | "http://www.w3.org/TR/html4/loose.dtd"> | + | $> cat script.sh |ssh user@host |
- | <html> | + | |
- | <head> | + | |
- | <meta http-equiv="Content-Type" | + | ===== Looping over lines with spaces ===== |
- | < | + | |
- | <style type="text/css"> | + | To read filenames from a file and do something (eg. echo them) you might wanna do this: |
- | <!-- | + | |
- | body { | + | <code bash> |
- | background-color: | + | #!/bin/bash |
- | color: | + | |
- | font-size: ; | + | for x in `cat files.txt` |
- | margin: 0; | + | do |
- | font-family: | + | echo " |
+ | done | ||
+ | </code> | ||
+ | |||
+ | Unfortunately this breaks when some of these filenames contain spaces. [[man> | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | cat files.txt |while read x | ||
+ | do | ||
+ | echo "$x" | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | If you need to [[man> | ||
+ | |||
+ | <code bash> | ||
+ | # | ||
+ | |||
+ | cat files.txt |while read x | ||
+ | do | ||
+ | scp user@remote: | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Replace by regular expression in multiple files ===== | ||
+ | |||
+ | You can use Perl to replace a certain string with another in multiple files. But first you should make sure your regexp matches the right thing. The following is looking for a path in quotes starting with the dir '' | ||
+ | |||
+ | $> find -name ' | ||
+ | |||
+ | If you're happy use the following to do the replacement. Here we surround the string with the PHP function PI: | ||
+ | |||
+ | $> find -name ' | ||
+ | |||
+ | ===== Return absolute filename ===== | ||
+ | |||
+ | This handy function returns the absolute filename of a given file. Example: | ||
+ | |||
+ | $> absname ~/.bashrc | ||
+ | / | ||
+ | |||
+ | <code bash> | ||
+ | function absname { | ||
+ | if [ -d " | ||
+ | dir="$1" | ||
+ | unset file | ||
+ | elif [ -f "$1" | ||
+ | dir=$(dirname | ||
+ | file="/" | ||
+ | else | ||
+ | # The file did not exist. | ||
+ | # Return null string as error. | ||
+ | echo | ||
+ | | ||
+ | | ||
+ | |||
+ | # Change to the directory and display the absolute pathname. | ||
+ | cd " | ||
+ | echo ${PWD}${file} | ||
} | } | ||
- | //--> | + | </code> |
- | </style> | + | |
- | </ | + | Here is a simpler one which doesn' |
- | < | + | |
- | <CENTER> | + | <code bash> |
- | <TABLE height="400"><TR><TD> | + | # |
- | <CENTER> | + | |
- | <!-- | + | p=`echo "$0" |
- | body { | + | echo "The scripts absolute path is $p" |
- | background-color: | + | </code> |
- | color: | + | |
- | font-size: 29; | + | Or you could just use readlink, which also resolves symlinks: |
- | margin: 0; | + | |
- | font-family: | + | $> readlink -f ~/.bashrc |
- | } | + | / |
- | //--><center> | + | |
- | <table height=" | + | ===== Print ANSI colors ===== |
- | < | + | |
+ | This small script prints all available ANSI-colors on the terminal. | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | for i in 30 31 32 33 34 35 36 37 39 | ||
+ | do | ||
+ | for j in 40 41 42 43 44 45 46 47 49 | ||
+ | do | ||
+ | # skip if same fore- and backgroundcolor | ||
+ | if [ $j -eq $[ i + 10 ] ]; then | ||
+ | continue | ||
+ | fi | ||
+ | | ||
+ | | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | ===== Copy remote directories ===== | ||
+ | |||
+ | This is a short snippet to copy whole directory trees with all permissions, symlinks and special files (devices,fifos...). | ||
+ | |||
+ | $> cd /home/user | ||
+ | $> ssh user@remote.host.com "cd /home/user && find . \ | ||
+ | | ||
+ | |||
+ | The above statement will copy everything but // | ||
+ | |||
+ | ===== 30 days backup ===== | ||
+ | |||
+ | Just found at http:// | ||
+ | |||
+ | $> tar czf / | ||
+ | $> find /backupdir -name \*.tar.gz -mtime +30 -print0 | xargs -0r rm -f | ||
+ | |||
+ | ===== TAR all directories and delete them afterwards ===== | ||
+ | |||
+ | $> for x in `find -type d -maxdepth 1|grep -v ' | ||
+ | |||
+ | ===== Set system date by time from webserver ===== | ||
+ | |||
+ | Sometimes you want to set the system date of Unix system to some sane value. You could do it manually or use some NTP client. The first idea is too much work ;-) and for the second one you need a time server and some client installed. But why not use the HTTP Response Header '' | ||
+ | |||
+ | #> date -s "`curl -I http:// | ||
- | < | + | ===== Backups with afio ===== |
- | < | + | |
- | <param name=" | + | |
- | <param name=" | + | |
- | <param name=" | + | |
- | <param name=" | + | |
- | <embed src=" | + | |
- | </ | + | |
- | <br /> | + | |
- | <form action="" | + | |
- | <input type=" | + | The following command uses [[man>afio]] to create a gzipped backup stored on a remote machine (using [[man>ssh]]). |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
- | </ | + | |
+ | #> find / -path '/ | ||
+ | Creating multiple maximum 1GB sized chunks: | ||
+ | #> find / -path '/ | ||
+ | afio -o -v -M 100m -Z -0 -s 1000m \ | ||
+ | -H 'bash -c "mv \$2 \$2.\$1" | ||
+ | This is to prefer over other solutions using [[man> | ||
+ | Unfortunately this does not work with the '' | ||
+ | ===== Show specified lines from a file ===== | ||
+ | This shows lines 713-720 from '' | ||
+ | $> sed -n ' | ||
- | BODY { | + | ===== dos2unix unix2dos ===== |
- | BORDER-RIGHT: | + | |
- | }</ | + | |
+ | These are handy in the .bashrc | ||
+ | <code bash> | ||
+ | alias dos2unix=" | ||
+ | alias unix2dos=" | ||
+ | </ | ||
- | BODY { | + | I've got trouble with unix2dos while calling it on DOS files. So I replaced it with a new version. I'm not very familar with "regular expressions", so maybe there is a shorter way to find LF without a leading CR. But it works fine for me. |
- | SCROLLBAR-FACE-COLOR: | + | |
- | }</ | + | |
- | <meta content="text/ | + | |
- | <meta content=" | + | |
- | <meta content=" | + | |
- | <meta content=" | + | <code bash> |
- | <meta content=" | + | alias unix2dos="perl -pi -e 's/([^\r])\n/$1\r\n/;'" |
- | <meta content="" | + | </code> |
- | <meta content=" | + | |
- | <base target=" | + | |
- | <!-- | + | |
- | </ | + | |
- | <br> | + | |
- | <div style=" | + | Command Line (Windows to Unix): |
- | <span title=" | + | col -bx < win_file.txt > unix_file.txt |
- | <span style=" | + | |
- | İnFerNo | + | |
- | </ | + | ===== Strip UTF-8 Byte Order Mark (BOM) ===== |
- | <table width=" | + | |
- | < | + | |
- | <td align=" | + | |
- | </ | + | |
- | </ | + | |
- | < | + | |
- | <table width=" | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td height=" | + | |
- | <p class=" | + | |
- | Biz gecmiste oldugu gibi yeniden dünyaya Adalet getirmeye geldik! | + | |
- | Osmanliyi unutunuz meydani bos bulup dünyayi sömürmeye basladiniz! | + | |
- | Bizi unutmak istenizde artik herzaman rüyalarinizda yasayacagiz. | + | |
- | OSMANLI hala yasiyor, Geçmiste onlar sizleri nasil alt ettiyse, bu sefer de bizler onlarin torunlari olarak sizleri alt etmeye geldik. Osmanli' | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td height=" | + | |
- | <p class=" | + | |
- | be feared... Because we have come back to frighten you again. | + | |
- | We are here to tell that "we were here yesterday, are still here today and we will be here tomorrow" | + | |
- | Don't ever get this out of your mind and feel it deeply inside you each time. | + | |
- | Ottoman Empire is still living. Our ancestors have conquered you in the past and we are doing the same thing as their sons...! | + | |
- | Ottoman Empire isn't forgotten and it will never be..!. | + | |
- | See you next time..</ | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | </ | + | |
- | < | + | |
- | <td colspan=" | + | |
- | <p class=" | + | |
- | Wir sind die Enkel des osmanischen Reiches mit seiner ganzen kulturellen Vielfalt! | + | |
- | Wer denk wir sind vergangenheit hat sich hier mit geirrt! | + | |
- | Wir lassen uns von keinem was sagen und sind gekommen um Gerechtigkeit zu bringen wo von ihr nichts versteht. | + | |
- | Es lebe das Groß Osmanische Reich! | + | |
- | Auch wenn ihr uns vergessen wollt wir werden in euren Träumen weiter leben. | + | |
- | Ottoman-Empire Power of the Cyberworld</ | + | The following command removes the UTF-8 Byte Order Mark from given file(s). See [[http://www.xs4all.nl/~mechiel/projects/bomstrip/|bomstrip]] for solutions in other languages. |
- | </ | + | |
- | < | + | |
- | <td width=" | + | |
- | <td width=" | + | |
- | <td width=" | + | |
- | <td width=" | + | |
- | <td width=" | + | |
- | </tr> | + | |
- | </table> | + | |
- | <p class=" | + | |
- | </body> | + | |
- | </html> | + | |
+ | $> sed -i -s -e ' | ||
+ | ===== Print formatted man pages ===== | ||
- | </ | + | You can print out man pages -- in this case, 2 man pages on one paper sheet: |
- | <p align=" | + | |
- | <param value=" | + | |
- | <param value=" | + | |
- | <meta content=" | + | |
+ | $> function lprman () { man -t $1 $2 | psnup -2 | lpr -P $3 } | ||
- | </ | + | Parameter 1: man page category \\ Parameter 2: man page name \\ Parameter 3: name of the queue to print with |
- | </ | + | |
- | </ | + | |
- | </ | + | Sample call: |
- | </html> | + | $> lprman 5 fstab mylaser |
+ | Notes: | ||
+ | * you need psutils to have that working -- psnup belongs into this package | ||
+ | * you can put this function in a file that is sourced when you log in, for example / | ||
+ | * of course you can omit '' | ||
+ | * on my machines, the duplex setting is ignored, it's always printing on one side of the paper |
shellsnippets.1213179742.txt.gz · Last modified: 2008/07/15 22:30 (external edit)