HowTo

String replace
sed -i 's|STRING_FROM|STRING_TO|g' FILE

add line to a file
sed -i '13i\YOUR_TEXT' FILE

Extract RPM Archiv
rpm2cpio FILENAME | cpio -i --make-directories

Get file atime, mtime, ctime
stat FILE

Change mtime from a file
touch -d "2005-05-05 15:55:55" FILE

Create selfextract archive under Linux
makeself.sh [-bzip2] DIR archiv.run "DESCRIPTION" COMMAND

Create Linux software RAID
mdadm --create /dev/md2 --level=raid5 --raid-devices=4 --spare-devices=0 /dev/sdb4
/dev/sdc4 /dev/sdd4

Wake On Lan (WOL)
wakeonlan 00:11:22:33:44:55

Change root and start bash
chroot /mnt /bin/bash

Enable / Disable swap
swapoff -a
swapon -a

extract initrd.gz
gunzip

extract initrd.lz</strong>
unlzma -c -S .lz ../initrd.lz | cpio -id
 
<strong>compress initrd</strong>
find ./ | cpio -H newc -o > ../initrd
gzip ../initrd
 
<strong>Extract *.deb</strong>
dpkg-deb -x file.deb /tmp
 
<strong>Add script to a runlevel</strong>
sudo update-rc.d providername start 90 2 3 5 . stop 10 0 1 4 6 .
 
<strong>Most used commands</strong>
history | awk '{print $2}' | sort | uniq -c | sort -rn | head
 
<strong>VNC on slow connection</strong>
xtightvncviewer -compresslevel 9 -quality 0 192.168.0.100
xvnc4viewer -ZlibLevel 9 -LowColourLevel 0 192.168.0.110
 
<strong>Format partition as FAT16</strong>
mkdosfs -F 16 -n SDCARD /dev/sdd1
 
<strong>Forcing kernel to use new partition table after fdisk</strong>
partprobe
 
<strong>list blocking prozesses</strong>
lsof /mnt
 
<strong>Add a existing user to existing group</strong>
usermod -a -G GROUPNAME USERNAME
 
<strong>Delete user from group</strong>
edit /etc/group and remove user name
or
id -nG USERNAME
usermod -G group1, group2, group3,... USERNAME
# test gpasswd
 
<strong>Mount SSH</strong>
sshfs user@192.168.1.2:/media/images /mnt
 
<strong>unmask</strong>
global: /etc/profile
echo "umask 0000" >> ~/.profile
 
<strong>check for listening ports</strong>
netstat -anp | grep 1234
lsof -i | grep 1234
 
<strong>dpkg install force-architecture</strong>
dpkg  --force-architecture -i *.deb
 
<strong>display bandwidth usage</strong>
iftop
 
<strong>log loadavg</strong>
echo "$(date) $(cat /proc/loadavg)" >> loadavg.log
 
<strong>convert qcow2 to raw image</strong>
qemu-img convert -f qcow2 root.qcow2 -O raw root.raw
 
<strong>losetup</strong>
losetup -a - list all used devices
losetup -d loop_device - delete loop
losetup -f -  print name of first unused loop device
 
<strong>reconfigure keyboard / console</strong>
dpkg-reconfigure console-setup
 
<strong>kill all prozess from a user</strong>
ps -u USERNAME |  awk '{print $1}' | xargs kill -9
 
<strong>connect with gnome nautilus to ssh</strong>
sftp://root@SERVER/SHARE
 
<strong>disable monitor power save (disable DPMS)</strong>
xset -dpms
 
<strong>disable console, x11 screensaver</strong>
xset s 0 0
xset s noblank
xset s off
xset -dpms
setterm -blank 0
setterm -powersave off
setterm -powerdown 0
 
<strong>force umount</strong>
sudo umount -l -f /mnt/mountpoint
 
<strong>convert nero cd image to iso</strong>
nrg2iso infile.nrg outfile.iso
 
<strong>enable harddisk udma mode</strong>
hdparm -d1 /dev/hda
 
<strong>remove multiple spaces from a string</strong>
cat x.txt | tr -s " "
 
<strong>create uniqe file from two files</strong>
dos2unix adr_*.txt;  cat adr_hp.txt adr_sel.txt | sort | uniq > adr_uniq.txt
 
<strong>copy files between hosts with SSH and tar</strong>
tar -cf - /some/file | ssh host.name tar -xf - -C /destination
 
<strong>read cd volume label</strong>
dd if=/dev/hdd bs=1 skip=32808 count=32 2> /dev/null | tr -d " "
 
<strong>rebuild initrd</strong>
gzip -d miniroot.gz; mount miniroot /mnt/ -o loop; vi /mnt/linuxrc; gzip --best miniroot
 
<strong>Fix slow SSH login</strong>
echo "UseDNS no" >>  /etc/ssh/sshd_config
 
<strong>set hostname</strong>
echo myhost.local > /etc/hostname; /etc/init.d/hostname.sh start
 
<strong>start xterm in Xorg session</strong>
cat <<EOF> $HOME/.xsession
xterm
EOF
 
<strong>change language temporary on command line</strong>
export LANG="en_US.UTF-8"
 
<strong>fix broken package with apt-get (dpkg)</strong>
rm /var/lib/dpkg/info/PACKAGE_NAME*
dpkg –remove –force-depends –force-remove-reinstreq PACKAGE_NAME
 
<strong>configure timezone</strong>
dpkg-reconfigure tzdata
 
<strong>allow user to administrate system (add to adm group)</strong>
usermod -a -G adm $USER
 
<strong>change password non interactive</strong>
echo "root:terceS" | chpasswd
 
<strong>clean mbr</strong>
dd if=/dev/zero of=/dev/sdb bs=446 count=1
 
<strong>create checksum</strong>
echo "foo" | md5sum
 
<strong>MD5-Hash password</strong>
echo terceS | mkpasswd -s -H MD5
 
<strong>create tmpfs</strong>
cat <<EOF>> $TARGET/etc/fstab
tmpfs   /tmp   tmpfs   defaults   0   0
EOF
 
<strong>set / change volume label</strong>
e2label /dev/sda1 newlabel
tune2fs -L newlabel /dev/sda1
 
<strong>clean ubuntu trash</strong>
sudo rm -rf ~/.local/share/Trash/files/*
 
<strong>convert ISO-8859-1 to UTF-8</strong>
iconv --from-code=ISO-8859-1 --to-code=UTF-8 file.in > file.out file.in > file.out
 
<strong>remove multiple blanks</strong>
cat in.txt | sed "s/[ ][geshifilter- ]*/ /g&quot; &gt; out.txt

&lt;strong&gt;Extract Windows cab file&lt;/strong&gt;
cabextract CAB_FILE_NAME.exe

&lt;strong&gt;set recursive directory rights&lt;/strong&gt;
find . -type f -exec chmod 644 {} \;

&lt;strong&gt;extract pages from PDF file&lt;/strong&gt;
pdftk IN.pdf cat 1-5 output OUT.pdf

&lt;strong&gt;merge pdf sites to a single dokument&lt;/strong&gt;
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=out.pdf *.pdf

&lt;strong&gt;Ubuntu german locale&lt;/strong&gt;
locale-gen de_DE.UTF-8

echo 'LANG=&quot;de_DE&quot;' &gt; /etc/default/locale

cat &lt;&lt;EOF&gt;&gt; ~/.bashrc
export LANG=de_DE.UTF-8
export LC_ALL=de_DE.UTF-8
EOF

&lt;strong&gt;convert charcode&lt;/strong&gt;
iconv --from-code=UTF-8 --to-code=ISO-8859-1 IN.txt &gt; OUT.txt

&lt;strong&gt;find duplicate files&lt;/strong&gt;
fdupes -r . &gt; fdupes.txt

&lt;strong&gt;disable Nvidia logo on Xorg start (/etc/X11/xorg.conf)&lt;/strong&gt;
Section &quot;Device&quot;
	Option		&quot;NoLogo&quot;	&quot;True&quot;
EndSection

&lt;strong&gt;Reload gnome panels&lt;/strong&gt;
killall gnome-panel
#? killall gnome-panel nautilus

&lt;strong&gt;SSH X11 forward&lt;/strong&gt;
ssh -Y YOUR_SERVER -l YOUR_USER xclock

&lt;strong&gt;Mirror a homepage with wget (http://wiki.ubuntuusers.de/wget)&lt;/strong&gt;
wget  -m http://www.YOUR_DOMAIN.com --reject=pdf,jpg,gif,png,flv,m4v

&lt;strong&gt;format DVD-RW&lt;/strong&gt;
dvd+rw-format -force /dev/cdrom

&lt;strong&gt;update kernel partition table&lt;/strong&gt;
apt-get install -y parted &amp;&amp; partprobe

&lt;strong&gt;sync files from webserver&lt;/strong&gt;
wget -m -np -nH --cut-dirs=1 http://www.YOUR_DOMAIN.com/stsbox/ --reject=&quot;index*&quot;#

&lt;strong&gt;grep list only the file name&lt;/strong&gt;
grep  PATTERN -o *

&lt;strong&gt;view disk UUID and label&lt;/strong&gt;
blkid /dev/sda1 

[/geshifilter-]

Do you like this page? Then support it. Please click the AD below and visit the sponsor. Thank you!