this collection of little howtos was built up as i spent time figuring out how to do little things in Linux. most of these were first performed in Fedora, since that was my first distribution, but later i began dabbling in Debian and Ubuntu. some of these are specific to one distribution or another, but most should apply to any distribution.
mistakes? questions? know a better way? i can be contacted at bart at bnagel.NOT (net, not not).
the primary audience for this document is myself and for that reason i don’t provide any guarantee that any of this will work – i’ll only say that it worked for me at one point – and i haven’t gone into a great amount of detail. i thought perhaps this would be useful to others, so here it is.
i generally go for Vorbis quality 6 when the source is lossless, but if going from a WMA it probably isn’t worth it. go for the default, which is 3, probably.
mplayer -ao pcm:file=tempfile sourceoggenc -o destination -q quality --artist artist --album album --title title --date year --tracknum tracknum tempfile
mkfifo fifo; (oggenc -o destination -q quality --artist artist --album album --title title --date year --tracknum tracknum fifo; rm fifo) & mplayer -ao pcm:file=fifo source
scp file user@remotehost:destinationpath
either or both files can be remote, destinationpath can be a directory or full path including filename.
bandwidth can be limited with the l switch (Kbit s−1), for instance scp -l 90000 justripped/*.mkv perigee:/srv/media/video/film/ to leave a bit of room on a 100Mbit network
use the p switch to preserve modification times, access times and modes
that means the port switch has to be P port rather than lowercase p.
ssh in – the user who owns the x session must run this (not even root)
DISPLAY=:0 command &
probably want to combine this with nohup so it doesn't die when you log out.
ssh in with the X flag, then just run the program: ssh perigee -X
ssh-keygen -t rsa, no passphrase is fine)cat id_rsa.pub >> ~/.ssh/authorized_keysput unix extensions = no in /etc/samba/smb.conf in the [global] section
grep searchstring file list
this searches in all files in this directory and subdirectories
grep -r searchstring .
use the l switch to print the names of the files with matches rather than the matches themselves
the i switch for case-insensitive
the v switch for an inverse search (return lines/files which don’t match)
egrep instead of grep to use extended regexes
rpm -qa --qf "%{VENDOR} -- %{NAME}\n" | grep -i repo
edit the file /etc/acpi/events/power.conf – mine looks like this:
event=button/power.*
action=/usr/bin/bwarnshutdown
use the wall command. note that consoles can be set not to receive these (local ones are usually set like that for instance)
updatedblocate fglrx | xargs rm -rfrm -rf /usr/share/ati /usr/src/atichange the 5 to 3 in /etc/inittab
./necflash -scan./necflash -dump destination /dev/drive./necflash -flash firmware.bin /dev/drivego to about:plugins
either start it with nohup:
nohup command &
or, to make it not die when already running use disown after getting it running in the background:
disown %jid
ls -d */ or ll | grep ^d
to go recursive, you can use tree -d to show a tree, or stick the -R flag on the one with grep, or use a find . -type d
wavbreaker (an x app)
only newer files are copied. anything not in the source folder is deleted from the destination. be careful with characters which aren't allowed on the target filesystem. my script:
#!/bin/bash rsync --delete --modify-window=1 -av ~/media/music/ /media/IAUDIO/music/ > /var/log/syncx5.log >>&1 | grep -i argument
fat is retarded and makes folders made up of just uppercase lowercase. therefore it'll delete and re-copy the contents of such folders over each time. never mind, eh?
alternatively, use unison, which is based on rsync and can sync in both directions.
yum install kde-i18n-British
control-d
at time
then give commands and stop standard input. no seconds. instead of time, can also give a datetime. understands noon, teatime (4pm), midnight, tomorrow and some other bits.
can also add a relative time, for instance now + 20 minutes (now/tomorrow) (minutes/hours/days/weeks).
check the manpage
output is mailed to the user with sendmail. the DISPLAY environment variable isn't preserved, so if an X app should be loaded, prefix the command with DISPLAY=:0 or similar.
add this stuff to ~/.bashrc (can’t remember where i got it)
DULL=0
BRIGHT=1
FG_BLACK=30
FG_RED=31
FG_GREEN=32
FG_YELLOW=33
FG_BLUE=34
FG_VIOLET=35
FG_CYAN=36
FG_WHITE=37
FG_BOLDWHITE=39
FG_NULL=00
BG_BLACK=40
BG_RED=41
BG_GREEN=42
BG_YELLOW=43
BG_BLUE=44
BG_VIOLET=45
BG_CYAN=46
BG_WHITE=47
BG_NULL=00
##
# ANSI Escape Commands
##
ESC="\033"
NORMAL="\[$ESC[m\]"
RESET="\[$ESC[${DULL};${FG_WHITE};${BG_NULL}m\]"
##
# Shortcuts for Colored Text ( Bright and FG Only )
##
# DULL TEXT
BLACK="\[$ESC[${DULL};${FG_BLACK}m\]"
RED="\[$ESC[${DULL};${FG_RED}m\]"
GREEN="\[$ESC[${DULL};${FG_GREEN}m\]"
YELLOW="\[$ESC[${DULL};${FG_YELLOW}m\]"
BLUE="\[$ESC[${DULL};${FG_BLUE}m\]"
VIOLET="\[$ESC[${DULL};${FG_VIOLET}m\]"
CYAN="\[$ESC[${DULL};${FG_CYAN}m\]"
WHITE="\[$ESC[${DULL};${FG_WHITE}m\]"
# BRIGHT TEXT
BRIGHT_BLACK="\[$ESC[${BRIGHT};${FG_BLACK}m\]"
BRIGHT_RED="\[$ESC[${BRIGHT};${FG_RED}m\]"
BRIGHT_GREEN="\[$ESC[${BRIGHT};${FG_GREEN}m\]"
BRIGHT_YELLOW="\[$ESC[${BRIGHT};${FG_YELLOW}m\]"
BRIGHT_BLUE="\[$ESC[${BRIGHT};${FG_BLUE}m\]"
BRIGHT_VIOLET="\[$ESC[${BRIGHT};${FG_VIOLET}m\]"
BRIGHT_CYAN="\[$ESC[${BRIGHT};${FG_CYAN}m\]"
BRIGHT_WHITE="\[$ESC[${BRIGHT};${FG_WHITE}m\]"
BOLD_WHITE="\[$ESC[${BRIGHT};${FG_BOLDWHITE}m\]"
# REV TEXT as an example
REV_CYAN="\[$ESC[${DULL};${BG_WHITE};${BG_CYAN}m\]"
REV_RED="\[$ESC[${DULL};${FG_YELLOW}; ${BG_RED}m\]"
and then add things like $RED to $PS1 or $PS2, the prompt variables
either use tee, as in ls | tee file or use tail -f as in ls > file & tail -f file. the latter might not print the first bit to standard output if it starts quickly but it'll all be in the file. nevertheless, it's probably better since viewing output can be switched on and off by stopping or starting tail.
better still, run tee while in a screen. then the screen can be detached and reattached later and all previous output will still be visible. screen commands: control-a and then
log out to end any particular screen. screen -r to reattach a screen if it’s been detached.
follow instrux at corefonts (sourceforge). the RPM isn’t in a repo so you build it yourself and have to rebuild to update it.
create the file ~/.my.cnf with contents like:
[mysql] user=user password=pass [mysqladmin] user=user password=pass
note that since it’s not sending from a proper domain it way well end up in the spam box.
oggenc -q quality --discard-comments --artist artistname --album albumname --date year *.flac
i usually go for quality level 6. it might be overkill, but never mind. the discard-comments bit gets rid of existing tags (eg id3, which are sometimes on flac files). then run easytag . to tag the track numbers and titles and rename the files or picard it up.
on Fedora:
id3convert -s1 filesid3convert -s fileson Ubuntu, install id3v2, then
id3v2 -s filesid3v2 -D filesyou can find out which files a program is opening, for instance
strace command 2> outputfile
this works now – before i had the wrong port number for RDP. mushroom is the host to connect to once through the tunnel, bpp should probably be 8, 16 or 24 and geometry should look like 1024x768.
ssh -f -L 3389:mushroom:3389 bjn104@linuxproj.ecs.soton.ac.uk sleep 5; rdesktop -a bpp -g geometry localhost
from an faq linked in #winehq on freenode: go to the useful registry keys list on winehq and add the internet explorer ones using regedit. then run wineprefixcreate.
mount -t iso9660 isopath mountpoint -o loop
avimerge -o outfile -i infile infile
use nc:
echo -ne "GET /path/including/inital/slash.html HTTP/1.1\r\nHost: host\r\n\r\n" | nc host port
eg echo -ne "GET / HTTP/1.1\r\nHost: www.bnagel.net\r\n\r\n" | nc www.bnagel.net 80
use convert.
convert infile -resize widthxheight -quality 85 outfile
also look at mogrify, which i’ve used in the past. i don’t recall what the difference is. it could be that one resamples while the other does not. it could be that convert lets you specify an output file rather than replacing the input.
this code takes two images and puts them together side by side with no gaps:
convert desk_left.png desk_right.png +append wholedesk.png
-append would do it vertically
userdir.path = "public_html" and userdir.include-user = ( "tremby" ) (include-user means allow only these users – if you want to exclude only certain users, there’s exclude-user too)server.follow-symlink = "enable"chown :lighttpd -R /var/lib/php/sessionchkconfig lighttpd onservice lighttpd restarti was writing little bash scripts every time i wanted to do this, but there's a much better way.
rename "s/regexfrom/regexto/" files
use the n switch to test before making actual changes.
according to the manual, you can also pipe filenames to it, eg from find. haven’t tested this though.
note: i did this on Ubuntu and Debian. i’ve just tried on Fedora and there seems to be a completely different version there, which doesn’t take a s/from/to/ thing.
find . -type f -name "*~" -exec rm {} \;
find . -type f -name whatever -exec sed -i 's/regexfrom/regexto/' {} \;
careful. check the sed command on one file first.
for proper regexes, add the r switch to sed.
this sets up a tunnel to uni.
ssh -D 23456 bjn104@uglogin.ecs.soton.ac.uk
then set up whatever program to go through a proxy server (localhost) on that arbitrary port (23456).
awesome! this means if you want to log into a computer but don’t want to mess around with its network’s firewall, but you can run a command on that machine (tell someone to do it over the phone, or do it physically) you can still get to it.
this (run on otherbox) sets up a tunnel from perigee to otherbox:
ssh -nNT -R 2222:localhost:22 username@perigee.tremby.net
then on perigee username can run ssh -p 2222 username@localhost
it’s not in Ubuntu’s repo, so i found this command on linuxquestions.org:
echo string | tr 'a-zA-Z' 'n-za-mN-ZA-M'
or put it in a bash script:
#!/bin/bash echo $@ | tr 'a-zA-Z' 'n-za-mN-ZA-M'
and then run rot13 "fbzr grkg"
sshfs username@host:path mountpoint
and then to unmount, fusermount -u mountpoint
dd if=/dev/cdrom of=file.isoxset dpms force off – it comes back on with input like it usually would.
to force back on from the commandline, xset dpms force on
rotate 90 degrees clockwise (use 270 for ccw):
jpegtran -rotate 90 -outfile outfile infile
explorer ftp://username@server and click okwork in progress
mashed together from a howto, a post on the Ubuntu forums and my own experience.
STREAM=streamnum; DVDDEVICE=devicepath; VOBFILE=vobfile;
mplayer dvd://$STREAM -dvd-device $DVDDEVICE -dumpstream -dumpfile $VOBFILE
get chapter titles: STREAM=streamnum; DVDDEVICE=devicepath;
dvdxchap -t $STREAM $DVDDEVICE > chapters.txt and then edit them if necessary
check which audio and subtitle ids are which with STREAM=streamnum; DVDDEVICE=devicepath;
mplayer dvd://$STREAM -dvd-device $DVDDEVICE -v -vo null -ao null -frames 0 2>/dev/null </dev/null | grep "aid\|sid\|Found subtitle"
alternatively, use lsdvd, with the a switch for audio, s for subtitles or x for all, which includes title lengths. to convert its hex stream ids into decimal for AID (or SID+32), do echo "ibase=16; capitalhex" | bc
if they’re ambiguous (28 Days Later has two English subtitle tracks and two English audio tracks – one of each is commentary), test with mplayer: mplayer vobfile -sid sid and mplayer vobfile -aid aid
extract each subtitle required
VOBFILE=vobfile; SID=sid; SUBFILE=subtitlefilename;
tccat -i $VOBFILE | tcextract -x ps1 -t vob -a 0x`echo "obase=16; 32+$SID" | bc` > $SUBFILESUBFILE=subtitlefile;
mkdir ${SUBFILE}.images; cd ${SUBFILE}.images; subtitle2pgm -o ${SUBFILE}.i -c 255,255,255,0 < ../$SUBFILE (experiment to see which as 0 gives the centre part of the text – there seems to be no standard)SUBFILE=subtitlefilename;
pgm2txt ${SUBFILE}.iSUBFILE=subtitlefilename;
srttool -s -w < ${SUBFILE}.i.srtx > ../${SUBFILE}.srtget audio tracks
AC3 is lossily compressed, and Vorbis isn’t good at multichannel
VOBFILE=vobfile; AID=aid; AC3FILE=ac3file;
mplayer $VOBFILE -aid $AID -dumpaudio -dumpfile $AC3FILE -vc dummy -vo null
there is suspiciously little output, but it’s going.
a good idea for commentary tracks, which don’t need to be fantastic quality
VOBFILE=vobfile; AID=aid;
(tcscan -x pcm -i fifo | grep "suggested volume rescale") & mplayer $VOBFILE -aid $AID -ao pcm:nowaveheader:file=fifo -vo null -vc dummy -benchmark >/dev/null 2>&1VOBFILE=vobfile; AID=aid; VORBISQ=quality; VORBISOUT=oggfile; SCALEFACTOR=scalefactor;
oggenc -q $VORBISQ -o $VORBISOUT fifo & mplayer $VOBFILE -aid $AID -af volume=`echo "20*l($SCALEFACTOR)/l(10)" | bc -l` -ao pcm:file=fifo -vo null -vc dummy -benchmark >/dev/null 2>&1quite disgusting, but those two steps in one command: VOBFILE=vobfile; AID=aid; VORBISQ=quality; VORBISOUT=oggfile;
mkfifo fifo; (RESCALE=`tcscan -x pcm -i fifo | grep "suggested volume rescale" | sed -r "s/.*rescale=(.*)/\1/"`; echo "boosting ${RESCALE}dB"; oggenc -q $VORBISQ -o $VORBISOUT fifo & mplayer $VOBFILE -aid $AID -af volume=`echo "20*l($RESCALE)/l(10)" | bc -l` -ao pcm:file=fifo -vo null -vc dummy -benchmark >/dev/null 2>&1 </dev/null) & mplayer $VOBFILE -aid $AID -ao pcm:nowaveheader:file=fifo -vo null -vc dummy -benchmark >/dev/null 2>&1 </dev/null
the </dev/null bit towards the end lets mplayer wait patiently in the background – otherwise it and other interactive programs block until they are in the foreground. no good if it’s waiting for the other end of a pipe to open.
mplayer -vf cropdetect -sb 50000000 vobfile, navigate until all areas have been covered, then quit. see the last crop area output line. test it: mplayer vobfile -vf crop=cropsettingscheck if it’s interlaced (teeth wherever there’s movement), telecine (steady pattern of progressive and interlaced frames), progressive (each frame is complete) or some horrible mixture (check intro sequence, scene transitions and so on).
encode video. since i don’t care about the file size (i’m not into archiving to CDs and so there’s no point in having a 700M target size) i’m using x264’s constant quality mode, CRF. this also means only one pass is necessary, ensures quality and apparently gives results equal to two-pass average bitrate mode.
VOBFILE=vobfile; FRAMERATE=framerate; CROPSETTINGS=cropsettings; CRF=crfvalue; OUTFILE=outfile;
mencoder $VOBFILE -nosound -ofps $FRAMERATE -vf crop=$CROPSETTINGS -ovc x264 -x264encopts b_pyramid:weight_b:bframes=3:threads=auto:me=umh:trellis=1:mixed-refs:bime:b-rdo:subq=7:frameref=5:8x8dct:crf=$CRF -of rawvideo -o $OUTFILE
crfvalue is a scale from 0 (lossless) through 18 (pretty much transparent) through 24 (very decent) through 30 (pretty lossy) to 35 (crap) and beyond. 26 seems great.
for animation change frameref and bframes both to 16.
framerate is best using the fractional value rather than the decimal, for instance 24000/1001 instead of 23.976.
mmg and add all the files, chapters etc. add DVD cover titled “DVD cover” (not standard, but anything with “cover” is noticed by at least one shell extension). don’t forget to specify the framerate for the x264 file.this is probably quite obvious, but i hadn’t tried it until now. simply use the hashbang, so something like this:
#!/usr/bin/php
<?php
echo "here i am\n";
?>
reboot etc)if something must always run at boot/shutdown, make an init script for it. that will run as root, but you can use su to run as any given user.
head -n file | tail -1
-n is short for -n n.
add the following to the end of /etc/sudoers:
Cmnd_Alias SYSTEMPOWER = /sbin/poweroff, /sbin/reboot, /sbin/shutdown
%admin ALL = NOPASSWD: SYSTEMPOWER
i have missed these lovely things (the friendly blue smudge in the middle, particularly) since switching to Ubuntu.
someone has packaged them on kde-look (but they’re fine for any WM)
cuebreakpoints cuefile | shnsplit -o flac flacfilenetwork cards seem to forget that they're meant to wake on lan next time they boot, so they need reminding with a command like ethtool -s eth0 wol g
stick a script which runs that in /etc/init.d and then install the rc scripts with update-rc.d wakeonlanconfig start 20 2 3 4 5 . stop 80 0 1 6 .
mdf2iso file.mdfmplayer whatever -af pan=2:1:0:1:0
the 2 is the number of output channels (probably always 2), then the next arguments are proportion of the each input channel to each output channel:
iL→oL:iL→oR:iR→oL:iR→oR
the above command will pan it hard left.
gconf-editor/apps/metacity/generalsudo ifconfig device hw class address
class is most likely ether. network interface can’t be in use when this is run – disable networking first (harmless error otherwise).
this is not permanent – it’ll have to be repeated after a reboot/suspend.
use xclip. its default action is to copy from stdin or a file if a filename is given. pass -o to paste to stdout.
by default, the “x selection” register is used, which is set whenever you select something and can be pasted with a middle click. this is not the same as the clipboard (control-c/v, control/shift-insert) – to use that pass -selection clipboard.
use the X keyboard option ctrl:nocaps, for instance setxkbmap gb dvorak compose:ralt ctrl:nocaps
xmodmap -e "remove control = Control_R"
xmodmap -e "add mod4 = Control_R"
the two expressions can instead go in a file, for instance .xmodmaprc, and loaded with xmodmap .xmodmaprc from elsewhere, like .xinitrc
Pick the first 64 hex characters out of random data:
cat /dev/urandom | tr -dc '0-9a-f' | head -c 64
My sprunge script:
#!/bin/bash url=$(curl -F 'sprunge=<-' -H "Expect: " http://sprunge.us 2>/dev/null) if [ $? -ne 0 ]; then echo "request failed" exit 1 fi if [ $# -gt 0 ]; then url="$url?$1" fi echo $url if [ $DISPLAY ]; then which xclip >/dev/null 2>/dev/null if [ $? -eq 0 ]; then echo -n $url | xclip fi fi
The -H "Expect: " gets around a problem with sending the request through the Squid proxy. Not sure if that's a bug in Squid or what.