*** How to daily live Linux/Unix by Eric *** *How to read a initrd file: zcat initrd.img > initrd.uc mount -t auto ./initrd.uc /mnt/disk -o loop * How to list the files contained in a initramfs: gunzip -c /boot/initrd-2.6.14-eric-1.img | cpio -t * How to read a .dmg file: Uncompress it with dmg2img mount it like a hfsplus disk * How to create a .dmg file Create a blessed hfsplus with mkisofs Compress it with dmg (from libdmg-hfsplus) * How to install a compiled kernel make modules_install cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.0-test5-eric-1 cp .config /boot/config-2.6.0-test5-eric-1 cp System.map /boot/System.map-2.6.0-test5-eric-1 cp include/linux/kernel.h /boot/kernel.h-2.6.0-test5-eric-1 mkinitrd /boot/initrd-2.6.0-test5-eric-1.img 2.6.0-test5-eric-1 gvim /etc/lilo.conf;lilo -v * How to allow several processes to use the same alsa channel: write in /etc/asound.conf: pcm.!default { type plug slave.pcm "dmix:RATE=44100" } Or, if possible, simply use a newer alsa lib which has this setting by default * How to synchronize the pc clock on the fly: ntpdate ntp.ndsoftwarenet.com ntp.obspm.fr ntp.tuxfamily.net * How to use the latest autoconf: declare -x WANT_AUTOCONF_2_5=1 *How to do a man without man: bzcat man-file.bz2|groff -mtty-char -Tutf8 -mandoc |less -isrU *Howto read something written in ISO-8859-1 in UTF-8: iconv -f LATIN1 -t UTF8 < text-to-read.txt |less or utrac < text-to-read.txt |less *How to read a man page in utf-8 - put all the utf-8 manpages in directories finishing by .UTF-8 - change /etc/man.config so that the output device is utf8 - install groff-utf8 - modify nroff to run groff-utf8 if the file is from a directory finishing by .UTF-8 *How to read a japanese man (doesn't work well yet) xterm -fa "MS Gothic" iconv -f EUC-JP -t utf8 eject-jp.1 at least it works with konqueror: man:/home/eric/busy/man/eject-jp-utf8.1 Or use gnome-terminal with mandriva 2008 * How to turn on and off the satelitte led of the tm610 with acerhk echo w21> /proc/driver/acerhk/debug echo w20> /proc/driver/acerhk/debug On a kernel 2.6.23, using wistron_btns: echo 1 > /sys/class/leds/wifi\:red/brightness * How to make a root priviledged program runnable by every one put it in /usr/sbin ln -s /bin/consolehelper /bin/theprog make a good entry in /etc/pam.d: cp /etc/pam.d/reboot /etc/pam.d/theprog make an entry in /etc/security/console.apps/: cp /etc/security/console.apps/reboot /etc/security/console.apps/theprog * How to watch pictures according to their date ls -rt --quoting-style=c|xargs qiv -mfeI * How to change on the fly the resolution of the fonts echo "Xft.dpi: 90" |xrdb -override * howto change on the fly the resolution of the root window (and screen) (with xrandr 1.1) xrandr -s 1 *howto play a flash animation when it's in a .exe (for windows) find the starting byte N of the occurence FWS (using hexedit for instance) grep -a -b -o FWS fight.exe dd if=flash-anim.EXE of=flash-anim.swf ibs=1 skip=N #N is decimal tail fight.exe -c +376833 >fight.swf *How to get something not too bad quality in mp3 lame -h -V 7 --vbr-new -b 32 -B 320 %w %m or lame --preset medium --vbr-new %w %m *How to add vbr info to an mp3 file which seems to be extremelly long duration vbrfix *How to use the Canon PowerShot A70 via PTP: (it's necessary to specify the port) gphoto2 --camera "Canon PowerShot A70 (PTP)" --port usb: * How to get files from the camera gphoto2 --auto-detect -L gphoto2 --auto-detect -p 143-146 *How to setup automatically the 32 bits access to the cdrom: /sbin/hdparm -q -c3 /dev/hdc #/sbin/laptop-mode start *How to make all the keys working for the tm610: (cf dumpkeys(1), loadkeys(1), showkey(1)) setkeycodes 55 93 setkeycodes 6f 94 *How to compile wmaker with somewhat good paths ./configure --enable-gnome --enable-kde --prefix=/usr/X11R6 --with-appspath=/usr/X11R6/lib/GNUstep/Apps --with-nlsdir=/usr/share/locale *How to grep the stderr (this also grep the stdout) myprog 2>&1 | grep ... *How to know the maintainer of a given file rpmmon -p $(rpm -qf /dir/file | sed 's/-[^-]*-[^-]*$//') *How to correct the spelling of a tex file aspell --encoding=utf-8 --lang=en -t -c *How to change the HHGG books from html to pdf cat book1.htm |recode /CR-LF..txte|fmt -w 2000 -u>tmp.html mozilla-firefox tmp.txt select all the text paste in ooffice replace \chapter{} by "next page" Change the font, the page size to screen looking one, add page numbering, reduce the margins, cut the words export as PDF *How to login via ssh and have a tunnel to the smtp server ssh -C piel@ara.lifl.fr -L 2525:mailhost.lifl.fr:25 *How to authorise ssh connexion to a machine hidden behind a firewall on the hidden machine, connect to an open one: ssh -C piel@ara.lifl.fr -R 2223:localhost:22 Then, from outside, connect to the open one and then to the hidden one: ssh -C piel@ara.lifl.fr ssh localhost -p 2223 * How to allow VNC connexion from a Linux machine to a Windows machine behind a firewall On the Windows machine: install VNC server (tightvnc.com). Install SSH client (ftp.ssh.com/pub/ssh). Connect to the Linux machine by forwarding port 5900 to port 5900. On the Linux machine: connect a VNC viewer to localhost. *How to change the locale to Japanese: LC_ALL=ja_JP.UTF-8 LC_CTYPE=$LC_ALL : : LANG=$LC_ALL LANGUAGE=$LC_ALL:ja *How to display the numerical wchan of each pid ps n -eo pid,wchan:15,state,comm *How to send realiably and securely a file (or several) rsync --avP --bwlimit=10 eric@pieleric.dyndns.org:/path/to/original.file /path/to/destination.file Additional options -L and -z can also be useful *How to fetch a webpage fast echo -e "GET / HTTP/1.1\nHost: 127.0.0.1\n\n" | nc www.cnn.com 80 * How to print a map of the keyboard xkbprint :0 -level2 * How to put change the layout of only one specific keyboard xinput list # to know what is the ID of the device setxkbmap -device 12 nl * How to convert from °F to °C units tempF(100) tempC * How to detect the encoding of a file enca file.txt or utrac -p file.txt * How to decrease the sound volume by 5% amixer -c 0 sset 'Master' 5%- * How to record realplayer streams mplayer -dumpfile output.rm -dumpstream input.url * How to reencode a movie if its codec doesn't permit real time play mencoder -quiet s1ep01.mp4 -ovc xvid -xvidencopts fixed_quant=4 -oac pcm -o s1ep01-test-xvid-pcm.avi * How to create a bridge with Linux brctl addbr br0 ifconfig br0 up brctl addif br0 eth0 brctl addif br0 eth1 * How to create a gateway with Linux sysctl net.ipv4.ip_forward=1 iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE * How to share an internet connexion over Wifi Set up the server wifi card to a usable configuration (ad-hoc): iwconfig eth2 mode Ad-Hoc essid se key s:brend Set up the wifi card as an ethernet device ifconfig eth1 192.168.0.10 netmask 255.255.255.0 Create the gateway as previously mentioned Set up the client - turn ON the wifi card - set up network essid, mode and key - set up IP and DNS iwconfig eth1 mode Ad-Hoc essid se key s:brend ifconfig eth1 192.168.0.11 netmask 255.255.255.0 route add default gw 192.168.0.10 # resolv.conf * How to hide a file in a JPEG picture (max 10% of the picture size) steghide * How to fork bomb a machine with bash :(){ :|:& };: * How to do cow links in userspace cp -al A B When modifying a file, it must be overwritten (moved, not modified). In vim, you can put set backupcopy=no set writebackup * How to measure the time from low to high freqency by a dynamic cpufreq governor: date +%T.%N; while test $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) != $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq) ; do true ; done ; date +%T.%N * How to select only some bibtex entries accroding to their author: bibtool -- "select{author \"Piel\"}" west.bib -o piel.bib or bibtool -- "select{author \"Piel\"}" west.bib | utrac > piel.bib * How to do PAO: scribus * How to display the temperature in Lille (with internet) curl -s ftp://weather.noaa.gov/data/observations/metar/stations/LFQQ.TXT | tail -1 | tr " " "\n" | tac | grep -Eo ".*\/" | head -1 | tr M - | sed s%/%°C% * How to disable Connection sharing in ssh ssh -S none ... * How to rename files according to a regex for i in *.* ; do mv $i $(echo $i | sed "s%-\(..\)am%-\1.00am%"); done * How to convert a sequel of jpeg's into one pdf: for i in *.jpg; do a2ping $i; done or for i in *.jpg; do convert -density 300 $i $(basename $i .jpg).pdf; done pdftk *.pdf cat output finished.pdf * How to get an image out from a PDF file pdfimage myfile.pdf * How to cancel a file from being treated as binary in CVS: cvs admin -kkv myfile.ext cvs upate -A cvs commit -m "no binary" myfile.ext * How to see an old version of a file in CVS: cvs update -p -r 1.530 filename.tex | gvim - * How to see an old version of a file in SVN: svn cat -r 530 filename.tex | gvim - * How to convert a Windows encoded file to Unix encoding: recode /CR-LF myfile.ext * How to do symbolic mathematic mathomatic * How to find all the coredump files on the system locate -r "/core\.[[:digit:]]\+$" * How to watch a movie which is rotated mplayer -vf rotate=2 # or rotate=1 if clockwise rotation is needed * How to count the number of files in the current directory (recursively) exepted those in the directories called "not-so-good" and those which are hidden. find . -name not-so-good -prune -o -regex ".*/\..*" -prune -o -print | wc -l * How to automatically wake up a suspended PC after a while (can be used to hibernate the PC after a while suspended, or treat cron jobs in time...): echo "+0000-00-00 00:02:00" > /proc/acpi/alarm (watch out the hardware clock after) * How to use special features of Bash for variable modification: info bash Shell Parameter Expansion * How to split a subtitle file (subtitle.srt) identically as a movie - Check the length of the first part tcprobe mymovie1.avi -> hh:mm:ss,ttt - find the number of the first caption after the split vim subtitle.srt -> NUM - cut out the first part srttool -c 1,NUM -i subtitle.srt -o subtitle1.srt - cut out the second part srttool -c NUM -i subtitle.srt -o tmp.srt - compute how long after the split the first caption should appear head tmp.srt shift = time-of-caption - time-of-split - shift the second part and renumber the captions srttool -r -a 00:00:sh,ift -i tmp.srt -o subtitle2.srt * How to concatenate two subtitles together (not exact output) - finf out the time of the last caption in the first file. Pray it's not too far from the first caption of file2 tail file1.srt -> hh:mm:ss,ttt - shift the second subtitle by this amount srttool -a 00:00:sh,ift -i file2.srt -o tmp.srt - concatenate the two subtiles cat file1.srt tmp.srt > tmp2.srt - renumber the captions srttool -r -i tmp2.srt -o final.srt * How to watch "Le Zapping" on internet mplayer -cache 512 http://vipmms.canalplus.fr/canalplus/zapping_060918_a.wmv mplayer -ao alsa -quiet -cache 512 mms://vipmms.canalplus.fr/canalplus/zapping_070907_a.wmv for i in $(seq $(cat ~/tmp/last-zapping) 3000); do wget http://vod-flash.canalplus.fr/ZAPPING_EMISSION_070921_CAN_"$i"_video_H.flv && echo $i > ~/tmp/last-zapping && break; done ($i depends on the file! it's always increasing ~+100/day) * In case the colors are not displayed fine (because of 12bpp) mplayer -quiet -framedrop -vf yuy2 blindness.avi * How to use mplayer to crop subtitles and replace them by new ones mplayer -ao alsa Sekai.No.Chushin.De.Ai.Wo.Sakebu.rmvb -sub Sekai.No.Chushin.De.Ai.Wo.Sakebu.2004.DVDRip.XviD.iNT-NewMov.srt -ass -ass-bottom-margin 64 -ass-use-margins -ass-font-scale 1.5 -vf crop=:280 nicer: mplayer -ao alsa -framedrop -cache 3000 -quiet sad-movie.rmvb -vf crop=:310,expand=0:-100:0:0 ck-method=bg * Decoding HD files, with additional margin for the subtitles mplayer -vfm ffmpeg -vc ffh264 -lavdopts threads=2 -framedrop -quiet zwartboek.mkv -vf expand=0:-150:0:0 * Play .ram with mplayer mplayer -playlist my.ram * How to communicate with HAL To know the available methods: dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.DBus.Introspectable.Introspect To change the cpufreq governor: dbus-send --system --print-reply --dest=org.freedesktop.Hal /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.CPUFreq.SetCPUFreqGovernor string:ondemand * Suspending from the command line dbus-send --print-reply --system --dest=org.freedesktop.DeviceKit.Power /org/freedesktop/DeviceKit/Power org.freedesktop.DeviceKit.Power.Suspend or dbus-send --print-reply --system --dest=org.freedesktop.DeviceKit.Power /org/freedesktop/DeviceKit/Power org.freedesktop.DeviceKit.Power.Hibernate * How to debug a dbus method d-feet * How to remove rpm files of rpm not installed for i in $(rpm -qp --qf "%{NAME}\\n" *.rpm); do rpm -q $i; done | grep "not installed" | cut -d " " -f 2 > not-installed.txt for i in $(cat not-installed.txt ) ; do mv $i-?.*rpm not-installed; done * How to find the most disk space hungry rpm's rpm -qa --qf "%{SIZE} %{NAME}\\n" | sort -n * How to list only the packages for the i586 architecture rpm -qa --qf "%{ARCH} %{NAME} \\n"| grep i586 * How to share the keyboard and mouse with another computer x2x -to 192.168.0.10:0 -buttonblock -east or on triangle.local, do: xhost + on the other host, do: ssh eric@triangle.local x2x -to :0.0 -buttonblock -east * How to change the exif info on the orientation exiv2 mo -M "set Exif.Image.Orientation 1" 0968.jpg * How to change the time info of a picture exiv2 -M"set Exif.Photo.DateTimeOriginal Ascii 2009:08:11 13:41:37" 0968.jpg * How to retrieve contacts from the K610i: obexftp -u 0 -U synch -S -p telecom/pb.vcf => saved as pb.vcf * How to put new contacts on the K610i: put all the contacts in a file named telecom/pb.vcf (eg: in the directory telecom) obexftp -u 0 -S -p telecom/pb.vcf => Note the missing -U synch (it's needed, probably due to a bug in the firmware) * How to convert a russian text looking like Îá ýòîì áóäó êðèàòü âñþ íîü to something readable echo "Îá ýòîì áóäó êðèàòü âñþ íîü" | iconv -f utf8 -t latin1 | iconv -f WINDOWS-1251 -t utf8 * How to get information on Pulseaudio on a X11 display xprop -root | grep ^PULSE_ * How to convert Gaspard2 vectors to MARTE vectors: sed -i -r "s/\(([[:digit:]]+),([[:digit:]]+)\)/{\1,\2}/g;s/\(\)/{}/g;s/\(([[:digit:]]+)\)/{\1}/g;s/\(\{/{{/g;s/}\)/}}/g;" h263-nohwacc-date-marte.mdxml * How to show only common lines between two files sort the two files. diff --old-line-format="" --new-line-format="" --unchanged-line-format="%l"$'\n' A.txt B.txt * How to show lines existing in file A.txt but not file B.txt sort the files diff --unchanged-line-format="" --new-line-format="" --old-line-format="%l"$'\n' A.txt B.txt * How to prevent non-root users from using the system chmod o-rx / * How to differentiate between a physical and a virtual network interface ifconfig -a # to list all the interfaces ll /sys/devices/virtual/net/ # to see if an interface is virtual (otherwise it's physical) * How to add a video mode to an Xorg output cvt 1280 1024 xrandr --newmode "1280x1024_60.00" 109.00 1280 1368 1496 1712 1024 1027 1034 1063 -hsync +vsync xrandr --addmode VGA 1280x1024_60.00 xrandr --output VGA --mode 1280x1024_60.00 * How to know the full path to a file (resolving _every_ links in the path): readlink -m relative/path/to/file * How to convert a base64 string to hexadecimal echo 5Ok2Z9NCtmR1Hi9US1QlYAJnzf8 | base64 --decode | od -A n -t x1 -w32| sed "s/ //g" * activate USB autosuspend for A in `find /sys/bus/usb/devices/*/ -name "level"`; do echo auto > $A; done * Get the drive to turn off after a while mount / -oremount,commit=3600,nodiratime,relatime mount /data -oremount,commit=3600,nodiratime,relatime echo 360000 > /proc/sys/vm/dirty_writeback_centisecs echo 360000 > /proc/sys/vm/dirty_expire_centisecs hdparm -S 1 /dev/sda echo min_power > /sys/class/scsi_host/host0/link_power_management_policy * How to know which program is using most of the CPU/memory top * How to know which programs are using the most of the network nethogs eth1 * How to know which programs are using most of the harddisk bandwith iotop * How to know which program is waking up the CPU most often powertop * How to know which program is using most of the X server memory xrestop * How to know which file is used by which program lsof * How to know which program is listening on which port netstat -p * How to know why a program is slow to react latencytop * How to see the global ressource usage of the system dstat * How to know which sub-directory is using most of the harddisk space du -sk * | sort -n * How to change the default page size of a document generated by pdflatex texconfig (/etc/papersize does not have any effect) * How to update Mandriva cooker to the next cooker URPMI_ADDMEDIA_PRODUCT_VERSION=2010.0 urpmi --auto-update * Set up the synaptic driver to some sane defaults synclient AccelFactor=0.005 MinSpeed=0.1 MaxSpeed=1 TapButton1=1 TapButton2=2 TapButton3=3 CircularScrolling=1 CircScrollTrigger=3 PressureMotionMaxFactor=2 MaxTapTime=180 FastTaps=1 ClickTime=200 SingleTapTimeout=300 TrackstickSpeed=600 MaxTapMove=1000 VertTwoFingerScroll=0 VertEdgeScroll=1 HorizEdgeScroll=1 PalmDetect=1 PalmMinZ=10 * Looking at the second webcam mplayer tv:// -tv device=/dev/video1 * Compressing a movie from a photo camera to something smaller (~8x smaller) mencoder mvi_8490.avi -oac mp3lame -lameopts vbr=2:q=4:mode=3 -ovc x264 -x264encopts subq=5:8x8dct:frameref=2:bframes=3:b_pyramid:weight_b:qp=30 -of lavf -noskip -o mvi_8490-compressed.mkv # or with deinterlacing, denoising, and better quality mencoder ../mov002.mpeg -vf yadif -aspect 16:9 -oac mp3lame -lameopts vbr=2:q=4:mode=3 -ovc x264 -x264encopts subq=6:8x8dct:frameref=2:bframes=3:weight_b:crf=20:nr=100 -of lavf -noskip -o mov002.mkv * How to get the keyboard back in X after it has disapeared: echo -n "i8042" > /sys/bus/platform/drivers/i8042/unbind ; sleep 1; echo -n "i8042" > /sys/bus/platform/drivers/i8042/bind or echo -n rescan > /sys/bus/serio/devices/serio0/drvctl or rmmod atkbd; modprobe atkbd * Find your location given the BSSID of a wifi hotspot: iwlist wlan0 scanning | grep -E "(Address|No scan results)" MYMAC=PUTTHEADDRESSWITHOUTCOLON && curl --header "Content-Type: text/xml" --data "betajs.loki.com$MYMAC-50" https://api.skyhookwireless.com/wps2/location