# A little quick [debian] lookup, ``handy to grep in'' file # http://www.rdrs.net/document/ # last update, Sun Sep 11, 2005 # # # kernel cd src/kernel.???/ make (x|menu)config make dep make clean make bzImage make modules make modules_install mv arch/i386/boot/bzImage /boot/vmlinuz-kernel??? # adapt /etc/lilo.conf & run lilo # note: lilo; ctrl-esc # : make mrproper = default kernel-config restore # # strace strace -p `pidof APAtCHy[sErver]` # attach to a running process strace -c myprogram # report summary # # Promise ULTRA ATA/133 controller and linux kernel... # For 2.4 kernels Either download the [closed source] patch from the # vendor's website or enable the; # 'PROMISE PDC202{46/62/65/67/68}' # option in you kernel configuration under ATA/IDE/MF/RLL support.. # # Create a chroot [on debian] mkdir /tmp/virtual cd /tmp/virtual/ tar zxvf /debian/dists/unstable/main/disks-i386/current/base2_2.tgz cp /etc/apt/sources.list /tmp/virtual/etc/apt/ cp /etc/resolv.conf /tmp/virtual/etc/ chroot /tmp/virtual/ bin/bash apt-get update dpkg --purge lilo # !NOTE! # 1. You might want to create a 2d proc system # and/or an 2d /dev/ directory # Because on systems where for example sockets are implemented on top of # streams e.g. Sys V based systems, the socket() function will actually be # opening special files in /dev/. # 2. Symlinks do not work within chrooted enviroments. # Use `mount --bind' or `mount -o bind' instead. [Linux Kernel >= 2.4] # # groff/nroff & man pages # convert a man page to ascii/text groff -Tascii -man program.1 nroff -man < program.1 > program.1.txt # or.. man 3 printf | col -b # produce postscript... man -t troff >troff.man.ps # Using `Make' & man pages manpages: foo.n foo_short.n foo.n: foo_master.n nroff -Tlatin1 foo_master.n | sed -e '/^$/d' > foo.n foo_short.n: foo_master.n nroff -Tlatin1 -nSHORT=1 foo_master.n | sed -e '/^$/d' > foo_short.n # # convert .pdf files to .txt files ls -1 *.pdf | while read file ; do ps2ascii $file ${file%%pdf}txt ; done # # convert .chm wintendo format to .html # in DOS hh.exe -decompile c:\output_folder c:\documentation.chm # one could convert the .html output to .pdf with an # utility called DocBook, for GNU/Linux, Unix # # gprof gcc -static -v -g -pg -lc_p myprogram.c -o myprogram ./myprogram gprof ./myprogram gmon.out # # mpatrol gcc ./program.c -include /usr/include/mpatrol.h \ -L/usr/include/mpatrol \ -lmpatrol \ -lelf \ -o program mpatrol --dynamic ./program # now read the logfile in current dir # # memwatch # #include "memwatch.h" gcc -DMEMWATCH -DMW_STDIO program.c memwatch.c -o program # now read the logfile in current dir: memwatch.log # # dump obj. objdump --source -a -x -d -s -r -G -t /bin/mkdir strings /bin/mkdir nm readelf # # gdb gcc -ggdb gdb program (gdb) set args '-H -T -v' (gdb) run (gdb) help run # # splint splint +posixlib -I /path/for/inclusion/ -weak splint -help topic # # Samba smbpasswd -a user -a user # user add -e user # user enable # # Options to increase speed with Samba socket options = TCP_NODELAY SO_SNDBUF=8192 SO_RCVBUF=8192 # !NOTE! # this will disable the Nagle buffering algorithm plus the speed # increase is very minimal. # The Nagle algorithm groups together as much data as it can # inbetween ACK's from the other end of the connection # Search for Nagle at google for more info ... # # locking out non-root users # disable all user logins (except for root) without taking down # the system into maintenance mode create a file: /etc/nologin. # The content of this file will be displayed when a user tries to log in. # # mount mount -w -t smbfs -o username=user,password=passwd //host/c /mnt/c # Msdos to linux net use Disk_name: \\pc_name\dir passwd # # change owner chown name.name file chown -R # Recursive # # dpkg # To make a local copy of the package selection states: dpkg --get-selections > myselections # # Transfer this file to another computer, and # install it there with: dpkg --set-selections < myselections # .deb packages are just ar files.... # # view contents of .deb-package ar -t src/unhtml_2.2-5.deb..deb # # unpack contents of .deb package ar -x ar -t src/unhtml_2.2-5.deb..deb # # beep # turn system beep off # if it doesn't work, replace the \e with \033 echo -e "\e[11;0]" # To set another frequency echo -e "\e[10;]" # Set the duration (must be < 2000 miliseconds) echo -e "\e[11;]" # # terminal bell in bash # get a key-list + save it to my_file bind -v > my_file # set bell-style none - in my_file # in bashrc bind -f .my-file # # Tera Term & Vi Improved background color. # To get rid of white background when # working with vim from Tera-Term # set TERM to `vt100' instead of `linux' # in your shell start-up files. # # inet.d swat stream tcp nowait.400 root /usr/sbin/tcpd /usr/sbin/swat smtp stream tcp nowait root /usr/sbin/exim in.exim -bs # Exim as deamon only when requested. To slow for my 386 :( grrr waf, waf /etc/init.d/inetd #(restart|reload|start|stop) # # mail mail [user] -s [subject] < [file] mail [user] -s [subject] < /dev/null > EOF # End session (ctrl-d) or `.' # from the command line with other programs... echo -e 'Subject: test\nhello this is a test' | /usr/sbin/exim name@domain.com pine -url 'mailto:billy@kristal.com?subject=a%20subject&body=the%20body' # # Exim boot & DNS # if exim hangs for about 2min's during boot and have no network, # add the following line to: /etc/exim4/update-exim4.conf.conf dc_minimaldns='true' # and execute. update-exim4.conf # # ping ping -fs 9999 175.1.44.255 -f = flood # ok -s = packet size # max= -l = preload # (need to have root priveleges) -f = predefined hex # -f ff # return 0 =UP - return 1 =DOWN - return 2 =ERROR # # Find out MSN messenger ip address of other people # open up MSDOS console and type netstat -n 3 # now send the specific user a file ... # voila; the new ip address is in the MSDOS window # # IP nr to base 10 192.168.1.200 $1=192 $2=168 $3=1 $4=200 echo $1|awk -F. '{print $1" * 256^3 + "$2" * 65536 + "$3" * 256 + "$4}'|bc # # netcat # What's that site running ? echo -en "HEAD / HTTP/1.0\n\n" | nc localhost 80 | egrep "^Server:.*$" # a server running on port 2000 nc -l -p 2000 # tcp port scanner nc -vz localhost 1-1024 # udp port scanner nc -vz -vur -i 1 -w 2 localhost 1024 108-112 # Retrieve stats from ADSL modem speedtouch with netcat printf "\r\n\r\n%s\r\n\r\nexit\r\n" 'ip aplist' | nc -t -v modem # # stty stty sane # reset stty -echo # turn echo off (password like) stty echo # turn echo on # # find find . -name '*.mp3' -exec rm '{}' \; find . -size 0 -exec rm -i {} \; find '[.]' # find last modified file find / -ctime -1 -print # find world writable files find / -perm -2 ! -type l -ls # remove anything older than 14 days find $HOME/foo -mtime +14 -exec rm {} \; find / -group lefox -exec rm -i {} \; # upper --> lower find . -type d -print | xargs rename 'tr/A-Z/a-z/;' find / -name 'foo'[$] find . -type d -maxdepth 1 # find jpg's smaller than 40k and remove them find . -type f -name '*.jpg' -size -40k -print -exec rm '{}' \; # find object files larger than 1MB not accessed in a year find /users -type f -name "*.o" -size +1048576c -atime +365 -print # List all C source files sorted by number of lines find . -name "*.c" -print | xargs wc -l | sort -nr # Recursive thumbnail conversion find . -name '*.jpg' -print | while read file ; do convert -geometry 120x90 "$file" "${file%/*}/thumb_${file##*/}" ; done # display inode nr of file: ls -i * # find the file associated with it, and remove it by inode nr. find . -inum 615383 -exec rm '{}' \; # find files modified 3 days ago find . -mtime 3 -print # find files modified inbetween 9 and 11 days ago find . -mtime +9 -mtime -11 -print # # locate locate foo # (update database (redhat)) Or updatedb (debian) locate -u # # telnet to smtp-port helo test mail from: rcpt to: data just a test . to: root quit # fetch a file with telnet.. telnet to remote machine uuencode myfile disconnect use your screen buffer to cut and past the previous output into a target file now use uudecode done ... # # Formail # print all the from addresses formail -Y -czxFrom: -s < ~/mail/spam/spam # # bash-prompt # Some of the codes that can go in your bash-prompt are: + \d the date (day-of-the-week month day) + \h the hostname (without the domain) + \n start a new line + \u the current username + \w the working directory # # Personal prompt: PS1='`date +%H:%M` [tty`tty | cut -c10`] \u:\w\$ ' # # reset terminal # bash reset stty sane # # Or # '^O' (control-O) at the beginning of your prompt ($PS1). # This automatically changes the charset back as soon as my prompt starts to # print. # # jobs # show pid jobs -l fg # foreground current job [1 job] %2 # foreground second job pidof pppd # shows pid off pppd # # kill skill -c [command that is runnning] `pidof ???` # # init # Runlevel 0 is halt. # Runlevel 1 is single-user. # Runlevels 2-5 are multi-user. # Runlevel 6 is reboot. init -s # single user mode # # apt apt-cache search netris apt-get install [-s] netris # # system sysctl -a lsof # # rpc rpcinfo -p hostname # # last log last lastlog w # # tar # remote backup tar --file=HOSTNAME:/DEV/FILE NAME tar -xvzf filefoo (tar en gzip (z) combi) # Store files in different dir at the same time. tar -cvzf tmp.tgz -C /etc . -C /usr/local/etc . # directory full of tar and gzipped files # uncompress them all at once #!/bin/sh dir=. tararray=$(ls $dir/*.tar.gz|xargs) for file in $tararray ; do gunzip -9c $file | tar xvf - done # # backup from a list of files tar czvf tarfile.tar.gz -T list_file # where list_file is a simple list of what you want to # include into the tar array # example: /etc/smb.conf /root/myfile # all files into the /etc/ppp directory /etc/ppp /opt/gnome/html/gnome-dev-info.html # extract a single file from the tgz.archive to stdout tar zxfO logs.tgz ppp.log # # fold fold -s text.txt # format text to xxx chars, break at spaces # # expand expand # euh... expand # # System info dmesg w last -20 tail -20 /var/log/messages # # No Mesg y blinking on all your consoles. # In ~/.profile: mesg y [ `who -T |grep "$LOGNAME\ *+" |wc -l` -ge 1 ] && mesg n # # RPM / deb rpm -ivh package.rpm rpm -ivh --replacepkgs package.rpm rpm -e package dpkg -i foo.deb apt-get install foo.deb apt-cdrom add # # Print lpr -#1 -Ppr1 foo lpq lpc lprm man sendmail | lpr man sendmail | mpage -2 | lpr printtool (in Xwindows) magicfilter(config) # # Patches cp patch.gz /usr/src/ cd /usr/src zcat 'patch.gz | patch -p0' --- diff -Naur [OLD[dir|file]] [NEW[dir|file]] > new_patch cd directory to where patch needs to be applied patch -p0 < new_patch patch -p1 < new_patch -p[0|1] directory levels, to strip or not to strip # # Assign multiple ip-addresses to one ethernet card. # GNU Debian: # add the following lines to the file /etc/network/interfaces # # Dummy interface iface eth0:1 inet static address 192.168.1.10 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 # and at the prompt give the command: ifconfig -a down && ifconfig -a up # or # You have a machine at 192.168.10.1 on device eth0. # ifconfig eth0:1 192.168.10.2 # route add -host 192.168.10.2 dev eth0:1 # You can ping yourself at two different IPs. # The process can be repeated with eth0:2, :3, etc... # Warping with the speed of arping, boom you are a box ? #!/bin/sh MAC=`ifconfig eth0 |awk '/HWaddr/ {print $5}'` IP=`tcpdump -nc1 ether dst $MAC and icmp[0]=8 |awk '/echo request/ {sub(":","",$4);print $4}'` echo $IP # # Grep grep -in "HDIO_GETGEO_BIG" /usr/src/linux/include/linux/hdreg.h # everything exept for foo grep -v foo bla.txt # recursive while ignoring case grep -ir querry * # show line B-fore and A-fter match grep -A1 -B1 querry * # # news # post every file we can find find . -type f -exec newspost -s "Every file we can find" -n alt.binaries.pictures -f noaddress@botmail.com -o no_organisation -i news.foreveryone.net "{}" \; # # Crontab crontab -e (Open with vi with current user) MINUTE(0-59) HOUR(0-23) DAYOFMONTH(1-31) MONTHOFYEAR(1-12) DAYOFWEEK(0-6) Note 0 = Sun */5 * * * * mail joepie@internet.org << /dev/null #every 5 minutes a mailling.. # # at at -l # list queue, same as atq at -d job1 # delete jobs from the at queue by number, same as atrm # -- # Run `program' once at 06:15 p.m. tomorrow: at 6:15pm tomorrow at> program at> ^D # Run commands that are listed in the file `command_list' at # 9 p.m. two days from now: at -f command_list 9pm + 2 days # remove job number 5 from the at queue at -d 5 # # Debian boot scripts #Place Script foo in /etc/init.d update-rc.d foo defaults 91 #Link to script foo is now being made in # /etc/rc[2-5].d as sfoo and kfoo (start & kill), # 91 is time # # split files # Cut file foo in pieces of 100kb split --bytes=100k foo foofoo # split c code into separate routines csplit -k test.c '%main(%' '/^}/+1' {20} # # Concatinating Files foofoo?? cat foofoo* >> foo # # a Floppy image cat < /dev/fd0 > /tmp/flop # # Date # Change Date (make sure to execute all the commands) date --set "11/23/00 11:19:00" echo "" > /etc/adjtime hwclock --systohc # # forgot root-passwd (lilo) # while booting linux init=/bin/bash rw # or linux init=/bin/bash ro erase passwd at /etc/passwd or in /etc/shadow Reboote # # Squid squid -k shutdown #Squid-cache rebuild: rm -rf /var/spool/squid/* squid -z (=build the directory-structure again) squid -k reconfigure # # NcFTP ncftpput -u user -p xxxxx ftp.xs4all.nl WWW sandwich.html ncftpget -u user -p xxxxx ftp.xs4all.nl ~ WWW/sandwich.html # # Arghh nr's hexadecimal: decimal >>> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 hexadecimal >>> 1 2 3 4 5 6 7 8 9 A B C D E F 2DA --> 730 (decimal) 10 * 1 = 10 (16 power 0) 13 * 16 = 208 (16 power 1) 2 * 256 = 512 + (16 power 2) --------------- 730 binairy: 10010111 --> 151 (decimal) 1 * 1 = 1 1 * 2 = 2 1 * 4 = 4 0 * 8 = 0 1 * 16 = 16 0 * 32 = 0 0 * 64 = 0 1 * 128 = 128 + --------------- 151 binary: ------------------------------------------- | double or long word | ------------------------------------------- | | word | ------------------------------------------- | | | | byte | ------------------------------------------- | | | | | | | |nibble| ------------------------------------------- | 11010111| 11001010| 1111001 |1110| 1001 | ------------------------------------------- NAME SIZE IN BITS SIZE IN BYTES VARIABLE SIZE IN C ------------------------------------------------------------------------------ | nibble | 4 bits | ½ byte | not available | ------------------------------------------------------------------------------ | byte | 8 bits | 1 byte | char | ------------------------------------------------------------------------------ | word | 16 bits | 2 byte | unsigned integer | ------------------------------------------------------------------------------ | double or long word | 32 bits | 4 byte | unsigned long integer | ------------------------------------------------------------------------------ # base 64 encoding. # each character of an encode string # represents six bits of an input word. # Symbol table: 0 1 2 3 4 5 6 7 0 . / 0 1 2 3 4 5 8 6 7 8 9 A B C D 16 E F G H I J K L 24 M N O P Q R S T 32 U V W X Y Z a b 40 c d e f g h i j 48 k l m n o p q r 56 s t u v w x y z # # Bash History # Equivalent to recall-function from Vax alias r='fc -s' (in .bashrc) # Bash commandline !ss history man history [CTRL-r] # # scp scp sed.html user2@host:~/sed.html scp -r user1@hot.net:~/ . # copy all,.... # # Upper to lowercase sed y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ sed s/[a-z]/[A-Z]/g # # tr tr [:upper:] [:lower:] # Convert DOS to UNIX tekstformat # Dos newline = \r\n # Unix newline = \n tr -d '\015' < filename > newfile # Remove multiple blank spaces tr -s ' ' ' ' < test.txt # To rot 13 tr '[A-Za-z]' '[N-ZA-Mn-za-m]' # From rot 13 tr '[N-Z][A-M][n-z][a-m]' '[A-M][N-Z][a-m][n-z]' # delete all character Except vowels tr -dc aeiou # Example from the tr manpage: # Replace all characters that are not a letter `-c' # with a newline `\n' and then squeeze multiple # newlines into a single newline `-s'. # The * after \n means as many repetitions as needed. tr -cs '[A-Z][a-z]' '[\n*]' # substitude all non-printable characters except for # cntrl chars with an underscore tr -sc '![:print:][:cntrl:]' '_' # Remove [multiple] blank lines cat -s < foo.txt | sed '/^[[:space:]]*$/d' # # another rot 13 #! /bin/sed -f y/nopqrstuvwxyzabcdefghijklm/abcdefghijklmnopqrstuvwxyz/ # # sed <[^>]*> # HTML-tagging match ^.*$ # whole sentence ^.*\.html # Equivalent to "*.html" in the shell. ££* # more than one space "£" indicates a "space". ^$ # Empty line # # swap fields echo 'this is a string' | sed 's/^\([a-z]*\) \([a-z]*\) \([a-z]*\) \([a-z]*\)/\3 \4 \1 \2/' output: a string this is # # mime sed -n '/------=_NextPart_/,/==$/!p' # # remove most HTML tags (accommodates multiple-line tags) sed -e :a -e 's/<[^>]*>//g;/ version 5.1 Latest version of this file is usually at: http://www.student.northpark.edu/pemente/sed/sed1line.txt http://www.cornerstonemag.com/sed/sed1line.txt This file is also available in Portuguese at: http://www.lrv.ufsc.br/wmaker/sed_ptBR.html FILE SPACING: # double space a file sed G # double space a file which already has blank lines in it. Output file # should contain no more than one blank line between lines of text. sed '/^$/d;G' # triple space a file sed 'G;G' # undo double-spacing (assumes even-numbered lines are always blank) sed 'n;d' NUMBERING: # number each line of a file (simple left alignment). Using a tab (see # note on '\t' at end of file) instead of space will preserve margins. sed = filename | sed 'N;s/\n/\t/' # number each line of a file (number on left, right-aligned) sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /' # number each line of file, but only print numbers if line is not blank sed '/./=' filename | sed '/./N; s/\n/ /' # count lines (emulates "wc -l") sed -n '$=' TEXT CONVERSION AND SUBSTITUTION: # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format sed 's/.$//' # assumes that all lines end with CR/LF sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M sed 's/\x0D$//' # gsed 3.02.80, but top script is easier # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format sed "s/$/`echo -e \\\r`/" # command line under ksh sed 's/$'"/`echo \\\r`/" # command line under bash sed "s/$/`echo \\\r`/" # command line under zsh sed 's/$/\r/' # gsed 3.02.80 # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format sed "s/$//" # method 1 sed -n p # method 2 # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format # Cannot be done with DOS versions of sed. Use "tr" instead. tr -d \r outfile # GNU tr version 1.22 or higher # delete leading whitespace (spaces, tabs) from front of each line # aligns all text flush left sed 's/^[ \t]*//' # see note on '\t' at end of file # delete trailing whitespace (spaces, tabs) from end of each line sed 's/[ \t]*$//' # see note on '\t' at end of file # delete BOTH leading and trailing whitespace from each line sed 's/^[ \t]*//;s/[ \t]*$//' # insert 5 blank spaces at beginning of each line (make page offset) sed 's/^/ /' # align all text flush right on a 79-column width sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at 78 plus 1 space # center all text in the middle of 79-column width. In method 1, # spaces at the beginning of the line are significant, and trailing # spaces are appended at the end of the line. In method 2, spaces at # the beginning of the line are discarded in centering the line, and # no trailing spaces appear at the end of lines. sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1 sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' # method 2 # substitute (find and replace) "foo" with "bar" on each line sed 's/foo/bar/' # replaces only 1st instance in a line sed 's/foo/bar/4' # replaces only 4th instance in a line sed 's/foo/bar/g' # replaces ALL instances in a line sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case sed 's/\(.*\)foo/\1bar/' # replace only the last case # substitute "foo" with "bar" ONLY for lines which contain "baz" sed '/baz/s/foo/bar/g' # substitute "foo" with "bar" EXCEPT for lines which contain "baz" sed '/baz/!s/foo/bar/g' # change "scarlet" or "ruby" or "puce" to "red" sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g' # most seds gsed 's/scarlet\|ruby\|puce/red/g' # GNU sed only # reverse order of lines (emulates "tac") # bug/feature in HHsed v1.5 causes blank lines to be deleted sed '1!G;h;$!d' # method 1 sed -n '1!G;h;$p' # method 2 # reverse each character on the line (emulates "rev") sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//' # join pairs of lines side-by-side (like "paste") sed '$!N;s/\n/ /' # if a line ends with a backslash, append the next line to it sed -e :a -e '/\\$/N; s/\\\n//; ta' # if a line begins with an equal sign, append it to the previous line # and replace the "=" with a single space sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D' # add commas to numeric strings, changing "1234567" to "1,234,567" gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta' # GNU sed sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' # other seds # add commas to numbers with decimal points and minus signs (GNU sed) gsed ':a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta' # add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.) gsed '0~5G' # GNU sed only sed 'n;n;n;n;G;' # other seds SELECTIVE PRINTING OF CERTAIN LINES: # print first 10 lines of file (emulates behavior of "head") sed 10q # print first line of file (emulates "head -1") sed q # print the last 10 lines of a file (emulates "tail") sed -e :a -e '$q;N;11,$D;ba' # print the last 2 lines of a file (emulates "tail -2") sed '$!N;$!D' # print the last line of a file (emulates "tail -1") sed '$!d' # method 1 sed -n '$p' # method 2 # print only lines which match regular expression (emulates "grep") sed -n '/regexp/p' # method 1 sed '/regexp/!d' # method 2 # print only lines which do NOT match regexp (emulates "grep -v") sed -n '/regexp/!p' # method 1, corresponds to above sed '/regexp/d' # method 2, simpler syntax # print the line immediately before a regexp, but not the line # containing the regexp sed -n '/regexp/{g;1!p;};h' # print the line immediately after a regexp, but not the line # containing the regexp sed -n '/regexp/{n;p;}' # print 1 line of context before and after regexp, with line number # indicating where the regexp occurred (similar to "grep -A1 -B1") sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h # grep for AAA and BBB and CCC (in any order) sed '/AAA/!d; /BBB/!d; /CCC/!d' # grep for AAA and BBB and CCC (in that order) sed '/AAA.*BBB.*CCC/!d' # grep for AAA or BBB or CCC (emulates "egrep") sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d # most seds gsed '/AAA\|BBB\|CCC/!d' # GNU sed only # print paragraph if it contains AAA (blank lines separate paragraphs) # HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;' # print paragraph if it contains AAA and BBB and CCC (in any order) sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d' # print paragraph if it contains AAA or BBB or CCC sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only # print only lines of 65 characters or longer sed -n '/^.\{65\}/p' # print only lines of less than 65 characters sed -n '/^.\{65\}/!p' # method 1, corresponds to above sed '/^.\{65\}/d' # method 2, simpler syntax # print section of file from regular expression to end of file sed -n '/regexp/,$p' # print section of file based on line numbers (lines 8-12, inclusive) sed -n '8,12p' # method 1 sed '8,12!d' # method 2 # print line number 52 sed -n '52p' # method 1 sed '52!d' # method 2 sed '52q;d' # method 3, efficient on large files # beginning at line 3, print every 7th line gsed -n '3~7p' # GNU sed only sed -n '3,${p;n;n;n;n;n;n;}' # other seds # print section of file between two regular expressions (inclusive) sed -n '/Iowa/,/Montana/p' # case sensitive SELECTIVE DELETION OF CERTAIN LINES: # print all of file EXCEPT section between 2 regular expressions sed '/Iowa/,/Montana/d' # delete duplicate, consecutive lines from a file (emulates "uniq"). # First line in a set of duplicate lines is kept, rest are deleted. sed '$!N; /^\(.*\)\n\1$/!P; D' # delete duplicate, nonconsecutive lines from a file. Beware not to # overflow the buffer size of the hold space, or else use GNU sed. sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P' # delete the first 10 lines of a file sed '1,10d' # delete the last line of a file sed '$d' # delete the last 2 lines of a file sed 'N;$!P;$!D;$d' # delete the last 10 lines of a file sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1 sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2 # delete every 8th line gsed '0~8d' # GNU sed only sed 'n;n;n;n;n;n;n;d;' # other seds # delete ALL blank lines from a file (same as "grep '.' ") sed '/^$/d' # method 1 sed '/./!d' # method 2 # delete all CONSECUTIVE blank lines from file except the first; also # deletes all blank lines from top and end of file (emulates "cat -s") sed '/./,/^$/!d' # method 1, allows 0 blanks at top, 1 at EOF sed '/^$/N;/\n$/D' # method 2, allows 1 blank at top, 0 at EOF # delete all CONSECUTIVE blank lines from file except the first 2: sed '/^$/N;/\n$/N;//D' # delete all leading blank lines at top of file sed '/./,$!d' # delete all trailing blank lines at end of file sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' # works on all seds sed -e :a -e '/^\n*$/N;/\n$/ba' # ditto, except for gsed 3.02* # delete the last line of each paragraph sed -n '/^$/{p;h;};/./{x;/./p;}' SPECIAL APPLICATIONS: # remove nroff overstrikes (char, backspace) from man pages. The 'echo' # command may need an -e switch if you use Unix System V or bash shell. sed "s/.`echo \\\b`//g" # double quotes required for Unix environment sed 's/.^H//g' # in bash/tcsh, press Ctrl-V and then Ctrl-H sed 's/.\x08//g' # hex expression for sed v1.5 # get Usenet/e-mail message header sed '/^$/q' # deletes everything after first blank line # get Usenet/e-mail message body sed '1,/^$/d' # deletes everything up to first blank line # get Subject header, but remove initial "Subject: " portion sed '/^Subject: */!d; s///;q' # get return address header sed '/^Reply-To:/q; /^From:/h; /./d;g;q' # parse out the address proper. Pulls out the e-mail address by itself # from the 1-line return address header (see preceding script) sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//' # add a leading angle bracket and space to each line (quote a message) sed 's/^/> /' # delete leading angle bracket & space from each line (unquote a message) sed 's/^> //' # remove most HTML tags (accommodates multiple-line tags) sed -e :a -e 's/<[^>]*>//g;/zipup.bat dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat TYPICAL USE: Sed takes one or more editing commands and applies all of them, in sequence, to each line of input. After all the commands have been applied to the first input line, that line is output and a second input line is taken for processing, and the cycle repeats. The preceding examples assume that input comes from the standard input device (i.e, the console, normally this will be piped input). One or more filenames can be appended to the command line if the input does not come from stdin. Output is sent to stdout (the screen). Thus: cat filename | sed '10q' # uses piped input sed '10q' filename # same effect, avoids a useless "cat" sed '10q' filename > newfile # redirects output to disk For additional syntax instructions, including the way to apply editing commands from a disk file instead of the command line, consult "sed & awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly, 1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power of sed, one must understand "regular expressions." For this, see "Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997). The manual ("man") pages on Unix systems may be helpful (try "man sed", "man regexp", or the subsection on regular expressions in "man ed"), but man pages are notoriously difficult. They are not written to teach sed use or regexps to first-time users, but as a reference text for those already acquainted with these tools. QUOTING SYNTAX: The preceding examples use single quotes ('...') instead of double quotes ("...") to enclose editing commands, since sed is typically used on a Unix platform. Single quotes prevent the Unix shell from intrepreting the dollar sign ($) and backquotes (`...`), which are expanded by the shell if they are enclosed in double quotes. Users of the "csh" shell and derivatives will also need to quote the exclamation mark (!) with the backslash (i.e., \!) to properly run the examples listed above, even within single quotes. Versions of sed written for DOS invariably require double quotes ("...") instead of single quotes to enclose editing commands. USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used the expression '\t' to indicate a tab character (0x09) in the scripts. However, most versions of sed do not recognize the '\t' abbreviation, so when typing these scripts from the command line, you should press the TAB key instead. '\t' is supported as a regular expression metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80. VERSIONS OF SED: Versions of sed do differ, and some slight syntax variation is to be expected. In particular, most do not support the use of labels (:name) or branch instructions (b,t) within editing commands, except at the end of those commands. We have used the syntax which will be portable to most users of sed, even though the popular GNU versions of sed allow a more succinct syntax. When the reader sees a fairly long command such as this: sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d it is heartening to know that GNU sed will let you reduce it to: sed '/AAA/b;/BBB/b;/CCC/b;d' # or even sed '/AAA\|BBB\|CCC/b;d' In addition, remember that while many versions of sed accept a command like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which contains space before the 's'. Omit the space when typing the command. OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to large input files or slow processors or hard disks), substitution will be executed more quickly if the "find" expression is specified before giving the "s/.../.../" instruction. Thus: sed 's/foo/bar/g' filename # standard replace command sed '/foo/ s/foo/bar/g' filename # executes more quickly sed '/foo/ s//bar/g' filename # shorthand sed syntax On line selection or deletion in which you only need to output lines from the first part of the file, a "quit" command (q) in the script will drastically reduce processing time for large files. Thus: sed -n '45,50p' filename # print line nos. 45-50 of a file sed -n '51q;45,50p' filename # same, but executes much faster If you have any additional scripts to contribute or if you find errors in this document, please send e-mail to the compiler. Indicate the version of sed you used, the operating system it was compiled for, and the nature of the problem. Various scripts in this file were written or contributed by: Al Aab # "seders" list moderator Edgar Allen # various Yiorgos Adamopoulos Dale Dougherty # author of "sed & awk" Carlos Duarte # author of "do it with sed" Eric Pement # author of this document Ken Pizzini # author of GNU sed v3.02 S.G. Ravenhall # great de-html script Greg Ubben # many contributions & much help ------------------------------------------------------------------------- # # AWK # # emulate cat awk {print} # emulate wc. awk { chars += length($0) + 1 ; words += NF} # emulate wc. awk 'END { print NR }' # emulate grep awk '/expression/ { print }' # emulate grep - all letters and numbers awk '/[a-zA-Z0-9]/ { print }' # emulate grep - match expression only on field 3 awk '$3 ~ /[Ee]pression/ { print }' # emulate grep - don NOT! match expression on field 3 awk '$3 !~ /[Ee]pression/ { print }' # only print the last field awk { print $(NF) } # set the field seperator to a colon awk 'BEGIN { FS = ":" }' # find same 3 charaters in one file awk "{ for (i = 1; i <= NF; i++) if (\$i ~ /$1.*$1.*$1/) print \$i }" # print all input fields one per line grep 'Expression' My.file | awk '{ for (i = 1; i <= NF; i++)print $i }' # the fourth field is the sum of the second field and the third field. awk '{ $4 = $2 + $3; print $0 }' # if the third field is larger then 118, #then the third field holds the value of "too big". awk '{ if ($3 > 118) $3 = "too big" ; print }' # prints the total of the sum of each field it encounters. # Like field1 + field1 + field1 etc.. = sum awk 'BEGIN {sum=0} ; {sum=sum+$1} ; END {print sum}' My.file ######### # BEGIN and END provide a way to gain control before and after processing. # A pattern in front of an action acts as a selector that determines whether # the action is to be executed. # # PINE # modify from header. Version > 4.0 # Edit .pinerc directly and add under the features list the hidden pine opion: allow-changing-from # More info at: http://www.ii.com/internet/messaging/pine/changing_from/ # # PINE # automaticly edit your signature everytime # it gets invoked # write a shell-script that echoe's your # sig to stdout(). # and define your signature-file to be signature-file = fortunesig| # yes; define filename, and add a pipe # to the end of line in configfile # # Passwd #Audit pwck # # set hostname hostname -s # # ImageMagick identify -ping ww_04.jpg # output ww_04.jpg 800x533 DirectClass 79kb JPEG 1s # Convert to thumbnails convert -geometry 120x90 picture.jpg thumb_picture.jpg # split an animated gif into seperate images convert +adjoin -coalesce image.gif frame%02d.gif # Recursive thumbnail conversion ... find . -name '*.jpg' -print | while read file ; do convert -geometry 120x90 "$file" "${file%/*}/thumb_${file##*/}" ; done # convert a directory full of .bmp files to .png files for file in *.bmp ; do convert $file ${file%.bmp}.png ; done # Convert all jpg images found in directory to thumbs.. mogrify -size 120x120 -resize 120x120 +profile "*" *.jpg # create a single index or overview of multiple images montage -label '%f\n%b' -tile 6x24 img1.jpg img2.jpg img3.jpg index.jpg # rotate an image convert -rotate 90 input.jpg output.jpg # inserting text strings into images convert -font helvetica -fill green \ -pointsize 22 -draw 'text 20,80 "This is a string"' image.jpg image_with_text.jpg # Convert images into .pdf convert *.jpg images.pdf # extract images from .pdf convert images.pdf image_%02d.jpg # # host host -t MX hotmail.com Output: hotmail.com mail is handled by 5 mx4.hotmail.com. hotmail.com mail is handled by 5 mx1.hotmail.com. hotmail.com mail is handled by 5 mx2.hotmail.com. hotmail.com mail is handled by 5 mx3.hotmail.com. # # bash operator expansion foo=/usr/bin/X11/startx echo ${foo#*/} # output usr/bin/X11/startx echo ${foo##*/} # output startx # # ${param:-default} # If param is null, param gets the value of `default'. ${#param} # supplies the length of `param'. ${param%word} # remove from end the smallest part from `param' # that equals `word' and returns the remainder as result. ${param%%word} # remove from end the biggest part from `param' # that equals `word' and returns the remainder as result. ${param#word} # remove from the start the smallest part of `param' # that equals `word' and returns the remainder as result. ${param##word} # remove from the start the longest part from `param' # that equals `word and returns the remainder as result. ${foo:=bar} # Test if foo is not 0 and exsist, if so, return the value of # foo, if not the value of bar is assignend to foo and returns # the value. ${foo:?bar} # prints the string `foo:', if foo doesn't exsist, it stops executing # the command if foo doesn't exsist or is 0. ${foo:+bar} # returns bar if foo exsists and is not 0. # # remove lilo from the mbr from DOS dosprompt> FDISK /MBR # # nano sleeping in ansi-c man nanosleep # # Send WinPopup-Messages to all active hosts in a workgroup # This would be useful to send all active users messages like # servers going down for reboot in x minutes". # interpret the output of nmblookup '*' # Resolving from ip to netbeui as you can do with nbtstat from a M$ WIN95 box: # nbtstat -A xxx.xxx.xxx.xxx nmblookup -U xxx.xxx.xxx.xxx -A # # How to setup Netscape in a Samba environement # Create a profile with netscape that's called default and that points # to the user's directory in the server. mounted in L: : L:\default # The profile must be called default, the directory not. # # copy the default directory to all the users home directory in the # server. # # The file in the server : default/prefs.js holds the preferences # of the user. You can do a script that substitutes the mail address # for every user. # # Make the profiles directory be in the server (that's explained in the docs) # that's not mandatory but it's better for my users because they can log # in any workstation and work the same. # # The users home directory is mapped automatically every # time it enters. I have addedd a [netlogon] entry in # smb.conf and a logon script like this: # net use L: \\MyServer\homes # # Cookies and Netscape [3] rm ~/.netscape/cookies; ln -s /dev/null ~/.netscape/cookies # # Cookies and Netscape [4] chmod 000 ~/.netscape/cookies # # Private / Intranet DNS server # For hosts with 2 or more ethernet cards. # Put a "listen-on" directive in your /etc/named.conf # (assuming you are running bind 8). listen-on { 192.168.0/24; 127/8; }; # # Boost performance for harddisk by using 32bits transfers # add the line to a bootup script `/sbin/init.d/boot.local'. hdparm -c3 /dev/hdX # This enable 32 bit X-fer for you harddisk. # On some systems it boost xfer performance by 75%. # Test how much you gained hdparm -t -T /dev/hdX # # ATX softpower switch - Turn computer off (totaly) # Recompile the kernel (with kernel-package) and enable the APM # features. shutdown -h now # will then turn the computer off. # # Allowing non-root users to shutdown a Linux box. # As root create a group shutdown. addgroup shutdown # Put /sbin/shutdown into the group shutdown. chown root.shutdown /sbin/shutdown # Change accessrights to make /sbin/shutdown setuid and disallow # other users from executing shutdown. chmod 4754 /sbin/shutdown # Make a link from /bin/shutdown to /sbin/shutdown ln -s /sbin/shutdown /bin/shutdown # Now anyone belonging to the group shutdown can execute shutdown but I just will # allow the person in control of the keyboard to be able to issue the shutdown # command. You might prefer something else. # For the following to work you need to have "shadow password" installed. # Edit the file login.defs. Near the end of this file locate the line CONSOLE_GROUPS floppy:audio:cdrom # Remove the hashsign and add the group shutdown to this line and you get: CONSOLE_GROUPS floppy:audio:cdrom:shutdown # Thats it. Everyone logged in via the console will belong to these groups so # you need not add anyone to them. # # Detecting keyboard, mouse movements # `xev` is a program used for discovering keysyms, mouse movements, etc. it's # useful for determining the proper keysyms for trapping alt, shift, win95 keys, # # Memory tune echo "128 256 1024" > /proc/sys/vm/freepages # Good performance for a 32 Meg system used as a small server and # personal workstation. # # pppd # Auto-redail # add the 'persist' option to your config files. # It will auto-redial when disconnected. # # syslog # remote logging # start syslogd with the `-r' option. # Then add the syslog server to the /etc/syslogd.conf # file in the client, (use a @host syntax). # # syslog via ssh # Netcat wil pipe UDP into a TCP stream. # On the client machine, do: nc -l -u -p syslog | nc localhost 9999 # (as root), to bind to the syslog port # On your syslog server end, do: nc -l -p 9999 | nc localhost -u syslog # Setup your ssh tunnel from port 9999 on the client machine to # port 9999 on the syslog server machine. # Setup syslogd on the client to log the messages to localhost. Also, # make sure that the client syslogd is set up to not receive messages # from the network. # You want to filter the TCP listening port on the server to prevent # people from DoS'ing you with `messages'. # # rpm # verify .rpm files vs installation rpm -Vp $PACKAGE_FILE_NAME rpm -V $RPM_PACKAGE_NAME rpm -Va # # accessing files that start with `-' # -- is end of options.... rm -- `-file' grep -- `-file.name' grep `./-file.name' # # Sort # sort on login field sort -t: +6 /etc/passwd # sort in reverse sort -r < myfile # # Virtual hosts # File: /etc/network/interfaces # # The loopback interface auto lo iface lo inet loopback # The first network card - this entry was created during the Debian installation # (network, broadcast and gateway are optional) auto eth0 iface eth0 inet static address 192.168.1.30 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.200 # alias interface auto eth0:1 iface eth0:1 inet static address 192.168.1.10 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.200 # # Virtual host apache config # File: /etc/apache/httpd.conf # NameVirtualHost 192.168.1.10:80 DocumentRoot /var/www/virtual-2/ ServerName 192.168.1.10 ErrorLog /var/log/apache/192.168.1.10-error.log CustomLog /var/log/apache/192.168.1.10-access.log common # # Convert Wintendo .CHM book format # # On your wintendo box [[or GNU/linux+wine]] open a DOS session # enter the following command: hh.exe -decompile output_directory documentaion.CHM # Later one can convert all html files to a .pdf file # with the program ``htmldoc''. # # hard disk probe # hdparm -i /dev/hda /dev/hda: Model=QUANTUM FIREBALL SE6.4A, FwRev=API.0A00, SerialNo=336731814624 etc.. etc.. # # sms_client # sms_client -l4 'kpn:0611100800' 'my message tekst' # # renice, get/setpriority # # renice PID 9239 to -5 renice -5 -p 9239 # change the priority of process ID's 987 and 32, # and all processes owned by users daemon and root. renice +1 987 -u daemon root -p 32 # # ispell ispell -D dutch # use dutch dictionary # produce affixes from root word # echo BOTHER | ispell -c BOTHER BOTHE/R BOTH/R # reverse echo BOTH/R | ispell -e BOTH BOTHER # # Make # show commands, do not execute # `cd path/where/makefile/` make -n # Single source file,small `Make' example # uses script install dirs.. # `make install && make clean` CC=gcc FLAGS = -g -O2 -Wall -pedantic PREFIX = /usr/local BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/man/man1 all: program main.o: program.c $(CC) $(FLAGS) -c program.c main: desum.o $(CC) program.o -o program clean: /bin/rm -v -f program.o install: sh mkinstalldirs -m 755 $(BINDIR) cp -v program $(BINDIR) chmod 755 $(BINDIR)/program sh mkinstalldirs -m 755 $(MANDIR) cp man/man1/program.1 $(MANDIR) chmod 644 $(MANDIR)/program.1 # # /etc/hosts block # # on the wintendo.. # in dir. # Windows XP = C:\WINDOWS\SYSTEM32\DRIVERS\ETC # Win 98\ME = C:\WINDOWS # create a file named HOSTS # add the following entry to file HOSTS 127.0.0.1 ad.doubleclick.net # GNU/linux.. # use file /etc/hosts.deny # for a list of servers to deny # http://www.everythingisnt.com/hosts.html # for more info.. # http://www.windowsdevcenter.com/pub/a/windows/2004/03/30/hosts.html # http://www.mvps.org/winhelp2002/hosts.htm # add,configuring locales on debian # write names of all available locales to stdout locale --all-locales # reconfigure a locale.. dpkg-reconfigure locales # # clean/new hdd ? umount /mnt/?mountpoint? # remove everything.. dd if=/dev/zero of=/dev/hd? bs=64KB count=1 # create new partition.. [c]fdisk /dev/hd?? # make new filesystem mkfs.ext[2|3] /dev/hde1 # mount it again.. mount /dev/hd?? /mnt/?mountpoint? # update /etc/fstab accordingly # # Call to undefined function: mysql_connect() # solution [[debian]] 1. make sure you have installed mysql, php & apache ;-) 1.1 U can use: to see if mysql is compiled with php, etc... 2. add to your php.ini: extension=mysql.so 3. test if mysql.so is there /usr/lib/php4/????? 4. see if `extension_dir=??????` points to it in your php.ini extension_dir = "/usr/lib/php4/20010901/" # MAKE SURE YOU USE THE QUOTES: "./my/path/" e.g. """""""""""""""""""" # reload the apache configuration # that's it.. it should work now.. # # A computer.. ?? [[electricity => Transistors => Gates => ALU]] * [electrons] travel through transistors. * [transistors] are arranged to make simple gates. * [gates,AND,OR,NOT] are simple logical functions {1 AND 1 = 1; 1 AND 0 = 0} * [many gates are combined which makes an ALU [arithmetic-logical unit] [gates can be arranged to make adders, comparitors, and multipliers] * an ALU is a giant unit, and its function can be selected, {depending on its input A, input B, and a control signal} * A sequence of signals can be a simple program for the ALU. (Let's say you want to add A, B, and C). - Give input A, input B, and a control signal (ADD operation) - The result is A+B, call this X. Write this down. - Give input X, input C, and ADD - The result is A+B+C, which is the result we want. # # create a 1MB test file filled with some random bytes.. dd if=/dev/urandom of=/myfile bs=1M count=1 # # convert .ico to xwindows xpm.. # 1. use convert from ImageMagick convert pc.ico pc.xpm # 2. edit pc.xpm and change; static char *building[] = { # to static char *building_xpm[] = { # 3. change color HEX value's to width 6 instead of 8, done.. # [creating favicon..? google for png2ico] # # Terminal Scroll Lock in bash # Lock your terminal.. Hit C-S # UNlock your terminal.. Hit C-Q # # Pasting into Vim and avoiding excess whitespace # # turn autoident off. set noautoindent # paste... and after turn autoindent on again :set autoindent # or before the paste... :set paste # paste... and after turn paste turn off :set nopaste