Commands
man
man correct caracters.
LANG=C man passwd
man clean for output to file.
man [manual] | col -b > file.txt
putty
set up tunnel
putty -l bjorklun -pw password -L 19242:192.168.0.42:3389 blt.homeip.net
mbr
backup mbr.
# dd if=/dev/sdX of=/temp/sdx-mbr bs=512 count=1
restore mbr
# dd if=/temp/sdx-mbr of=/dev/sdX bs=446 count=1
numbers
series of numbers
bash: echo {1..10}
rpm
install src.rpm
rpmbuild --rebuild alien-6.51-1.src.rpm rpm -i /usr/src/redhat/RPMS/x86_64/alien-6.51-1.rpm
List contents of rpm.
rpm -qlp myfile.rpm
Extract contents of rpm.
rpm2cpio *.rpm | cpio -i --make-directories
Which version of rpm is installed. /etc/rpm/macros
%_query_all_fmt %%{name}-%%{version}-%%{release}.%%{arch}
Extract rpms in subdirectories.
for RPM in $(ls *|sed 's_\.rpm$__g');do echo $RPM; mkdir $RPM; rpm2cpio $RPM.rpm | (cd $RPM && cpio -i --make-directories);done
clean
Clean file from comments and blank lines.
sed '/ *#/d; /^ *$/d'
Update release area Windows.
servicepack.exe -s:z:\w2k3
rsync
Syncronize folders.
rsync --delete -az -e ssh acrobatreader acdse office2003 java nortonantivirus bjorklun@semco.homeip.net:/install/program/windows/
crontab
crontab.
* * * * * command to be executed - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59) 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday
ssh
Automated login on a user basis via ssh.
ssh-keygen -t dsa Generate personal ssh keys. cat id_dsa.pub >> authorized_keys2 Copy your personal ssh key to all machines. chmod 644 ~/.ssh/authorized_keys2 Verify correct access on files.
Tunnel ssh -nNTx -R 8728:localhost:8805 brscs20.brs.infineon.com > /dev/null 2>&1 -n Dont take console. Good for background. -N Do not execute a remote command -T Disable pseudo-tty allocation. -x Disables X11 forwarding. -R port:host:hostport
ssh -N -L 2222:www.halfface.se:22 www.halfface.se ssh -nNTx -R 2222:www.halfface.se:22 www.halfface.se
forward traffic
service x11 { disable = no socket_type = stream protocol = tcp wait = no user = root server = /usr/bin/nc server_args = 172.28.37.152 6000 }
reboot
Hard reboot mean that shutdown scripts will not run and machine reboot immediately without syncing hard disk drives, shutdown applications etc. echo 1 > /proc/sys/kernel/sysrq echo b > /proc/sysrq-trigger This commands enable sysrq and after this call fast reboot. If you want to force shutdown machine try this.
Force shutdown
echo 1 > /proc/sys/kernel/sysrq echo o > /proc/sysrq-trigger
ffmpeg
ffmpeg -y -deinterlace -aspect 16:9 -author "Andreas Bjorklund" -title "Tanzania" -year 2007 -i Tanzania.m2t -acodec mp3 -vcodec mpeg4 -b 3000k -s 720x540 test.avi
logging
bash create log.
#!/bin/bash exec > /logfile
alternative
exec 2>/tmp/log
Read logs on system.
tail -f $(lsof | grep log$ |awk '{ print $NF }' | sort -u |xargs)
rename
rename series.
for i in *; do mv "$i" "`basename $i .mpg`bajs.mpg"; done
rename series.
ls | sed 's/.*/mv & &.old/' | bash
ntfs-3g
mount ntfs filesystem. read and write.
yum install fuse fuse-libs ntfs-3g mount /dev/sda1 /media/c_drive -t ntfs-3g -r -o umask=0222,locale=en_US mount /dev/sda1 /media/c_drive -t ntfs-3g -rw -o umask=0000,locale=en_US fstab read and write. /dev/sda3 /media/e_drive ntfs-3g ro,defaults,umask=0222 0 0 /dev/sda1 /media/c_drive ntfs-3g rw,defaults,umask=0000 0 0
mplayer
mplayer in ascii mode.
mplayer -monitoraspect 4:3 -vo aa LinaFreestyler.avi
mplayer on second soundcard.
mplayer -ao oss:/dev/dsp *.mp3 mplayer -ao alsa:device=hw=0.0 *.mp3
Or, to specify a non-default (secondary) device either of the following commands can be used.
mplayer -ao oss:/dev/dsp1 *.mp3 mplayer -ao alsa:device=hw=1.0 *.mp3
play from v4l
mplayer -tv device=/dev/video:driver=v4l:input=1:width=640:height=480:norm=ntsc:adevice=/dev/dsp tv://1 -zoom -aspect 4:3
vi
:set ignorecase :set list show all keys. :set nolist show their representative.
codepage
Change codepage of file.
convmv -f cp850 -t iso-8859-1 --notest * convmv -f utf8 -t iso8859-1 -r --notest *
keyboard
keymaps dumpkeys loadkeys sv-latin1 setxkbmap en
reset corrupt keyboard after using vmware.
setxkbmap
date
date '+%Y-%m-%d %H:%M' date +%Y-%m-%d-%H%M
# date 033121422003.55 Mon Mar 31 21:42:55 PST 2003 date MMDDhhmmCCYY.ss
# date --date="+1000 years" +%C%y-%m-%d date --date="-2 hour" +%C%y-%m-%d\ %H:%M TZ=CEST date --date="-2 hour" +%C%y-%m-%d\ %H:%M
touch
touch -am 0910120003 Give a new access time on a file 0910120003MMDDhhmmyy
linux
touch -t 197102162324 *
tcpdump
dump trafic information, -e Print the link-level header on each dump line, -vvv verbose.
tcpdump -e -vvv port 21
dhclient
[root@wall sysconfig]# cat /etc/dhclient.conf
interface "eth0" { prepend domain-name-servers 127.0.0.1; supersede domain-name "bltprojektering.se"; }
search&replace
perl
grep -rsl '10.6.4.102' * | xargs perl -pi -e 's/10.6.4.102/10.6.4.103/'
sed
find . -type f -exec sed -i 's/string1/string2/g' {} \;
Grep for regexp starting with CN= and stop at first occurrence of ,.
grep -oE 'CN=[^,]*,'
pulse audio
sudo /sbin/alsactl restore
What architecture does my cpu have
lshw -class processor
command line mail with attachment
mutt -a syslogs.tar.gz admin@domain.org < /dev/null
printscreen
import -window root test.png
diff
sdiff <(echo -e 'hej\nda\nvi\nses\ni\nmorgon') <(echo -e 'hej\ndå\nvi\nSES\ni\nmorgon')
xargs
locate -ir ".*\.crt$" | xargs -i -t cp {} /temp/ssl/
sort
Sort ip address.
sort -t. +0n -1 +1n -2 +2n -3 +3n -4 <ip.list > ip.list.sort
cut
Cuf everything from field 5.
cut -f5- -d ' '
disk usage
baobab
find
Find exluding directory.
find . -wholename '/var/' -prune -o -ls
Find in only files.
find /opt/ongame/ -type f -exec grep --color=always -r '10\.7\.' /dev/null {} \;
boot
Booting singe user mode.
kernel ... single
netcat
- Check communication.
listen on port 3333.
nc -l 3333
talk to port 3333.
nc 192.168.0.1 3333
- Transfer data.
Cat file, calculate size listen on port 3333.
cat backup.iso | pv -b | nc -l 3333
Receive file.
nc 192.168.0.1 3333 | pv -b > backup.iso
grep
Colorize grep output.
grep --color=always -r '10\.7\.' /opt/ongame/