Linux recipes
networking
configuration
apt install resolvconf
vi /etc/network/interfaces
address, netmask, network, broadcast, gateway, dns-nameservers
wireless-essid, wireless-key s:
network card buffer overflows
# set noapic in boot options
install wpa
# edit /etc/udev/rules.d/70-persistent-net.rules to set interface name to wlan0
apt install wpasupplicant
wpa_passphrase ssid >>/etc/wpa_supplicant/wpa_supplicant.conf
vi /etc/network/interfaces
auto wlan0
iface wlan0 inet dhcp
wpa-driver wext
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
# install 2.6.30 kernel
# install agere firmware see http://wiki.debian.org/orinoco into /lib/firmware
ifup wlan0
apt install wireless-tools
iwlist wlan0 scan
bridge two interfaces
apt install bridge-utils
vi /etc/network/interfaces
auto br0
iface eth0 inet manual
iface eth1 inet manual
iface br0 inet dhcp
bridge_ports eth0 eth1
bridge tap into network
vi /etc/network/interfaces
# setup bridge
iface br0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
bridge_ports eth0 tap0
# change eth0 to manual
iface eth0 inet manual
# setup tap
iface tap0 inet static
pre-up tunctl -u user -t tap0
post-down tunctl -d tap0
address 192.168.2.1
netmask 255.255.255.0
# ensure tap created before bridge
auto tap0 br0
internet sharing
# host
iptables -A FORWARD -i lan -o wan -j ACCEPT
iptables -A FORWARD -i wan -o lan -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o wan -j MASQUERADE
# client
route add default gw ip lan
file sharing from Windows
apt install smbfs
apt install cifs-utils
smbclient -U user -L ip-address
mkdir tmp
smbmount //ip-address/x tmp -o user=user
mount -t cifs -o username=user -o domain=host //host/user mountpoint
remote access via ssh
apt install ssh # secure shell
scp . server:~
ssh-keygen # setup RSA login key
scp *.pub server:.ssh
cat *.pub >>authorized_keys # on server
vi /etc/ssh/sshd_config
set X11Forwarding yes
vi /etc/ssh/ssh_config
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
/etc/init.d/ssh restart
ssh -X $REMOTE
ssh -L 2022:client2:22 server; ssh -X -p 2022 localhost # port forward to second client
reducing ssh brute force attempts
vi /etc/ssh/sshd_config.d/disable_root_login.conf
PermitRootLogin no
vi /etc/ssh/sshd_config.d/disable_password_login.conf
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
apt install fail2ban
vi /etc/fail2ban/jail.conf # edit jail conditions
fail2ban-client status sshd # shows status
socks proxy via ssh
ssh -N -D 1080 server
# set SOCKS proxy in browser
127.0.0.1:1080
remote backups
apt_get install rsync
rsync /src /dst -a --del
rsync /src server:/dst -az --del -e ssh
rsync using remote fakeroot
# mount dst with user_xattr set in fstab
rsync -a --del /src backup@server:/dst --rsync-path='rsync --fake-super' -e 'ssh -i /home/backup/.ssh/id_rsa'
VPN tunnel via PPTP
vi /etc/ppp/chap-secrets
username PPTP password *
vi /etc/ppp/peers/tunnel
pty "pptp server --nolaunchpppd"
name username
remotename PPTP
file /etc/ppp/options.pptp
ipparam tunnel
require-mppe-128
vi /etc/ppp/ip-up.d/tunnel
#!/bin/sh
if [ "$PPP_IPPARAM" = "tunnel" ]; then
route add -net 192.168.subnet.0/24 dev $IFNAME
fi
chmod +x /etc/ppp/ip-up.d/tunnel
pon tunnel
poff tunnel
VPN through openvpn
apt install openvpn
cp *.crt *.key .openvpn
chmod 400 .openvpn
vi /etc/default/openvpn
AUTOSTART=NONE
vi .openvpn/client.conf
remote vpn-server 1194
ca ca.crt
cert cert.crt
key key.key
tls-auth ta.key 1
cipher AES-256-CBC
su openvpn client.conf
modem
cd /usr/src
wget http://linmodems.technion.ac.il/packages/ltmodem/kernel-2.6/ltmodem-2.6-alk-8.tar.bz2
bzip -d *.bz2
tar xf *.tar
cd ltmodemX
make
mknod --mode=0660 /dev/ttyLT0 c 62 64
chown :dialout /dev/ttyLT0
ln /dev/ttyLT0 /dev/modem
mkdir /lib/modules/2.6.8-X/kernel/drivers/modem
cp /usr/src/ltmodem*/lt*.ko /lib/modules/2.6.8*/kernel/drivers/modem
depmod -a
vi /etc/modprobe.d/aliases
alias char-major-62 ltserial
alias ttyLT0 ltserial
alias modem ltserial
modprobe ltserial
pppconfig
phone_number
dhcp
username, password
pon
voip
apt install kphone
# no stun, though can use stun.wirlab.net:3478
# xxxxxx@freephone.engin.com.au
# prefer codec iLBC, then G711a
apt install ekiga
# need to route ports SIP 5060, RTP 8000
skype
vi /etc/apt/sources.list
dep http://download.skype.com/linux/repos/debian/ stable non-free
apt install skype
LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype
remote desktop
apt install rdesktop
rdesktop 192.168.X.X
-f # sets window full screen
-r disk:directory=/home/user/directory # shares client directory
-g 1024x768 -g 1280x800
ctrl-alt-enter # turn off full screen
restart network
/etc/init.d/networking restart
accessing local network client names under NT domains
apt install winbind
vi /etc/nsswitch.conf
# add wins to hosts
reverse ssh
crontab -e
if ! ps -C autossh >/dev/null; then [autossh]; fi
autossh -f -p 10022 -R 10022:localhost:22 client -fN # from server
ssh -p 10022 localhost # from client
DNS for dynamic IP
# setup at www.dyndns.org
apt install inadyn
vi /etc/inadyn.conf
update_period_sec 600
username user
password password
dyndns_system dyndns@dyndns.org
alias name
iterations 1
chmod 600 /etc/inadyn.conf
crontab -e
0 0 * * * /usr/sbin/inadyn
securing ports
apt remove nfs-common rpcbind
vi /etc/inetd.conf
# comment out ident line
/etc/init.d/openbsd-inetd restart
pcmcia bus for Xircom network card
pccardctl info
ifdown eth0
pccardctl eject
rmmod xirc2ps_cs
modprobe xirc2ps_cs
pccardctl insert
ifup eth0
controlling multiple interfaces
route add X0.X1.X2.X3 eth0
route add 192.168.2.1 wlan0
route add 192.168.2.2 wlan1
iptables -t nat -A OUTPUT -d 192.168.2.1 -j DNAT --to X0.X1.X2.X3 -o wlan0
iptables -t nat -A OUTPUT -d 192.168.2.2 -j DNAT --to X0.X1.X2.X3 -o wlan1
network scanning
nc -zvv ip port # check for TCP listener
nmap -sn net/24 # ping scan
nmap ip # tcp port scan
traceroute -m hops ip # trace hops to destination
lsof | grep TCP # list TCP port connections
spoof MAC
ifdown eth0
ifconfig eth0 hw ether mac-address
ifup eth0
guessnet automatic network settings
apt install guessnet
vi /etc/network/interfaces
mapping eth0
script guessnet-ifupdown
map default: default
map timeout: 10
map verbose: true
map autofilter: true
iface eth0-home inet static
test peer address router-ip mac router-mac source own-ip
# network settings
iface default inet dhcp
change interface names
vi /etc/udev/rules.d/70-persistent-net.rules
override domain name servers
vi /etc/dhcp/dhclient.conf
supersede domain-name-servers 8.8.8.8, 8.8.4.4; # google DNS
list network interfaces
ip -br addr show
lshw -short -class network
show DNS records
dig -t ANY example.org
wireshark
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
wireshark
set full hostname of local machine
vi /etc/hostname
hostname
vi /etc/hosts
127.0.0.1 hostname.domain hostname localhost
/etc/init.d/hostname.sh
hostname --fqdn
# alternative
hostnamectl set-hostname hostname.domain
hostname
regenerate default SSL certificates
make-ssl-cert generate-default-snakeoil --force-overwrite
SSL certification (startssl.com)
# validate domain
openssl genrsa -aes256 -out domain.key 2048 # create key
openssl req -new -key domain.key -out domain.csr # create request
# submit request and save certificate
# allow time for certificate to reach servers
# copy to server
openssl rsa -in domain.key -out /etc/ssl/private/domain.key # decrypt key
wget http://www.startssl.com/certs/sub.class1.server.ca.pem
cat domain.crt sub.class1.server.ca.pem >/etc/ssl/certs/startcom-domain-unified.crt
SSL certification (certbot through letsencrypt.org)
# initial certificate
git clone https://github.com/letsencrypt/letsencrypt # mainline
apt install python-certbot # or repository
# manual renewal
certbot-auto certonly --manual -d domain -d *.domain
# make challenge available at DNS TXT _acme-challenge.domain
# make challenge available at http://domain/.well-known/acme-challenge
# nginx certs
vi /etc/nginx/sites-available/default
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain/privkey.pem;
service nginx restart
# gitlab certs (note that gitlab now have inbuild certbot functionality)
settings->pages->domains->Edit
@ turn off https forced if key has to be removed and added
@ update fullchain and privkey
# prosody certs
prosodyctl --root cert import /etc/letsencrypt/live
# non-interactive renewal (only for apache)
certbot-auto renew
wifi network QR code
apt install qrencode
qrencode -o qrcode.png "WIFI:S:ssid;T:WPA;P:password;;"
qrencode -o qrcode.png "otpauth://totp/issuer:account&issuer=issuer
internet
replace mail transfer agent exim4 with smaller esmtp
apt --purge install esmtp-run # removes exim4 daemon
set fully qualified hostname
vi .esmtprc
hostname=smtp.gmail.com:587
username="user@domain"
password="password"
starttls=required
# add CNAME for sending machine in DNS records
sending mail with telnet
telnet mail.iinet.net.au 25
HELO iinet.net.au
MAIL FROM: email
RCPT TO: email
DATA
SUBJECT: test
# blank line
test
.
QUIT
install firefox
apt install iceweasel mozplugger
install opera
vi /etc/apt/sources.list
deb http://deb.opera.com/opera/ stable non-free
wget -O - http://deb.opera.com/archive.key | apt-key add -
apt install opera
remove tab bar
history->memory cache=5Mb
browsing->redraw after 5s
browsing->no icons
User Prefs->Turbo Mode=0
instant messaging
apt install pidgin pidgin-otr
multimedia browser plugins
apt install flashplayer-mozilla mozilla-mplayer
add to opera plugins
update-flashplugin-nonfree --install
# OR
# download flash_player_npapi_linux.x86_64.tar.gz
tar -xzf flash_player_npapi_linux.x86_64.tar.gz
mv libflashplayer.so /usr/lib/mozilla/plugins/
install peer to peer
apt install mldonkey-server mldonkey-gui # edonkey
apt install gtk-gnutella # gnutella/limewire
apt install transmission-gtk
unpacking mail file
apt install munpack
# put into export filter
# export to mbox file
munpack file.mbx
GPG privacy
apt install gpgkeys seahorse
gpg --gen-key # generate key pair
gpg --send-keys --keyserver pgp.mit.edu key_id # upload public key
gpg --recv-keys --keyserver pgp.mit.edu key_id # download public key
gpg --fingerprint key_id # check a fingerprint
gpg --sign-key key_id # sign a key
gpg -ea -r email # encoding
gpg -d test.file.asc # decoding
gpg --clearsign # sign a text file
gpg --verify # verify a signature
gpg --edit-key email # edit key trust
trust
gpg --list-keys
GPG party sign using caff
apt install signing-party
caff -E -m yes keyid # mail back signed keys
# select uids
# check fingerprint
showphoto # check photo
sign # sign level 2
quit # quit and send mail
GPG party import
# save all signature.asc
gpg --import *.asc
gpg --keyserver pool.sks-keyservers.net --send-keys key_id # update own key to server
GPG key removal
gpg --export-secret-key --export-options export-minimal --armor key_id
gpg --delete-secret-keys key_id
gpg --delete-key key_id
GPG published over DNS
gpg --list-keys --fingerprint key_id # get the fingerprint
gpg --export --armor key_id >key_id.pub.asc # get the key
# add a DNS TXT record
user._pka TXT "v=pka1;fpr=key_fingerprint;uri=https://domain/key_id.pub.asc"
# test for the record
dig +short user._pka.domain TXT
# test with GPG
echo 'test' | gpg --no-default-keyring --keyring /tmp/gpg-$$ --encrypt --armor --auto-key-locate pka -r email | gpg
GPG symmetric file encryption/decryption
gpg --symmetric file
gpg --decrypt file.gpg >file
web site ftp upload transfer
apt install sitecopy
mkdir -m 700 .sitecopy
touch .sitecopyrc
chmod 600 .sitecopyrc
vi .sitecopyrc
site sitename
server servername
remote remoteroot
local localroot
username username
sitecopy --init sitename # to initialize indexing
sitecopy -o --update sitename # to update site
web site mirror
wget -x --save-cookies cookies.txt --keep-session-cookies --post-data "p=blah&submit=login" login.php
wget --load-cookies cookies.txt -mk -w 5 sitename
command line emailing
echo '<html>' >messagefile
echo '<h1>initial message</h1>' >>messagefile
sed -e 's/$/<br>/' logfile >>messagefile
echo '</html>' >>messagefile
cat messagefile | mail -s 'log file' -a 'Content-type: text/html' recipient@mail.org
dns records for google hosted
CNAME calendar,docs,www,user,mail ghs.google.com
A @ 72.14.203.121
MX @ aspmx.l.google.com,alt1.aspmx.l.google.com,alt2.aspmx.l.google.com,aspmx2.googlemail.com,aspmx3.googlemail.com
SPF @ v=spf1 include:_spf.google.com ~all
# mail check-auth@verifier.port25.com to check spf/dkim
fidonet
wget http://techtinkering.com/downloads/ansifonts.tar.gz
tar xvzf ansifonts.tar.gz; mv vga11x19.pcf /usr/share/fonts/X11/misc
mkfontdir /usr/share/fonts/X11/misc/
xset fp rehash
rxvt -fn vga11x19 -bg black -fg white
telnet theshackbbs.pepe.net.au
power management
acpi management
apt install lm-sensors
sensors-detect # install sensor modules
sensors # check temperature
acpitool -s # sleep
acpitool -T # shows toshiba values
acpitool -l 7 # sets LCD brightness
# setup /etc/acpi/events, /etc/acpi/actions for ac adapter and power button
apt install vbetool
vbetool dpms off # turn off LCD backlight, not sure how to automate
# comment out DPMS from xorg.conf
setting up UPS 3105
apt install nut
vi /etc/nut/ups.conf
# pw3105
driver = bcmxcp_usb
port = auto
upsdrvctl start
vi /etc/nut/upsd.conf
ACL all 0.0.0.0/0
ACL localhost 127.0.0.1/32
ACCEPT localhost
REJECT all
vi /etc/nut/upsd.users
# nut
password = password
allowfrom = localhost
upsmon master
vi /etc/nut/upsmon.conf
POWERDOWNFLAG /etc/killpower
MONITOR pw3105@localhost 1 nut password master
SHUTDOWNCMD "/sbin/shutdown -h +0"
chown nut:nut /etc/nut/*
chmod 640 /etc/nut/upsd.users /etc/nut/upsmon.conf
upsd
upsc pw3105@localhost ups.status # check status
upsmon
vi /etc/default/nut
START_UPSD=yes
START_UPSMON=yes
apt install wmnut
wmnut -w
power saving
powertop
echo 1500 >/proc/sys/vm/dirty_writeback_centisecs
fix powersave logging
vi /etc/acpi/events/ac /etc/acpi/events/battery
action=/etc/acpi/power.sh %e # pass a parameter to power.sh
display
check 3D access
apt install mesa-utils
glxinfo
legacy nvidia graphics card
apt install nvidia-glx-legacy-173xx nvidia-xconfig
apt install nvidia-glx-legacy-96xx nvidia-xconfig
nvidia-xconfig --no-composite
ATI graphics dual head
# add to Device section of /etc/X11/xorg.conf
Option "MergedFB" "true"
Option "CRT2Position" "Below"
Option "MergedXineramaCRT2IsScreen0" "true"
Option "SWCursor" "true"
# or duplicate Device, Monitor, Screen section of /etc/X11/xorg.conf, and in ServerLayout
Screen 0 "0 screen"
Screen 1 "1 screen" Below "0 screen"
Option "Xinerama" "true"
ATI fglrx driver
apt install linux-headers-3.2
apt -t wheezy-backports install fglrx-legacy-driver
aticonfig --initial=dual-head --xinerama=on
change screen resolution
dpkg-reconfigure xserver-xorg # sets up dummy xorg.conf
# add monitor frequencies to the monitor section
HorizSync 31.5-64.3 # Sony Vaio PCG-SRX77
VertRefresh 50.0-70.0 # Sony Vaio PCG-SRX77
HorizSync 42.0-52.0
VertRefresh 55.0-65.0
# add in display mode to the screen section
Subsection "Display"
Modes "1024x768"
EndSubsection
disable faulty radeon graphics modeset on boot
vi /etc/default/grub
# add nomodeset or radeon.modeset=0
disable svideo for intel vblank wait timed out
vi /etc/default/grub
kernel ... video=SVIDEO-1:d
display changes
xrandr --query # list displays
xrandr --output displays --mode widthxheight
xset q # query settings
xset s off # disable blank time
xset -dpms # disable dpms
xrandr --output display --panning widthxheight # change screen area
xrandr --output display1 --auto --output display2 --auto --right-of display1
xwindows, desktop
install xwindows
apt install xorg
# Portege] PCI:0:4:0 /dev/psaux
# Athlon] PCI:1:0:0 PCI:1:0:1 1280x1024 hsync:30-69 vsync:59-85
reconfigure xorg
dpkg-reconfigure xserver-xorg
dexconf
ctrl-alt-backspace
fluxbox desktop
apt install fluxbox
desktop style MerleyKay
toolbar 100% autohide maximize_over
slit autohide maximize_over
.fluxbox/init strftimeFormat: %k:%M %d/%m/%y
.fluxbox/init # point to local keys file
.fluxbox/keys Mod4 m :RootMenu
.fluxbox/startup # holds wm apps
.fluxbox/slitlist # remembers order of wm apps
share keyboard and mouse between computers
apt install synergy
# on server
# edit .synergy.conf
section: screens
host1:
host2:
end
section: links
host1:
up = host2
host2:
down = host1
end
section: options
switchDoubleTap = 500
end
# server start
synergys
# client start
ssh host2
ssh -f -N -L 24800:host1:24800 host1
synergyc localhost
authorize xwindows access
xhost +$REMOTE # or use xauth or use sux
monitoring applications in the slit
apt install wmcpu wmnet wmbutton
vi .fluxbox/startup
wmcpu &; wmnet -w &; wmbutton &; fluxbox
send X output to null
Xvfb :99 -screen 0 1x1x8 &
DISPLAY=:99 application &
math applications
apt install galculator # scientific calculator
apt install octave octplot # equation evaluation
# octave
loading data files
load a.out # data in a
plotting
plot(a)
fft
fa = fft(a)
antivirus
sudo freshclam # update virus list
clamscan file # virus scan
rm /etc/cron.d/clamav-freshclam
create menu entry
vi /usr/share/menu/app # standard desktop
update-menus
vi /usr/share/applications/app.desktop # for gnome
hide dotfiles in file dialog
ctrl-H
play a video on the desktop background
mplayer -rootwin -nosound -loop 0 -vf scale=1280 video.avi
selection pasting to xterm
vi ~/.Xdefaults
xterm*selectToClipboard: true
xrdb -merge ~/.Xdefaults
force hires 1024x768 on startup on Toshiba 3500
vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="vga=791 quiet"
GRUB_GFXMODE=1024x768
update-grub
fingerprint reader
apt install fprintd libpam-fprintd
fprintd-enroll username -f finger
text manipulation
editors and readers
apt install vim-gtk
apt install leafpad abiword abiword-help abiword-plugins # notepad, document editor
apt install acroread xpdf-reader flpsed pdftk # pdf reader, annotation
apt install xournal # edits pdfs
apt install wordnet # dictionary/thesaurus
apt install xchm # compressed html reader
apt install openoffice.org myspell-en-au
ereader formatting
# use firefox
about:config
unwriteable-margin-bottom = 110
letter paper
size 150%
ignore scaling
headers and footers off
set default editor to vi
ln -sf /usr/bin/vi /etc/alternatives/editor
strip carriage returns from file
tr out.txt
edit hex in vim
vim -b file.bin
:%!xxd
:%!xxd -r
digraphs in vim
:digraphs
ctrl-k a :
deleting empty lines in vim
:g/^$/d
sort lines in vim
:sort
:sort u # unique lines
generate random string for password
openssl rand -hex 8
manipulate pdf pages
pdftk in0.pdf in1.pdf output out.pdf # join
pdftk in.pdf cat 1-10 output out.pdf # select pages
pdftk in.pdf input_pw password output out.pdf # decrypt
games
games
apt install lmemory # memory
apt install Xjig # jigsaw
apt install gnugo gnuchess # go, chess
apt install nethack # hack
apt install sabre # flight simulator
apt install supertuxkart # kart racer
apt install planetpenguin-racer # skiing
apt install gltron # Tron lightcycles
apt install frozen-bubble # tetris style
apt install pingus # lemmings
apt install neverball neverputt # rolling ball
apt install wesnoth # board strategy
apt install codebreaker # mastermind
apt install pioneers-server pioneers-client # Settlers
installing windows game
# copy game to /usr/local/games
# create desktop link in /usr/share/applications
# create an xpm icon in /usr/share/pixmaps
apt install icotools
wrestool -l game.exe | grep icon
wrestool -x -n MAINICON game.exe >game.ico
gimp game.ico # save as xpm
bitcoin
# transaction flow
# wallet -> broadcast to mempool -> confirm to blockchain
apt install snapd
snap install bitcoin-core
# files in ~/snap/bitcoin-core/common/
bitcoin-core.daemon # start server
bitcoin-core.cli getblockcount
bitcoin_core.cli createwallet folder
# load wallet into running server
bitcoin_core.cli loadwallet filename
# get wallet information
bitcoin-core.cli -rpcwallet=folder getwalletinfo
bitcoin_core.cli -rpcwallet=folder getnewaddress name
# send money
bitcoin-core.cli -rpcwallet=folder settxfee amount # BTC/1kB eg 0.00005 = 5 satoshis/byte
firefox https://www.blockchain.com/charts/mempool-state-by-fee-level # queue statistics
bitcoin-core.cli sendtoaddress address amount # make payment
# rebroadcast transaction to mempool
# blocksonly=1 prevents broadcast
bitcoin-core.cli getrawtransaction transaction-id
bitcoin-core.cli sendrawtransaction raw-transaction-data
# unload wallet
bitcoin_core.cli unloadwallet wallet_name
audiovisual multimedia
mixer
apt install pavucontrol
test speakers
aplay -L
speaker-test -c2 -t wav
check pulseaudio configuration
pactl list short sources
pactl list short sinks
pactl set-default-sink 'sink'
access patent encumbered repositories
vi /etc/apt/sources.list
deb http://www.deb-multimedia.org/ stable main
multimedia applications
apt install mpg123 audacious
apt install vsound realplayer
apt install vlc
apt install audacity liblame0 mp3splt-gtk
# configure libmp3lame.so.0
apt install ripperx # CD ripper
apt install xdvdshrink # DVD ripper and burner
apt install libav-tools
convert midi to mp3
apt install timidity fluid-soundfont-gm
apt install lame
timidity file.mid -Ow -o - | lame - -b 64 file.mp3
view image and video metadata
exiftool file.ext
avconv
ffprobe -i input.mpg # view streams
avconv -i input.ext -codec copy output.mp4 # convert to mp4
avconv -i input.ext -c:v libx264 -strict experimental output.mp4 # convert to x264
avconv # cut video
-i input.mp4
-ss hh:mm:ss # start
-t hh:mm:ss # length
-codec copy
output.mp4
select audio/video streams from flv
mplayer -dumpaudio movie.flv -dumpfile movie.mp3
avconv -i in.flv -map 0:0 -c:v copy out.mp4 # select video
avconv -i in.flv -map 0:1 -c:a copy out.aac # select audio
avconv -i in.flac -acodec libmp3lame -aq 2 out.mp3
combine audio back in
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a wma -map 0:v:0 -map 1:a:0 out.wmv
working with DVDs
mpegdemux -d -s 0xe0 src.vob dst.m1v # ripping video from DVD vob
mpegdemux -d -s 0xbd -p 0x80 --ac3 src.vob dst.ac3 # ripping sound from DVD vob
ffmpeg -i src.mpg -async 1 -target pal-dvd dst.vob # create vob file from avi source
ffmpeg -i src.vob -async 1 -target pal-dvd -map 0.0 -map 0.1 -b 5400000 -ab 448000 dst.vob # create vob file from avi source with parameters
mplex -f 8 -o dst.vob src.m1v src.ac3 # multiplexing to vob
# vlc to mpeg transport to capture DVD
dvdauthor -x src.xml
<dvdauthor dest="DVD">
<vmgm />
<titleset>
<titles>
<pgc>
<vob file="movie.vob" chapters="0:00,10:00" />
</pgc>
</titles>
</titleset>
</dvdauthor>
rip svcd
apt install vcdimager
vcdxrip
rip dvd
apt install dvdbackup libdvdcss2 genisoimage
dvdbackup -M -i /dev/sr0
genisoimage -dvd-video -o movie.iso folder
reencoding video
apt install mencoder w32codecs
ln -s /usr/share/fonts/truetype/freefont/FreeSerif.ttf /usr/share/mplayer/subfont.ttf
mencoder input.flv -ovc xvid -xvidencopts pass=2:bitrate=1150 -oac mp3lame -of avi -o output.avi # encoding for video player
mencoder input.mp4 -ovc -vf scale=960:540 -ofps 30000/1001 xvid -xvidencopts bitrate=3000 -oac mp3lame -o output.avi # encoding for Sprint
ffmpeg -i input.avi -b 1150k -s 320x240 -vcodec mpeg4 -r 30000/1001 output.avi # encoding for youtube
# mencoder options
-vf scale=width:height
-ovc lavc -lavcopts vcodec=mpeg4:vbitrate=2160000
-nosound
-ffourcc DX50
-quiet
editing video
apt install openshot
# encoding for xvid
avi
libxvid, 3 Mb/s
libmp3lame, 44100 Hz, 2 channel, 192 kb/s
vi /usr/shared/pyshared/...
# set progressive scanning if interleaved
capturing screen video
xwininfo
./slowdown.out # approximately 10 times
recordmydesktop --full-shots --no-sound --windowid 0x00000000 --v_bitrate 1150000 --fps 3
play video at different frame rate
mplayer -fps 30 video.ogv
identify DVD type
dvd+rw-mediainfo /dev/dvd
burn DVD
dvd+rw-format /dev/dvdrw # for rewritables
growisofs -Z /dev/dvdrw -r -J $folder
record streaming files
mplayer $2 -ao pcm:file=$1.pcm
lame -m m -b 32 $1.pcm `date +%Y%m%d`$1.mp3
rm $1.pcm
record streaming files
mplayer $1 -dumpstream -dumpfile $2.rm
convert mp3 to wav
mpg321 src.mp3 -w dst.wav
convert audio to ogg
find . -name \*.m4a -exec sh recode.sh "{}" \;
vlc -I dummy "$1" --sout="#transcode{acodec=vorb,ab=256}:standard{access=file,mux=ogg,dst="\""$1.ogg"\""}" vlc:quit
video streaming
gstreamer-properties # to set stream properties
gqcam # to view camera
ln /dev/video0 /dev/video # for applications that use /dev/video
apt install stopmotion vgrabbj # stop motion animation
video streaming over network
vlc --vlm-conf test.vlm --ttl 12 -I http --http-src /usr/share/vlc/http --http-host :8080 --rtsp-host :5554 # server
vlc rtsp://ip_address:5554/test # client
iceweasel http://ip_address:8080/vlm.hml # interface
# vod command
new test vod enabled input "test.avi"
downloading iview
apt install python3 python3-gi bzr python-beautifulsoup libssl-dev python-simplejson
# install rtmpdump from rtmpdump.mplayerhq.hu
bzr branch https+urllib://jeremy.visser.name/bzr/python-iview/ python-iview
# compile rtmpdump
PATH=$PATH:path_to_rtmpdump ./iview-gtk
downloading BBC
apt install get-iplayer
get-iplayer # get list of programs
get-iplayer --get number --output ~/ --partial-proxy http://194.28.8.139:3128
running jack, showing oscilloscope of playing sound
apt install jackd1
jackd
alsaplayer -o jack file.ogg
jack.scope -s
vi .jack.plumbing
(connect "alsaplayer-[0-9]*:out_1" "jack\.scope-[0-9]*:in_1")
jack.plumbing
random generation from sound
apt install randomsound
rotate video
mencoder -vf rotate=1,mirror -ovc lavc -oac copy input.avi -o output.avi
ffmpeg -i input.avi -vf transpose=1 -target pal-dvd output.vob
reduce video size
ffmpeg -i input.avi scale=-1:720 -c:a copy output.mp4
replace mp3 id3 tags with filename
find *.mp3 -exec sh -c 'id3v2 -t $(basename {} .mp3) {}' \;
IR controller
apt install lirc
mode2 --driver devinput --list-devices # list available devices
mode2 --driver default --device /dev/lirc0
irrecord -d /dev/lirc0
apt install ir-keytable
ir-keytable -t -d /dev/input/eventX
graphics
graphics packages
apt install gqview libjpeg-progs gthumb
apt install gimp gimp-help-en gimp-helpbrowser gimp-print
apt install scribus scribus-template # publishing
apt install openclipart-png openclipart-svg
apt install dia # diagramming editor
apt install inkscape python-xml # svg editor
scanning
apt install sane sane-utils
adduser user scanner
# snapscan
# add u176v042.bin from driver disk to /usr/share/sane/snapscan
# set firmware line in /etc/sane.d/snapscan.conf
# epson
# use epkowa
vi .sane/xscanimage/epkowa:libusb:XXX:XXX.rc # to edit resolution
sane-find-scanner # find scanner device
scanimage -L # check for access to scanner
xscanimage # scan a page
capture camera
mplayer -fps 1 -speed 0.1 -frames 10 -tv driver=v4l2 -vo jpeg tv://
batch scanning
scanimage --help
scanimage -d epson2 --wait-for-button=yes --batch=%.4d.pnm --mode Gray --depth 8 --resolution 150 -x 210 -y 297 --batch-start=1
find . -name '*.pnm' -exec sh -c 'convert -quality 90 -normalize {} $(basename {} .pnm).jpg' \;
convert -density 150x150 *.jpg dst.pdf
convert -crop xsizexysize+xoffset+yoffset -resize xsizexysize input.jpg output.jpg
find . -name '*.JPG' -exec sh -c 'convert -resize 50% -quality 90 {} $(basename {} .JPG).jpg' \;
image processing
convert in.nef -crop wxh+x+y -colorspace Gray -level lower%,upper% -sharpen 0x1.0 out.jpg
screen snapshot
xwininfo
import -window id snapshot.jpg
panorama images
# convert to 2:1 aspect ratio
exiftool -ProjectionType="equirectangular" -Make="RICO" -Model="RICO THETA S" filename.jpg
image metadata
exiftool -artist="name" -P -overwrite_original -m img.jpg
animated gif
mogrify -crop widthxheight+xoffset+yoffset +repage *.png
convert -layers OptimizeFrame -delay 10 *.png -loop 0 filename.gif
image stacking
avconv -i input.avi -r 30 -f image2 %04d.tif # video to images
align_image_stack -a prefix -i -C *.tif # align images
enfuse -o output.tif *.png # stack images
acecad tablet device
apt install xserver-xorg-input-acecad
# add lines to /etc/X11/xorg.conf
Section "InputDevice"
Identifier "Tablet"
Driver "acecad"
Option "Device" "autodev"
Option "Mode" "absolute"
EndSection
Section "ServerLayout"
InputDevice "Tablet"
EndSection
# restart X
# check log in /var/log/Xorg.0.log
# setup in gimp->file->preferences->input devices
gimp plugins
apt install libgimp2.0-dev
extract images from pdf files and join together
pdfimages -j file.pdf "prefix"
convert in.pbm out.png
convert -rotate 90 in.png out.png
convert -crop 2000x1500+100+100 in.png out.png
convert -density 200x200 in.png out.png
convert *.png out.pdf
montage of images
montage -tile 2x4 -geometry 500x500 -background none inputimages output.jpg # proof sheet
montage -geometry +0+0 inputimages output.jpg # retain resolution
increase image magick memory
sudo vi /etc/ImageMagick-6/policy.xml
# set memory resource size
plotting
apt install gnuplot
gnuplot
plot "input.dat" using 0:1 with lines, "input.dat" using 0:2 with lines # plot comparative traces
download flash videos (youtube, vimeo)
# open in player
lsof +L1 | grep Flash
cp /proc/pid/fd/fd video.mp4 # copy at end
tail -c +0 -f /proc/pid/fd/fd >video.mp4 # copy while running
fix opengl hang with blank window
vblank_mode=0 app
vi /etc/drirc
<driconf>
<device>
<application name="all">
<option name="vblank_mode" value="0"/>
</device>
</driconf>
# OR
vi /etc/default/grub
pci=nomsi
update-grub
access digital camera
gphoto2 --auto-detect
gphoto2 --list-files
gphoto2 --no-keep --get-all-files
gphoto2 --capture-image
gphoto2 --set-config datetime=now
streaming camera to html5
apt install gstreamer1.0-tools
gst-launch-1.0 v4l2src device=/dev/video0 ! videoconvert ! theoraenc quality=4 ! oggmux ! tcpserversink host=ip-address port=port
test.html
<html>
<body>
<video width="100%" autoplay>
<source src="http://ip-address:port/" type="video/ogg">
</body>
</html>
create timelapse
cat files.jpg | avconv -f image2pipe -c:v mjpeg -i - -r 25 -map 0 file.mp4
languages and fonts
international fonts
apt install ttf-gentium ttf-sil-charis ttf-sil-doulos
locales
dpkg-reconfigure locales
sorting
/etc/default/locale
LC_ALL=en_AU.utf8
arabic support
reconfigure xserver # lenny
layout "us,ar"
options "grp:caps_toggle,grp_led:caps"
vi /etc/default/keyboard # squeeze
XKBLAYOUT="us,ar"
XKBOPTIONS="grp:caps_toggle"
# keymap in /usr/share/X11/xkb/symbols
# Scheherezade and Lateef fonts from SIL
# install in /usr/share/fonts/truetype
apt install libft-perl
defoma-hints -c --no-question truetype font.ttf >font.hints
defoma-font register-all font.hints
japanese support
apt install scim-anthy
im-switch -c # set scim via scim-bridge
# restart X session
# use ctrl-space to switch
inserting unicode
ctrl-shift-u ctrl-shift- # hold down ctrl-shift
ctrl-V u hexcode # in vim
install latex xetex
apt install texlive arabtex texlive-xetex texlive-omega texlive-latex-extra lmodern
# if no access to xetex fmt
fmtutil --enablefmt xetex # fixes access to xetex fmt
fmtutil --enablefmt xelatex
latex test.tex
xdvi test
dvips -o test.ps test
xetex test.tex
xpdf test
add latex sty
mkdir /usr/share/texmf/tex/latex/newsty
cp new.sty /usr/share/texmf/tex/latex/newsty
texhash
truetype fonts?
apt install xfstt
FontPath "unix/:7101" in /etc/X11/XF86Config-4
ctrl-alt-backspace
apt install fontforge fontmatrix
installing ttf font
cp font-folder /usr/share/fonts/
fc-cache -vf
losslessly recompressing images
pngcrush
jpegoptim
package management
upgrading
apt update # update package index
apt dist-upgrade # upgrade packages
apt autoclean # remove unavailable packages
mixed stable and testing distribution
# add both stable and testing lines to /etc/apt/sources.list
vi /etc/apt/apt.conf
APT::Default-Release "stable";
apt update
apt -t testing install # package
downgrade to stable distribution
vi /etc/apt/preferences
Package: *
Pin: release a=stable
Pin-Priority: 1001
apt proxy
apt install apt-proxy
vi /etc/apt-proxy/apt-proxy-v2.conf
# set up backend sections
/etc/init.d/apt-proxy restart
# on client machines
vi /etc/apt/sources.list
# use server:9999/section as the source
apt update
apt-proxy-update /var/cache/apt/archives
mount remote apt directory via ssh
apt install sshfs
sshfs host:/var/cache/apt/archives /var/cache/apt/archives
fusermount -u /var/cache/apt/archives
mount remote directory via ssh through fstab
ln -s /sbin/mount.fuse /sbin/mount.fuse.sshfs
vi /etc/fstab
server:/home/user /media/share fuser.sshfs user,noauto 0 0
mount /media/share
umount /media/share
create a local deb repository
apt install dpkg-dev
mkdir /var/cache/apt/altdeb
cp package-file.deb /var/cache/apt/altdeb
dpkg-scanpackages /var/cache/apt/altdeb /dev/null | gzip > /var/cache/apt/altdeb/Packages.gz
vi /etc/apt/sources.list
deb file:// /var/cache/apt/altdeb/
apt update
list installed packages
dpkg --get-selections
upgrading to squeeze
# install later kernel because of new udev
# disk names hda->sda
upgrade-from-grub-legacy
add GPG key (eg Opera)
gpg --keyserver keyserver.ubuntu.com --recv F9A2F76A9D1A0061
gpg --export --armor F9A2F76A9D1A0061 | apt-key add -
viewing library debug information
apt install libname-dbg
cd /usr/src/
apt source libname
objdump --prefix=/usr/src/ --prefix-strip=2 -S /lib/libname
fixing fstab after / mounted ro
reboot to recovery
mount -o remount /dev/sda1 /
vi /etc/fstab
forcing broken dependencies
dpkg -i --ignore-depends package.deb
vi /var/lib/dpkg/status
# remove broken dependencies
installing android
# get SDK platform tools https://developer.android.com/tools/releases/platform-tools
# developer mode settings->about->build x 7
# enable USB debugging on phone from advanced settings
adb devices # list devices
adb reboot bootloader # switch to bootloader
fastboot devices # list fastboot devices
fastboot flashing lock # lock bootloader
fastboot flashing unlock # unlock bootloader
fastboot flash boot boot.img # install image
fastboot reboot # reboot
installation, kernel, devices
install Debian distro
# Portege 3480ct] set up BIOS (F1)
# Portege 3500] set up BIOS (Esc)
boot from Sarge CD
Debian mirror at ftp.iinet.net.au
partition using Debian
no desktop packages
build debian kernel
apt install kernel-package ncurses-dev build-essential
apt install linux-source-2.6.26
tar xfj linux-source-2.6.26.tar.bz2
ln -s /usr/src/kernel-source-2.6.26 /usr/src/linux
bzcat ../patch-2.6.26-8-rt16.bz2 | patch -p1 # real time patches
make clean && make mrproper
make menuconfig # or oldconfig
make-kpkg clean
fakeroot make-kpkg buildpackage linux-image --initrd --append-to-version "-gmX"
dpkg -i linux-image-2.6.26.deb
apt install firmware-linux
backported debian kernel
apt install -t lenny-backports linux-image-2.6.30-bpo.1-686 firmware-linux acpid
boot DSL from grub
# loop mount the iso
# copy the isolinux directory to /boot
# copy the KNOPPIX directory to /
# set up grub to point to linux24 and minirt24.gz
boot windows from second disk
title Windows
rootnoverify (hd1,0)
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1
working with DOS formats
apt install dosfstools
mkfs.fat -F 12 /dev/sdX1 # FAT 12
mkfs.fat -F 16 /dev/sdX1 # FAT 16
mkfs.fat -F 32 /dev/sdX1 # FAT 32
mounting floppy
killall -9 udisks-daemon # squeeze daemon bug
mount /media/floppy
adding and copying to new disk
fdisk /dev/sdX
c # turn off dos compatibility
n p # make primary partition
n e # make extended partition for swap
n l # make logical partition for swap
a 1
w
mkfs -t ext4 /dev/sdX1
tune2fs -O ^has_journal /dev/sdX1 # optionally disable journal
mkswap /dev/sdX5
telinit 1 # or reboot in maintenance mode
# mount sdX1
cp -ax / /new-disk
grub-install --root-directory=/new-disk /dev/sdX
# update UUIDs in /new-disk/etc/fstab
blkid /dev/sdX1 /dev/sdX5
# switch disks
# boot from command line
linux (hd0,1)/vmlinuz root=/dev/sda1
initrd (hd0,1)/initrd.img
boot
grub-mkconfig -o /boot/grub/grub.cfg
# update UUIDs in /etc/initramfs-tools/conf.d/resume
update-initramfs -u
change swap volume
blkid /dev/sda5 >>/etc/initramfs-tools/conf.d/resume
vi /etc/initramfs-tools/conf.d/resume
update-initramfs -u
memtest boot disk
apt install memtest86+
ln -s /usr/lib/grub /lib/grub
ln -s /usr/sbin/grub /sbin/grub
make-memtest86+-boot-floppy
remove extra terminals
vi /etc/inittab
ctrl-alt-F1 ctrl-alt-F7
change magic key to shutdown instead of reboot
vi /etc/inittab
change ctrlaltdel shutdown line to -h instead of -r
# remove unnecessary terminals
allow user to shut down
addgroup shutdown
adduser user shutdown
chown root:shutdown /sbin/shutdown
chmod 750 /sbin/shutdown
chmod u+s /sbin/shutdown
allow user to shut down
visudo
# user] ALL=NOPASSWD: /sbin/shutdown
system clock using ntp
apt install ntp # real-time updates
vi /etc/ntp.conf
server time.iinet.net.au
apt install ntpdate # scheduled updates
sudo crontab -e
2 0 * * * /usr/sbin/ntpdate -s time.iinet.net.au
system testing
apt install sysutils # bogomips, memtest, etc
setting up devices
# add drivers
cp *.ko /lib/modules/`uname -r`/kernel/drivers/mfr/
depmod
# set up nodes
udevinfo -a -p /sysfs_path
vi /etc/udev/rules.d/z60_mfr.rules
KERNEL=="driver", NAME="devicename"
udevtest /sysfs path
parallel port
modprobe ppdev
mknod /dev/parport0 c 99 0 -m 666
fixing irq problems (eg scsi)
# add irqpoll to defoptions
update-grub
prevent process hangup
nohup command # run command without hangup
disown -h pid # prevent hangup of pid
process monitoring
/usr/bin/time -v application # report process statistics
strace -c application 2>strace.out # summarize system calls
run a command from a different user context
su -c "DISPLAY=:0.0 command" user
monitor logins
less /var/log/auth.log
authentication of applications
vi /etc/pam.conf
vi /etc/pam.d/command
list process hierarchy
pstree -p
power down usb port
echo suspend >/sys/bus/usb/devices/1-2/power/level
echo auto >/sys/bus/usb/devices/1-2/power/level
reset root password
# on start, add init=/bin/bash
mount -n -o rw,remount / # remount root
# change root password
sync
mount -n -o ro,remount /
reboot
boot chart
apt install bootchart
# grub
init=/sbin/bootchartd
bootchart
geeqie bootchart.png
preserve MBR
dd if=/dev/hda of=/mnt/sda1/mbr.img bs=512 count=1
dd if=/mnt/sda1/mbr.img of=/dev/hda bs=512 count=1
cleaning up a system
change root password
remove users
adduser smith
purge /home/*
rm /var/log/*.gz
check /etc/network/interfaces
check /etc/wpa_supplicant/wpa_supplicant.conf
check /etc/shadow
check root in /etc/aliases
clean /etc/hosts
change /etc/hostname
root clear .bash_history, .ssh, .gnupg
dd if=/dev/zero of=dummy.txt bs=4096
reducing disk access for SSD
# turn off journal
# set relatime,discard,commit=600 in /etc/fstab
# remove swap from /etc/fstab
# move /tmp and /var/tmp to memory in /etc/fstab
tmpfs /tmp tmpfs defaults 0 0
tmpfs /var/tmp tmpfs defaults 0 0
FAT 16 file system
mkfs.fat -F 16 /dev/sdb1
live usb-hdd
wget ftp://ftp.iinet.net.au/debian/debian-cd/current-live/i386/iso-hybrid/debian-live-X.X.X-i386-lxde-desktop.iso
dd if=debian-live-X.X.X-i386-lxde-desktop.iso of=/dev/sdb
gparted /dev/sdb
# make ext4 partition with label persistence
mount /dev/sdb2
vi persistence.conf
/ union
# boot to usb-hdd, use persistence option
live usb
# get hybrid ISO
gparted
# create FAT partition for ISO
# create ext3 partition for live-rw
# mount FAT partition
unetbootin
vi /media/sdb1/syslinux.cfg
# add persistent flag to boot variables
faster boot
apt install readahead; touch /.readahead-collect
rename user
usermod -l newuser olduser
groupmod -n newgroup oldgroup
usermod -d /home/newuser -m newuser
network led
apt install iptables-persistent
iptables -A INPUT -j LED --led-trigger-id all --led-delay 50
iptables-save >/etc/iptables/rules
echo netfilter-all >/sys/class/leds/beaglebone\:green\:usr0/trigger
systemd
journalctl --follow # view logs for current user
systemctl start service # start service
printing
cups installation
apt install cupsys cupsys-client gs-esp cups-pdf cupsys-bsd hp-ppd
http://localhost:631/admin
# set hp1200 to socket://ip-address:9100
# set pdf to color_ps, or use /usr/share/gs-esp/8.15/lib/ghostpdf.ppd
multiple page printing
apt install mpage
printer sharing
# set to shared from server settings
cupsctl --share-printers
# remote administration
cupsctl --remote-admin
remove xprint
apt --purge autoremove xprint-common
print to shared printer from windows
# add network printer from another machine
# url] http://ip-address:631/printers/queuename
set printer to reverse page order
lpadmin -p CANON -o outputorder-default=reverse
set printer default renderer
lpadmin -p printer -o pdftops-renderer-default=gs
fix Adobe plugin bug generating debuglog
vi -b /opt/Adobe/Reader9/Browser/intellinux/nppdf.so
:s/C:\\nppdf32Log\\/.\/.nppdf32Log./
files, storage and mounting
list available disks and partitions
fdisk -l
mounting USB drive
mkdir /media/usb1
vi /etc/fstab
/dev/sda1 /media/usb1 auto rw,user,umask=000,noauto 0 0
mount /media/usb1
umount /media/usb1
mount ISO file
mkdir /mnt/iso
mount -o loop -t iso9660 file.iso /mnt/iso
umount /mnt/iso
# or
apt install fuseiso9660
add-group username fuse
fuseiso9660 src.iso mountpoint
fusermount -u mountpoint
ripping ISO file
dd if=/dev/cdrom of=file.iso
erase disk
dd if=/dev/zero of=/dev/sdx
check dd progress
kill -USR1 $!
backup
mount /media/usb0
rsync /home/* /media/usb0/host -a --del -e ssh -v
drive testing
dumpe2fs -b /dev/sda1 # list current bad blocks
e2fsck -c /dev/sda1 # read test
e2fsck -cc /dev/sda1 # read/write test
apt install smartmontools
smartctl -i /dev/sda # information
smartctl -d ata -a /dev/sda # extended information
smartctl -d ata -t short /dev/sda # short test
smartctl -d ata -t long /dev/sda # long test
smartctl -l selftest
force fsck on next boot
tune2fs -c 1 /dev/sda1
allow laptop mode to turn off drive
vi /etc/laptop-mode/laptop-mode.conf
CONTROL_HD_IDLE_TIMEOUT=1
LM_AC_HD_IDLE_TIMEOUT_SECONDS=300
LM_BATT_HD_IDLE_TIMEOUT_SECONDS=300
/etc/init.d/laptop-mode restart
allow hdparm to turn off drive
vi /etc/hdparm.conf
/dev/sda {
spindown_time = 240
}
/etc/init.d/hdparm restart
check disk transfer rates
hdparm -t -T /dev/sda
force fast ide (short 40 pin cable)
vi /etc/modprobe.d/options
options ide_core ignore_cable=0 # kernel 2.6.26
options libata force=1.00:short40c # kernel 2.6.32
update-initramfs -u
convert Nero nrg files to iso
apt install nrg2iso
nrg2iso src.nrg dst.iso
orphaned mounts
vi /etc/mtab # and remove, not sure if this is kosher
packaging utilities
apt install zip unzip
apt install unrar
encrypting directory system
apt install encfs
addgroup username fuse
encfs directory mountpoint
# copy files into mount
fusermount -u mountpoint
recursively set permissions
chmod -R u=rwX,go=rX .
# or
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
secure deletion and disk wiping
apt install secure-delete
sfill -lz /
encryption applications
apt install mypasswordsafe
file management
apt install xfe xtrlock filelight
mount root readonly
telinit 1
service rsyslog stop
service network-manager stop
killall dhclient
mount -o remount,ro /
backup disk
# mount root readonly
dd if=/dev/sda of=host.img.gz
fdisk -l -u host.img
# something like mount -o loop,ro host.img XXX
managing MSDOS files
apt install mtools
mcopy
redirect both standard and error output
command &>command.out
extended attributes
getfattr -d filename
setfattr -n name -v value filename
truncate a file
dd if=/dev/null bs=1k seek=new size in KBi of=filename
disk quotas
apt install quota
file creation times
debugfs -R "stat " /dev/sda5
storing archives as readable filesystems
apt install squashfs-tools
mksquashfs /home/user dir.sqsh
mount dir.sqsh /media/share -t squashfs -o loop
fusermount -u /media/share
software raid
apt install mdadm
mdadm --create /dev/md0 -v --level=0 --raid-devices=2 /dev/sda2 /dev/sdb2
mkfs -t ext3 /dev/md0
upgrading from ext3 to ext4
vi /etc/fstab # change to ext4
# reboot into single user read only
tune2fs -O extents,uninit_bg,dir_index /dev/sda1
# reboot into single user read only
e2fsck -fDC0 /dev/sda1
# reboot
change reserved space
tune2fs -m5 /dev/sdb1
monitor block reads/writes
while true; do cat /sys/block/sda/stat; sleep 10; done
Adobe digital editions
# mount ereader and note mount point
# umount ereader
winecfg
# add ereader mount point as floppy drive Y
wine digitaleditions.exe
# register
# drag and drop files
new uuid
tune2fs /dev/sdb1 -U random
hard link duplicate files
hardlink -s 64M -X -v .
image failed hard drive
apt install gddrescue
smartctl -l scterc,10,10 /dev/sdx # limit recovery time
ddrescue -d -r3 /dev/sdx sdx.img sdx.map
changing partitions on loopback disk images
kpartx -av disk.img
ls -l /dev/mapper/loop0p* # dm to partition mapping
ln -s /dev/dm-X /dev/loop0pY # mirror previous links
gparted /dev/loop0
kpartx -uv /dev/loop0 # update
kpartx -d disk.img # disconnect
rm -f /dev/loop0pX
splitting files
split -b 2G -d filename filename.
cat filename.* >filename
overlay filesystem
mount -t overlay overlay -o lowerdir=lower/,upperdir=upper/,workdir=.working/ merged/
MTP access
apt install jmtpfs
# unlock phone
jmtpfs mountpoint
fuse -u mountpoint
programming
install perl
apt install perl perl-doc
java
apt install j2re1.4 # deb ftp://mirror.aarnet.edu.au/pub/java-linux/debian/ stable non-free
add path in opera # /usr/lib/j2se/1.4/jre/lib/i386
run java once as superuser
java
apt install sun-java6-bin sun-java6-fonts sun-java6-plugin
update-alternatives --config java
avr
apt install avrdude
webasm
apt install wabt
vi /etc/nginx/mime.types
application/wasm wasm;
vi test.wasm
(
module
(
func $test (export "test") (param f64) (result f64)
(f64.mul (local.get 0) (f64.const 42))
)
)
wat2wasm test.wat
vi test.html
<html>
<body>
<script>
WebAssembly.instantiateStreaming(fetch('test.wasm'))
.then(results => alert(results.instance.exports.test(10)));
</script>
</body>
</html>
install current libboost
# download to /usr/src
tar --bzip2 -xf boost*.tar.bz2
./configure --with-libraries=date_time,thread
make install
mv /usr/local/include/boost_1-36/boost /usr/local/include
rmdir /usr/local/include/boost_1-36
file differencing
apt install meld
invoking a command in multiple directories
find . -type d -exec bash -c 'cd "{}"; command' \;
hex dump
od -A n -t x1 file.bin
hexdump file.bin -e '"" 128/1 "%02X" "\n"'
mathcad
LC_ALL=en_CA.UTF-8 wine /media/cdrom/SETUP.EXE
apt install winetricks
winetricks corefonts vcrun6sp6
cp SYMBOL.TTF .wine/drive_c/windows/Fonts/
git
# basic
cd $DIRECTORY
git init # create git repository
git add filename # track files
git commit -a -m 'message' # stage and commit
git remote add repository https://host/username/repository.git
git push # push to remote
# detailed
git status # summary status
git add -u # stage commit
git diff # unstaged changes
git commit -m 'message' # commit
git checkout -- . # discard changes
git reset --hard branch # unwind back
git branch # show branches
git log # show commit log
git reflog # show head reference log
git branch -D branch # delete branch
git push -u repository master # explict push to remote
cmake
apt install cmake
vi CMakeLists.txt
cmake_minimum_required(VERSION version)
project(project_name)
add_compile_definitions()
set(CMAKE_CXX_FLAGS "flags")
file(GLOB SOURCES "sources")
add_executable(executable ${SOURCES})
cmake -B build # create build files
cmake --build build # run build
sqlite
sqlite3 database.sqlite
.tables
.schema table
select * from table where field = 'value';
select count (*) from table;
^D
bash shortcuts
sudo !! # sudo last command
cmd !* # new command with previous arguments
reset # reset terminal
<esc> . # last argument
^oldtext^newtext # rerun with replace
<ctrl>-u <ctrl>-y # undo/restore command buffer
<ctrl>-x <ctrl>-e # edit command
<ctrl>-l # clear screen
<ctrl>-r # search commands
mv filename.{old,new} # change filename extension
<alt>-<SysRq> r e i s u b # reboot: raw, sigterm, sigkill, sync, ro mount, boot
serve current directory on http
python3 -m http.server # serve folder on port 8000
monitor network activity
lsof -i
sand boxes
screen
apt install screen
screen
<ctrl-a>d # disconnect session
<ctrl-a>c # new session
<ctrl-a>p # previous session
<ctrl-a>n # next session
<ctrl-a>[ # scroll mode
screen -ls # list screen sessions
screen -r # resume
exit
windows in vmware
# download vmware tar from www.vmware.com/products/players
# does not work with 64 bit kernel
apt install linux-headers-2.6-k7
export CC=/usr/bin/gcc-4.1
./vminstall.pl
use headers from built kernel
# create image files www.easyvmx.com
# boot from floppy, fdisk/format, install from CD
# download VMWare Tools windows.iso from Workstation/Server
# mount as second cdrom, install video and mouse drivers
apt install dbus # fixes /usr/lib/libhal.so.1 hang in libdbus, libdbus-glib
# parallel port access
adduser smith lp
rmmod lp
windows in virtualbox
apt install virtualbox-ose virtualbox-ose-modules-2.6-686 -t lenny-backports
# if in repository
apt install virtualbox-ose-modules-2.6-686 -t lenny-backports
# otherwise
apt install virtualbox-ose-source -t lenny-backports
m-a unpack virtualbox-ose
m-a auto-install virtualbox-ose
# create virtual disks
# install from iso mounted as CD
# download VBoxGuestAdditions_1.6.6.iso
# install guest additions from within guest operating system
# make sure vboxdrv loads on startup
vi /etc/modules
vboxdrv
vboxnetflt
# otherwise
vi /etc/default/virtualbox-ose
LOAD_VBOXDRV_MODULE=1
/etc/init.d/virtualbox-ose start
# start the machine
# select host interface to bridge the networks
insmod vboxnetflt # solves bad module
VBoxManage startvm virtualmachine
windows virtualbox images
http://dev.modern.ie/tools/vms/linux
vboxmanage clonehd disk.vmdk disk.vdi --format VDI
adduser user vboxusers
vboxmanage extpack install extpack.vbox-extpack
shrink virtualbox disk file
# from client
# defragment
sdelete -z
# from host
vboxmanage modifyhd disk.vdi compact
clone virtualbox disk file
VBoxManage clonevdi src.vdi dst.vdi
kvm
apt install qemu-system libvirt-clients libvirt-daemon-system virtinst
adduser user libvirt
virsh list --all
virt-install --virt-type kvm -name test-server --cdrom debian-11.0.0-amd64-netinst.iso --os-variant debian11 --disk size=10 --memory 1024
virsh --connect=qemu:///system net-start default # to start virtual network
virsh start test-server # to start
virsh shutdown test-server # to shutdown
virt-viewer # to connect
wine
ln -s /media/share .wine/dosdevices/d:
apt install fuseiso
sudo adduser user fuse
sh -c 'fuseiso /home/user/rom.iso /media/share;\
wine "c:/Program Files/example.exe";\
fusermount -u /media/share'
chroot
mkdir chroot
debootstrap stable chroot debian_repository
chroot chroot /bin/bash
gcc
g++ -v -dD -E empty_file.cpp # list predefines
g++ --print-search-dirs # list search path