Linux Cheatsheet
Here is a list of commands and howtos, which I found worth writing down over the last years.
There is usually no explanation given. If required, they can be found in the man pages or Ubuntu wiki. Use at your own risk! Never copy commands without thinking about them.
There will be new things appended from time to time.
select-default-wordlist
select-default-ispell
echo 1 > /proc/sys/vm/block_dump
kernel.dmesg_restrict = 0
1. Create xorg.conf:
Xorg :1 -configure
2. Copy to proper location
3. Add to ServerLayout
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
-> Not enough.
Section "Monitor":
Option "DPMS"
-> Not enough, KDE trinity sets the values too:
kcontrol -> disable power settings there
XKBOPTIONS="terminate:ctrl_alt_bksp"
aa-status
aa-complain usr.bin.vlc
If this does not work (encrypted drives):
nano /etc/udev/rules.d/99-hide-disks.rules
KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"
KERNEL=="sdb1", ENV{UDISKS_IGNORE}="1"
vm.swappiness = 10
rm nepomukserver.desktop
by "Allow from @LOCAL"
[super-user-command]
super-user-command=su
rsync -aHuv --delete-after /sbin/ /mnt/sdb9/sbin/
rsync -aHuv --delete-after /bin/ /mnt/sdb9/bin/
rsync -aHuv --delete-after /lib/ /mnt/sdb9/lib/
rsync -aHuv --delete-after /opt/ /mnt/sdb9/opt/
rsync -aHuv --delete-after /var/ /mnt/sdb9/var/
rsync -aHuv --delete-after /boot/ /mnt/sdb9/boot/
rsync -aHuv --delete-after /initrd.img /mnt/sdb9/initrd.img
rsync -aHuv --delete-after /vmlinuz /mnt/sdb9/vmlinuz
rsync -aHuv --delete-after /etc/ /mnt/sdb9/etc/
echo -e 'Package: *systemd*\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemd
showkey -s
Append:
screen -d -m bash -c 'powertop --auto-tune; echo on > /sys/bus/usb/devices/usb3/power/control; echo on > /sys/bus/usb/devices/usb2/power/control'
From askubuntu.com. Adjust usb2 and usb3 to your system, or add more if you want to have hotplug capability on more than two ports.
tar -xf filename.tar
updatedb
shred -n1 -s4600M myfile
losetup /dev/loop0 /path/to/myfile
With entering password: cryptsetup -y create mysecret /dev/loop0
With file as password: cryptsetup -d /mykey create mysecret /dev/loop0
Check it: dmsetup ls
Mount it: mount /dev/mapper/mysecret /mnt/tmp
Unmount it:
umount /mnt/tmp
cryptsetup remove mysecret
losetup -d /dev/loop0
Enter password
dom.webnotifications.enabled -> FALSE
media.autoplay.enabled -> FALSE
plugins.notifyMissingFlash -> FALSE
browser.tabs.WarnOnClose -> FALSE
browser.tabs.CloseWindowWithLastTab -> FALSE
update-firefox --config x-www-browser
nano /etc/apache2/ports.conf
Listen 127.0.0.1:80
nano /etc/apache2/sites-enabled/000-default.conf
After "DocumentRoot /var/www/html" add:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
For <Directory /var/www/> change into:
AllowOverride all
a2enmod rewrite
systemctl restart apache2
2. nano /etc/nsswitch.conf
hosts: files mdns4_minimal dns mdns4 [NOTFOUND=return]
3. nano /etc/avahi/avahi-daemon.conf
disable-user-service-publishing=yes
4. service avahi-daemon restart
Hosts are now available under PCNAME.local
AllowUsers YOURUSERNAME@YOURONLYIP
2. Start wished command
3. Ctrl+B, D leaves tmux
4. tmux attach to reconnect later
1. Backup the settings from the FritzBox.
2. Locate wrong settings lan_dns4_server and fix the IP value.
3. Recalculate the checksum with the help of the script from superuser.com
4. Change the checksum in the file
5. Upload fixed config
svn propedit svn:ignore .
git add .
git commit -m "Test"
git remote add origin https://github.com/YOURUSERNAME/YOURPROJECT.git
git remote -v
git pull origin master
git push origin master
git push origin master
One pattern per line, like: *~
fakeroot
apt-get --build source xserver-xorg-video-ati
dpkg-deb --control xserver-xorg-video-ati_7.5.0-1_i386.deb ati/DEBIAN
---Edit the files---
dpkg -b radeon xserver-xorg-video-radeon_7.5.0-2MalteM_i386.deb
Virtual 2048 2048
if xrandr delivers too small values
Generate proper modeline: cvt 1920 1080
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync xrandr --addmode CRT1 1920x1080_60.00
xrandr --output CRT1 --mode 1920x1080_60.00
CRT1 can be namend VGA-0 or VGA_1 - depending on the driver
ffmpeg -i input.MTS -threads 3 -c:v libvpx -crf 10 -vf scale=-1:1080 -b:v 6M -c:a libvorbis output.webm
cd ~/.wine/drive_c/windows
touch War3Unin.dat
touch War3Unin.exe
default-sample-channels = 4
default-channel-map = rear-left,rear-right,front-left,front-right
2. alsamixer
F6 -> HD Audio Generic
Channel Mod ->4ch
3. Restart Alsa, this saves the config changes done by alsamixer
4. pavucontrol: Select the output device "Analog Surround 4.0 + Analog Stereo Input"
5. Test the settings
Test tone front left: speaker-test -c 4 -t sine -P 8 -s 1
Test tone front right: speaker-test -c 4 -t sine -P 8 -s 2
Test tone back right: speaker-test -c 4 -t sine -P 8 -s 3
Test tone back left: speaker-test -c 4 -t sine -P 8 -s 4
The number sec= could be 30 or 60 too
#!/bin/bash
set -e
DSTR=`date +%Y-%m-%d`
OUTFILE="merged-$DSTR.gpx"
INFILES=""
for f in records/20*.gpx
do
INFILES="$INFILES -f $f"
done
#Makes a new track if the time of the next point is more than 10minutes later
gpsbabel -t -i gpx $INFILES -x track,merge,discard,title="",split=10m -o gpx -F "$OUTFILE"
#the track names are just annoying in Google Earth, so remove them:
awk '!/name/' "$OUTFILE" > "$OUTFILE.tmp"
mv "$OUTFILE.tmp" "$OUTFILE"
There is usually no explanation given. If required, they can be found in the man pages or Ubuntu wiki. Use at your own risk! Never copy commands without thinking about them.
There will be new things appended from time to time.
System
Scan for SCSI drives
sg_scanSelect default wordbook/spelling
as rootselect-default-wordlist
select-default-ispell
Switch messages from local language to english
LANG=CMonitor which files are written
systemctl disable rsyslogecho 1 > /proc/sys/vm/block_dump
Follow dmesg in a live view
dmesg -wHPermit dmesg as normal user
nano /etc/sysctl.confkernel.dmesg_restrict = 0
Create new user
adduser guestAdd user into group of other user
usermod -aG guest THEUSERCompletely disable DPMS
Problem is, screen wont show anything after disabled once1. Create xorg.conf:
Xorg :1 -configure
2. Copy to proper location
3. Add to ServerLayout
Option "BlankTime" "0"
Option "StandbyTime" "0"
Option "SuspendTime" "0"
Option "OffTime" "0"
-> Not enough.
Section "Monitor":
Option "DPMS"
-> Not enough, KDE trinity sets the values too:
kcontrol -> disable power settings there
Enable Control+Alt+Backspace again
nano /etc/default/keyboardXKBOPTIONS="terminate:ctrl_alt_bksp"
Find all 32bit packages (left over from a 32->64bit system migration)
file /usr/bin/* | grep 32-bit | cut -f 1 -d ":" | apt-file search -fApp Armor
aa-enforce /etc/apparmor.d/usr.lib.firefox-esr.firefox-esraa-status
aa-complain usr.bin.vlc
Remove unwanted drives from Save-As dialog
x-gvfs-hide as mount option or set the mount point to something else than /mediaIf this does not work (encrypted drives):
nano /etc/udev/rules.d/99-hide-disks.rules
KERNEL=="sda1", ENV{UDISKS_IGNORE}="1"
KERNEL=="sdb1", ENV{UDISKS_IGNORE}="1"
Avoid swapping
nano /etc/sysctl.confvm.swappiness = 10
Kill nepomuk
cd /usr/share/autostartrm nepomukserver.desktop
Add a script to startup (sysvinit)
update-rc.d startupImage.sh defaultsSet CUPS policities
Replace "Require user @SYSTEM"by "Allow from @LOCAL"
Use su instead of sudo
nano ~/.kde/share/config/kdesurc[super-user-command]
super-user-command=su
Trinity wont run properly, conflicting with KDE4
Remove package kdelibs4c2Copy whole Linux installation
rsync -aHuv --delete-before /usr/ /mnt/sdb9/usr/rsync -aHuv --delete-after /sbin/ /mnt/sdb9/sbin/
rsync -aHuv --delete-after /bin/ /mnt/sdb9/bin/
rsync -aHuv --delete-after /lib/ /mnt/sdb9/lib/
rsync -aHuv --delete-after /opt/ /mnt/sdb9/opt/
rsync -aHuv --delete-after /var/ /mnt/sdb9/var/
rsync -aHuv --delete-after /boot/ /mnt/sdb9/boot/
rsync -aHuv --delete-after /initrd.img /mnt/sdb9/initrd.img
rsync -aHuv --delete-after /vmlinuz /mnt/sdb9/vmlinuz
rsync -aHuv --delete-after /etc/ /mnt/sdb9/etc/
Check for local modifications of config files
debsums -c -e | grep ^/etc/init.dNo systemd
echo -e 'Package: systemd\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemdecho -e 'Package: *systemd*\nPin: origin ""\nPin-Priority: -1' > /etc/apt/preferences.d/systemd
Enable extra keys
Shows the map: xmodmap -pkeshowkey -s
Automatically adjust energy settings with powertop
nano /etc/rc.localAppend:
screen -d -m bash -c 'powertop --auto-tune; echo on > /sys/bus/usb/devices/usb3/power/control; echo on > /sys/bus/usb/devices/usb2/power/control'
From askubuntu.com. Adjust usb2 and usb3 to your system, or add more if you want to have hotplug capability on more than two ports.
Filesystem
Unpack .tar.gz
gunzip filename.tar.gztar -xf filename.tar
Find files
locate -i xyzUpdate files database
as root:updatedb
Search through the content of all files in a folder
find . -type f -exec grep "wxvlc" '{}' \; -printGet date from files found
locate cookies.sqlite | xargs ls -lChange the owner
chown [-R] newUser DirectoryOrFileBenchmark harddisk with 4GB
bonnie -u USERNAME -d DIRECTORY -s 4096Check a file system
fsck /dev/sdXCreate an encrpyted file system in a file
touch myfileshred -n1 -s4600M myfile
losetup /dev/loop0 /path/to/myfile
With entering password: cryptsetup -y create mysecret /dev/loop0
With file as password: cryptsetup -d /mykey create mysecret /dev/loop0
Check it: dmsetup ls
Mount it: mount /dev/mapper/mysecret /mnt/tmp
Unmount it:
umount /mnt/tmp
cryptsetup remove mysecret
losetup -d /dev/loop0
Create password file
sha256 > mykeyEnter password
Create file system
mke2fs /dev/mapper/mysecretReenable Konqueror (KDE3, Trinity) to open compressed files
delete content in /usr/share/kubuntu-default-settings/kde-profile/default/share/mimelnk/applicationSync from local PC to remote PC
rsync -auv ./foo REMOTEPCNAME:/home/USERNAME/fooRemotely sync with only specific files
rsync -auxXv -e "ssh -l USERNAME" --include='*.pdf' --exclude='*.*' "/home/USERNAME/DIRECTORY/" "IPV4:/home/USERNAME/DIRECTORY/"Set name of an USB drive
mlabel -i /dev/sdd1 -s ::"ForRigol8GB"Network
Add a DNS server
nano /etc/resolv.confAdd a route
sudo ip route add default via 192.168.1.1 dev eth0Stop Firefox being annoying
about:configdom.webnotifications.enabled -> FALSE
media.autoplay.enabled -> FALSE
plugins.notifyMissingFlash -> FALSE
browser.tabs.WarnOnClose -> FALSE
browser.tabs.CloseWindowWithLastTab -> FALSE
Set your default browser to Firefox
update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/bin/firefox 10update-firefox --config x-www-browser
Fix Thunderbird always opening attachments with the wrong program
Edit .icedove/YOURPROFILE/mimeTypes.rdfConfigure Apache
apt-get install apache2 libapache2-mod-phpnano /etc/apache2/ports.conf
Listen 127.0.0.1:80
nano /etc/apache2/sites-enabled/000-default.conf
After "DocumentRoot /var/www/html" add:
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
For <Directory /var/www/> change into:
AllowOverride all
a2enmod rewrite
systemctl restart apache2
Convert old html files into UTF-8
recode html..utf8 < index0.php > index1.phpSetup MDNS
1. apt-get install avahi-daemon2. nano /etc/nsswitch.conf
hosts: files mdns4_minimal dns mdns4 [NOTFOUND=return]
3. nano /etc/avahi/avahi-daemon.conf
disable-user-service-publishing=yes
4. service avahi-daemon restart
Hosts are now available under PCNAME.local
Secure SSH
nano /etc/ssh/sshd_configAllowUsers YOURUSERNAME@YOURONLYIP
Let a command run on a computer accessed by ssh in the background
1. tmux2. Start wished command
3. Ctrl+B, D leaves tmux
4. tmux attach to reconnect later
Set FritzBox to an IP not ending with .1
After setting the FritzBox 7490 IPv4 to say 192.168.23.42, the DNS entry wich is delivered by the DHCP answer is still 192.168.23.1 and devices not using their own DNS settings wont have Internet access.1. Backup the settings from the FritzBox.
2. Locate wrong settings lan_dns4_server and fix the IP value.
3. Recalculate the checksum with the help of the script from superuser.com
4. Change the checksum in the file
5. Upload fixed config
Programming
Ignore files for SVN
svn propset svn:ignore *.suo .svn propedit svn:ignore .
Use GIT
git initgit add .
git commit -m "Test"
git remote add origin https://github.com/YOURUSERNAME/YOURPROJECT.git
git remote -v
git pull origin master
git push origin master
Update to GIT
git commit -m "Foobar"git push origin master
Ignorefile for GIT
nano .gitignoreOne pattern per line, like: *~
File diff tool
kdiff3Get the source of a package and build it
apt-get source xserver-xorg-video-atifakeroot
apt-get --build source xserver-xorg-video-ati
Fix dependencies and version of a package
dpkg-deb -x xserver-xorg-video-ati_7.5.0-1_i386.deb atidpkg-deb --control xserver-xorg-video-ati_7.5.0-1_i386.deb ati/DEBIAN
---Edit the files---
dpkg -b radeon xserver-xorg-video-radeon_7.5.0-2MalteM_i386.deb
Multimedia
Mount iso image
mount image.img /mnt/tmp -t iso9660 -o loopRotate an image
exiftool -Orientation='Rotate 270 CW' image.jpgResize all jpg files in a folder
for i in `ls`; do convert -resize 800x800 -quality 65 $i resized_$i; doneConvert a video file to a DVD compatible video file
ffmpeg -i movie.avi -aspect 4:3 -target pal-dvd dvd.mpgConvert DVD compatible video file into a DVD file structure
dvdauthor -o dvd/ -t dvd.mpgBurn a DVD file structure onto a DVD
growisofs -Z /dev/sr0 -dvd-video dvd/Configure screen
Add in xorg.conf SubSectionVirtual 2048 2048
if xrandr delivers too small values
Generate proper modeline: cvt 1920 1080
xrandr --newmode "1920x1080_60.00" 173.00 1920 2048 2248 2576 1080 1083 1088 1120 -hsync +vsync xrandr --addmode CRT1 1920x1080_60.00
xrandr --output CRT1 --mode 1920x1080_60.00
CRT1 can be namend VGA-0 or VGA_1 - depending on the driver
Convert midi to mp3
timidity foo.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k bar.mp3Restart Spacenav to make it work in Freecad
/etc/init.d/spacenavd restartRemove help button from Konqueror (KDE3, Trinity)
Konqueror-> Titelleiste rechte Maustaste -> Fensterverhalten Festlegen -> Fensterdekoration -> Knöpfe -> Benutzerdefinierte Position von Titelleistenknöpfen -> Entfernen des Symbols per Drag and DropMerge PDFs
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=firstANDsecond.pdf -dBATCH first.pdf second.pdfConvert file to webm
ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis output.webmffmpeg -i input.MTS -threads 3 -c:v libvpx -crf 10 -vf scale=-1:1080 -b:v 6M -c:a libvorbis output.webm
Make tethering on smartphone work
All root applications need access to wireless lanMake Frozen Throne installer work
After installing base gamecd ~/.wine/drive_c/windows
touch War3Unin.dat
touch War3Unin.exe
Set Alsa to run as 4.0 surround system
1. nano /etc/pulse/daemon.confdefault-sample-channels = 4
default-channel-map = rear-left,rear-right,front-left,front-right
2. alsamixer
F6 -> HD Audio Generic
Channel Mod ->4ch
3. Restart Alsa, this saves the config changes done by alsamixer
4. pavucontrol: Select the output device "Analog Surround 4.0 + Analog Stereo Input"
5. Test the settings
Test tone front left: speaker-test -c 4 -t sine -P 8 -s 1
Test tone front right: speaker-test -c 4 -t sine -P 8 -s 2
Test tone back right: speaker-test -c 4 -t sine -P 8 -s 3
Test tone back left: speaker-test -c 4 -t sine -P 8 -s 4
Make Skype work again
env PULSE_LATENCY_MSEC=90 skypeforlinuxThe number sec= could be 30 or 60 too
Put all GPS tracks into a single file
Processes 700000+ waypoints distributed over a vew hundred files within some seconds.#!/bin/bash
set -e
DSTR=`date +%Y-%m-%d`
OUTFILE="merged-$DSTR.gpx"
INFILES=""
for f in records/20*.gpx
do
INFILES="$INFILES -f $f"
done
#Makes a new track if the time of the next point is more than 10minutes later
gpsbabel -t -i gpx $INFILES -x track,merge,discard,title="",split=10m -o gpx -F "$OUTFILE"
#the track names are just annoying in Google Earth, so remove them:
awk '!/name/' "$OUTFILE" > "$OUTFILE.tmp"
mv "$OUTFILE.tmp" "$OUTFILE"