Commands: Difference between revisions

From Halfface
Jump to navigation Jump to search
Line 190: Line 190:
grep ip addresses from message file.
grep ip addresses from message file.
  sudo grep DHCP /var/log/messages | grep -oir --color=always '192\.168\.[0-9]*\.[0-9]*' | sort -u
  sudo grep DHCP /var/log/messages | grep -oir --color=always '192\.168\.[0-9]*\.[0-9]*' | sort -u
==Handbrake==
Compress dvd
#Rip dvd.
sudo vobcopy -o /storage/temp/ -v -x -l
#compress video.
HandBrakeCLI -e x264 -Z Normal -i /temp/films/PIPPI7H_SN5.vob -o /storage/temp/Pippi_soderhavet.mkv -a 1 -r 25 -E faac -f mkv -d
HandBrakeCLI -e x264 -Z Normal -i /temp/films/PIPPI7H_SN5.vob -o /storage/temp/Pippi_soderhavet_small.mkv -a 1 -r 25 -E faac -f mkv -d -S 600


==keyboard==
==keyboard==

Revision as of 05:34, 8 April 2010

arecord

List soundcards.

arecord -l

Chose source.

alsamixer

Create mp3 from source.

arecord -f cd -d 5 -t raw | lame -x -r - out.mp3

boot

Booting singe user mode.

kernel ... single

bootchart

Analyze startup times.

bootgraph

How to use.

Kernel later than 2.6.28
kernel option initcall_debug
dmesg | /usr/src/linux-headers-2.6.28-11-generic/scripts/bootgraph.pl > /tmp/bootgraph.svg

chattr/lsattr

Set extendet attributes of files.

Lock file for most activities.
chattr +i file
Unlock file
chattr -i file

clean

Clean file from comments and blank lines.

sed '/ *#/d; /^ *$/d'

codepage

Change codepage of file.

convmv -f cp850 -t iso-8859-1 --notest *
convmv -f utf8 -t iso8859-1 -r --notest *

cpio

Copy wanted partitions.

#!/bin/bash
ssh root@192.168.2.148 "(cd /boot/ ; find ./ -xdev -depth -print0 | cpio -o -0Hnewc )" | (cd /mnt/sysimage/boot ; cpio -idvuma )
ssh root@192.168.2.148 "(cd / ; find ./ -xdev -depth -print0 | cpio -o -0Hnewc)" | (cd /mnt/sysimage ; cpio -idvuma )
# -o copy out mode.
# -0 terminated by null character.
# -Hnewc som storing format.
# -i extract copy in mode.
# -d make directories.
# -v verbose.
# -V print dot.
# -u replace all files.
# -m preserve modification time.
# -a preserve access time.

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

Run command every 10 minutes.

*/10 * * * * command

Start program under crontab.

#!/bin/bash
COMMAND="screen -L -d -m ping www.dn.se"
if [ "$(ps -ef | grep -i ping | grep -v grep)" ]
then
  echo "\"${COMMAND}\" already running."
else
  echo "Starting \"${COMMAND}\"."
  cd /tmp
  ${COMMAND}
fi

cut

Cuf everything from field 5.

cut -f5- -d ' '

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

dd

output your microphone to a remote computer's speaker

dd if=/dev/dsp | ssh -c arcfour -C username@host dd of=/dev/dsp

dhclient

[root@wall sysconfig]# cat /etc/dhclient.conf

interface "eth0" {
         prepend domain-name-servers 127.0.0.1;
         supersede domain-name "bltprojektering.se";
}

diff

sdiff <(echo -e 'hej\nda\nvi\nses\ni\nmorgon') <(echo -e 'hej\ndå\nvi\nSES\ni\nmorgon')

which files differ between servers.

rsync -nrlptDqv --delete --exclude napsjb/server/naps/tmp/ /opt/ongame/ 10.6.21.11:/opt/ongame | less
-n dry run.
-r recursive
-l copy symlinks av symlinks.
-p preserve permission
-t preserve tims.
-D --device --special. Keep special files.
-q quiet
-v verbose

disk

disk usage

baobab

foremost

recover deleted files.

display

Change resolution

xrandr --output LVDS --mode 1280x800
xrandr --output default --mode 1280x1024

Query graphics card capabilities.

xrandr -q

dvgrab

Capture dv material

dvgrab -f dv2 -i -showstatus -s 0 -timestamp California-2

e2fsck

Scan for bad blocks.

e2fsck -ycv /dev/VolGroup00/LogVol00

edid/ddc

startx -- -logverbose 5.
The EDID information turns up in /var/log/Xorg.0.log.

encryption

Simple encryption decryption.

gpg -c --force-mdc /temp/shadow
echo "$(gpg -qd /temp/shadow.gpg)"

ffmpeg

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

Create swf/flv from mpeg2 stream

ffmpeg -deinterlace -i VTS_01_1.VOB -ab 56 -ar 22050 -b 500000 -r 15 -s 360x288  sisyfos.swf

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 {} \;

Find text file in directoy execpt directory. Grep for text in that file and show it with colours in less.

find /opt/ongame/ -wholename '/opt/ongame/napsjb/server/naps/tmp' -prune -o -type f -exec grep --color=always -r '/fraud' /dev/null {} \; | less -SR

Find excluding svn.

find . -path '*/.svn' -prune -o -type f -print

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
}

gphoto2

Capture photo from the command line linux.

gphoto2 --camera='Canon EOS 40D (PTP mode)' --port=usb: --capture-image-and-download

grep

Colorize grep output.

grep --color=always -r '10\.7\.' /opt/ongame/

Show non comment lines ending with a blank.

find . -name '*.properties' -exec grep --color=always -E '^[^#].*\ $' {} \; | less -SR

grep ip addresses from message file.

sudo grep DHCP /var/log/messages | grep -oir --color=always '192\.168\.[0-9]*\.[0-9]*' | sort -u

Handbrake

Compress dvd

  1. Rip dvd.
sudo vobcopy -o /storage/temp/ -v -x -l
  1. compress video.
HandBrakeCLI -e x264 -Z Normal -i /temp/films/PIPPI7H_SN5.vob -o /storage/temp/Pippi_soderhavet.mkv -a 1 -r 25 -E faac -f mkv -d
HandBrakeCLI -e x264 -Z Normal -i /temp/films/PIPPI7H_SN5.vob -o /storage/temp/Pippi_soderhavet_small.mkv -a 1 -r 25 -E faac -f mkv -d -S 600

keyboard

keymaps 
dumpkeys
loadkeys sv-latin1
setxkbmap en

reset corrupt keyboard after using vmware.

setxkbmap

kill

suspend/resume a jobb.

# kill -STOP PID
# kill -CONT PID

lastb

Show failed ssh logins.

lastb

locale

To show 24 hour format.

LC_ALL=C

lock

locking keyboard under linux.

lock-keyboard-for-baby

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)

lshw

Is cpu 32 or 64bit.

lshw -class processor

mail

Put the followin in .muttrc to change From.

set realname="Joe User"
set from="user@host"
set use_from=yes

command line mail with attachment

mutt -s subject -a syslogs.tar.gz admin@domain.org < /dev/null

command line mail with changed from

echo -en "\nAndreas is playing\nwith mail\nPlease take care." | /bin/mail -s "Subject written by Andreas" "andreas.bjorklund@company.org" -- -f "andreas.bjorklund@company.org"
echo "#MESSAGES# This is the message. #MESSAGE#" | mailx -s "#SUBJECT# This is the subject. #SUBJECT#" 0XXXXXXX@sms.tele2.se -- -r anden@halfface.se

man

man correct caracters.

LANG=C man passwd

man clean for output to file.

man [manual] | col -b > file.txt

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

mkfs

Create fat32 file system.

mkfs.vfat -F 32 /dev/sdc1

mogrify

Resize, crop... a file. Removes original.

mogrify -resize 800 *.jpg

mount

Mount a temporary ram partit

mount -t tmpfs tmpfs /mnt -o size=1024

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
mplayer -fps 15 tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0play hdv material.
mplayer -monitoraspect 16:9 -vf pp=lb

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
  • Setup telnet server
nc -L -l -p1234 -d -e cmd.exe
  • Test connection.
nc -w2 -znv 10.1.22.31 7222
  • tunnel

On the server, we open a listener on the TCP port 6667 which will forward data to UDP port 53 of a specified IP. If you want to do DNS forwarding like me, you can take the first nameserver's IP you will find in /etc/resolv.conf - in this example, this is 192.168.1.1. But first, we need to create a fifo. The fifo is necessary to have two-way communication between the two channels. A simple shell pipe would only communicate left process' standard output to right process' standard input.

mkfifo /tmp/fifo
nc -l -p 6667 < /tmp/fifo | nc -u 192.168.1.1 53 > /tmp/fifo

nmap

Scan for open ssh ports.

nmap -p 22 --open -sV 10.0.0.0

nohup

Start binary under nohup and tail log.

nohup ./run.sh & sleep 1 ; tail -1000f nohup.out

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

numbers

series of numbers

bash:
echo {1..10}

password cracking

hydra -l root -P /etc/passwdknown -t 5 192.168.29.62 ssh2

patch

Update release area Windows.

servicepack.exe -s:z:\w2k3

postfix

remove mails in queue.

mailq 2>&1 | grep ^[A-F0-9] | awk '{print $1}' | postsuper -d -

printscreen

import -window root test.png

/proc

  • /proc/meminfo

MemTotal — Total amount of physical RAM, in kilobytes.

MemFree — The amount of physical RAM, in kilobytes, left unused by the system.

Buffers — The amount of physical RAM, in kilobytes, used for file buffers.

Cached — The amount of physical RAM, in kilobytes, used as cache memory.

SwapCached — The amount of swap, in kilobytes, used as cache memory.

Active — The total amount of buffer or page cache memory, in kilobytes, that is in active use. This is memory that has been recently used and is usually not reclaimed for other purposes.

Inactive — The total amount of buffer or page cache memory, in kilobytes, that are free and available. This is memory that has not been recently used and can be reclaimed for other purposes.

HighTotal and HighFree — The total and free amount of memory, in kilobytes, that is not directly mapped into kernel space. The HighTotal value can vary based on the type of kernel used.

LowTotal and LowFree — The total and free amount of memory, in kilobytes, that is directly mapped into kernel space. The LowTotal value can vary based on the type of kernel used.

SwapTotal — The total amount of swap available, in kilobytes.

SwapFree — The total amount of swap free, in kilobytes.

Dirty — The total amount of memory, in kilobytes, waiting to be written back to the disk.

Writeback — The total amount of memory, in kilobytes, actively being written back to the disk.

Mapped — The total amount of memory, in kilobytes, which have been used to map devices, files, or libraries using the mmap command.

Slab — The total amount of memory, in kilobytes, used by the kernel to cache data structures for its own use.

Committed_AS — The total amount of memory, in kilobytes, estimated to complete the workload. This value represents the worst case scenario value, and also includes swap memory.

PageTables — The total amount of memory, in kilobytes, dedicated to the lowest page table level.

VMallocTotal — The total amount of memory, in kilobytes, of total allocated virtual address space.

VMallocUsed — The total amount of memory, in kilobytes, of used virtual address space.

VMallocChunk — The largest contiguous block of memory, in kilobytes, of available virtual address space.

HugePages_Total — The total number of hugepages for the system. The number is derived by dividing Hugepagesize by the megabytes set aside for hugepages specified in /proc/sys/vm/hugetlb_pool. This statistic only appears on the x86, Itanium, and AMD64 architectures.

HugePages_Free — The total number of hugepages available for the system. This statistic only appears on the x86, Itanium, and AMD64 architectures.

Hugepagesize — The size for each hugepages unit in kilobytes. By default, the value is 4096 KB on uniprocessor kernels for 32 bit architectures. For SMP, hugemem kernels, and AMD64, the default is 2048 KB. For Itanium architectures, the default is 262144 KB. This statistic only appears on the x86, Itanium, and AMD64 architectures.

ps

Process list in tree view.

ps axfww

Process list sorted after memory usage.

ps aux --sort=size

pulse audio

sudo /sbin/alsactl restore

putty

set up tunnel

putty -l bjorklun -pw password -L 19242:192.168.0.42:3389 blt.homeip.net

rename

Recursive lowercase to uppercase

for i in $(find * -depth); do (mv $i $(echo $i | sed 's%[^/][^/]*$%%')$(echo $i | sed 's!.*/!!' | tr [:upper:] [:lower:])); done

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

route

The route to a network is behind 10.111.222.7

route add -net 10.111.223.0 netmask 255.255.255.0 gw 10.111.222.7

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 ~/.rpmmacros

%_query_all_fmt         %%{name}-%%{version}-%%{release}.%%{arch}

List only name of installed rpms.

rpm -qa --qf "%{NAME}\n"

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

screen

Start program in screen.

screen -d -m 

rsync

Syncronize folders. Delete non existing files on remote host. Compress.

rsync --delete -az -e ssh bjorklun@semco.homeip.net:/install/program/windows/

Syncronize files over ssh on port 2222. Show progress. Syncronize even empty directories.

rsync -Pae 'ssh -p 2222' localhost:/opt/techops/bin/ /opt/techops/bin/

Run rsync in both ends but transfer data with normal user.

sudo rsync -aP /tmp/andreas/ andreasbj@localhost:/tmp/andreas2/ --rsync-path='sudo rsync'

sar

Old sar information.

sar -f /var/log/sa/sa25 -s 00:00:00 -e 23:59:00

load average.

sar -q -f /var/log/sa/sa25 -s 00:00:00 -e 23:59:00

All information.

sar -A -f /var/log/sa/sa25 -s 00:00:00 -e 23:59:00

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=[^,]*,'

sms

Mail to sms gateway.

tele2
07XXXXXXXX@sms.tele2.se
Comviq
467xxxxxxxx@sms.comviq.se
Europolitan
4670xxxxxxx@europolitan.se

snmpwalk

Get information from an oid.

snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.84

sort

Sort ip address.

sort -t. +0n -1 +1n -2 +2n -3 +3n -4 <ip.list > ip.list.sort

ssh

Automated login on a user basis via ssh.

ssh-keygen -t dsa                    Generate personal ssh keys.
cat id_dsa.pub >> authorized_keys   Copy your personal ssh key to all machines.
chmod 644 ~/.ssh/authorized_keys    Verify correct access on files.
ssh andreasbj@www.halfface.se "cat >> ~/.ssh/authorized_keys" <  /home/andreasbj/.ssh/id_dsa.pub

Copy public key to authorized_keys

ssh-copy-id user@host

Tunnel

sudo ssh -nNTx -R 2222:localhost:22 andreasbj@www.halfface.se
-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
sudo ssh -N -L 2222:www.halfface.se:22 www.halfface.se
sudo ssh -nNTx -R 2222:www.halfface.se:22 www.halfface.se
sudo ssh -nNTx -R 443:satellite.ongame.com:443 root@10.0.254.30 # Tunnel 443 over ssh from remote host via local host.

Limit ssh access with pam_access

/etc/security/access.conf

mount filesystem over ssh

sshfs name@server:/path/to/folder /path/to/mount/point

tar

Make a backup of a directory or disk.

server: tar -cpsf - $dir | pv -b | nc -l 3333
client: nc server 3333 | pv -b | tar -xpst -

tcpdump

dump trafic information, -e Print the link-level header on each dump line, -vvv verbose.

tcpdump -e -vvv port 21

dump all trafic to and from machine. -w write to file, -s0 size of package, host to listen from.

time tcpdump -w ssl_dump -s0 host test.x30.webservices.itsfogo.com

dump all trafic into files of max 100MB. 270MB in reality.

sudo tcpdump -w snoop -s0 -C 100000000

dump all trafic. compress logfiles. Create 10 files which are 10 MB big. Dont convert numbers to names. Dont truncate frames create logfile with this name.

sudo tcpdump -z gzip -i wlan0 -C 10 -W 10 -n -s0 -w /tmp/tcpdump.log

top derivates

apachetop
dnstop
iftop
latencytop

top over time.

vmstat 2 -n

touch

touch -am 0910120003    Give a new access time on a file 0910120003MMDDhhmmyy

linux

touch -t 197102162324 *

unetbootin

Boot iso image from usb memory.

vi

:set ignorecase
:set list        show all keys.
:set nolist      show their representative.

xargs

locate -ir ".*\.crt$" | xargs -i -t cp {} /temp/ssl/

zip

Zip directory exclude files .svn directory.

zip -r /temp/ssl.zip . -x ".svn/*"

zdump

View information from timezone tz.

zdump -v /etc/localtime