linux general tips

 Memory

-> memory usage per process
---------------------------------------------------------------
ps -eo pid,ppid,rss,vsize,pcpu,pmem,cmd -ww --sort=pid
or
run top
press SHIT+f
choose n (memory)
:)
------------------------------------------------------------

-> free mem
------------------------------
# free -m will show in mb
# use also vmstat
-----------------------

-> show process tree
-----------------------
pstree
or
pstree -p
------------------------


-> bash

-> howto become a root, do something, and exit with bash script
------------------------------------------------------
#!/bin/bash
echo "i am root"
su noch -c "echo alalala ; whoami; exit";
echo "i am root again"
whoami
----------------------------

-> howto debug bash script

------------------------
add following line in the script

set -o xtrace
-------------------


-> finding files from plain console without mc
----------------------------------------------
for instance grep in header files for some word
find . -name \*.h | xargs grep your_word
---------------------------------------------

-> last logged in users
-----------------------------------------
last command reads list from /var/log/mwtmp
--------------------------------------------

-> debug and trace
-------------------
strace -p pid
strace -s 200 elffilename to intercept system calls, -s 200 for string length
ltrace elffilename
--------------------------------------------

-> howto run program in bash and keep it running even when terminal closed
-------------------------------------------------------
$ nohup script &
-----------------------------------------------------

-> Console screensaver
----------------------------------------
setterm -blank 0 to disable it
------------------------------------------

-> at
-----------------------------
at 9:15 playcd
at 9:15 mpg123 *
atq - to list programmed jobs
atrm number to delete automatic job with that number
------------------------------

-> making patches
------------------------------------
diff -u oldfile.c newfile.c > file.patch
------------------------------------

-> applying patches
-----------------------------------
patch file.c file.patch
----------------------------------


-> Change the first occurence of stringA in filename file to stringB and saves it in a new file :)
-----------------------------------------------
sed 's/stringA/StringB/' filename > newfilename
----------------------------------------------

-> Change all the occurences of stringA to stringB in filename :)
----------------------------------------------------------
sed 's/stringA/stringB/g' filename > newfilename
--------------------------------------------------

-> Line count, word count and byte count for the file
----------------------------------------------------
wc file 
---------------------------

-> Compress folder with zip
---------------------------------
zip -r filename.zip folder
--------------------------------

-> Resize image
-----------------------------------
man montage
convert -resize 800x600 original.jpg modified.jpg
---------------------

-> Time setup
------------------------
date -s 10/13/00

month, day, year

date -s 07:13:30

To change time without spoling date
date -s "month/day/year" + "%D"
date -s "12:00:00" + "%T"

rdate -p ntp.nasa.gov - show the server date and time
rdate -s ntp.nasa.gov synchronize with that server
---------------------------------

-> adding user to group
-------------------------
gpasswd -a user group
usermod -G group1, group2  user
This one could not work with ldap users
---------------------------

-> deleting user from a group
------------------------
gpasswd -d user group
-------------------------


networking

-> slip networking via null modem cable
---------------------------------------
connect-server.sh

#!/bin/bash
slattach -s 115200 -p slip /dev/ttyS0 &
sleep 3s;
ifconfig sl0 192.168.0.2 pointopoint 192.168.0.1
route add -host 192.168.0.1 dev sl0
iptables -t nat -A POSTROUTING -p ALL -s 192.168.0.1/24 -d 0/0 -j MASQUERADE


connect-client.sh

#!/bin/bash
slattach -s 115200 -p slip /dev/ttyS0 &
sleep 3s;
ifconfig sl0 192.168.0.1 pointopoint 192.168.0.2
route add -host 192.168.0.2 dev sl0
route add -net 0.0.0.0/0 dev sl0
rm -rf /etc/resolv.conf
# lycos-europe.am dns server
echo "nameserver 10.37.12.3" >> /etc/resolv.conf
# xternet.am dns servers
#echo "nameserver 83.217.224.37" >> /etc/resolv.conf
#echo "nameserver 83.217.224.35" >> /etc/resolv.conf
#lycos dns route
route add -host 10.37.12.3 dev sl0
#xternet dns route
#route add -host 83.217.224.37 dev sl0
---------------------------------------

-> netstat
------------------------
# netstat -lnp --ip will display current running daemons
# netstat --anp --inet
----------------------

-> when nfs mount is too long
----------------------------
mount -t nfs -o nolock
-------------------

-> samba mount
--------------------------------------------------------------------------------
from /etc/fstab

//public/install        /network/public/install smbfs
credentials=/etc/samba/credentials/noch,uid=1000,gid=1000,fmask=0644,dmask=0755,workgroup=somedomainname

or worst variant with open password in fstab, not recommended:

//public/films               /mnt/samba      smbfs   
user,rw,iocharset=utf8,uid=500,gid=500,fmask=775,dmask=775,password=yourpassword,username=domainusername,workgroup=domainname,debug=4 
0 0

cat /etc/samba/credentials/noch
username=noch
password=IHAVECOOLPASSWORD

from console:

mount -t smbfs //public/films /mnt/samba -o 
credentials=/etc/samba/credentials/noch
-----------------------------------------------------------------------------------

-> Secure file copy
-------------------------------------
scp /path/to/sourcefile username@server:/path/to/destinationfile
---------------------------------------------------------------

-> wget howto download a site
-----------------------------------------
wget -rl 4 http://someurl
httrack -P proxy.domain.com:8080 -%f ftp://ftp.simtel.net/pub/simtelnet/msdos/turbopas/*
httrack -mirror http://something.stupid
-----------------------------------------

X

-> howto configure x server
----------------------------
Xorg -configure
if error then
xorgconfig

in debian: dexconf

in gentoo: mkxf86config
---------------------------


-> wheel mouse in xorg config:
-----------------------------
Section "InputDevice"
        Identifier  "Mouse0"
        Driver      "mouse"
        Option      "Protocol" "ImPS/2"
        Option      "ZAxisMapping" "4 5"
        Option      "Buttons"      "5"
        Option      "Device" "/dev/input/mice"
------------------------------


-> lefthanded mouse
---------------------------
xmodmap -pp
xmodmap -e "pointer = 3 2 1"
or
xmodmap -e "pointer = 3 2 1 4 5"

that depend on your mouse type :)
------------------------------

-> armenian and russian in plain x without some keyboard switcher
-----------------------------------------------------------
following lines should work with all xorg x11 servers
setxkbmap "us, am(phonetic)" -option 
"grp:alt_shift_toggle,grp_led:scroll"
setxkbmap "us, ru(phonetic)" -option 
"grp:alt_shift_toggle,grp_led:scroll"
--------------------------------------

Drives
--------------------------------
insert cd
# eject -t

#hdaprm -tT /dev/hda - time benchmark

#hdparm -d 1 /dev/hda - set ultradma access using_dma to 1
----------------------------------

howto assign a label to partition
-------------------------
man e2label :)
----------------------


Multimedia

-> zoran card in redhat/fedora system
--------------------------------
options zr36067 card=1 //card number one is new miro vard like drx
alias char-major-81 zr36067
--------------------------------

-> if you connected your firewire camera, but can't use it with computer

mknod -m 0666 /dev/raw1394 c 171 0
mknod -m 0666 /dev/video1394 c 172 0

-> capturing old standard avi with miro capture board
---------------------------
lavrec -i p -w -f a -d 1 -q 36 -a 16 -r 44100 -l -1 -R l -c 2 -t 100000 
-T 1 -n
32 -b 256 -s --use-read --max-file-size 1900 
/home/norik/Desktop/%09d.avi
----------------------------

-> convert to vcd or svcd compliant mpeg file with mencoder
----------------------------
pass one:
mencoder $1 $2 $3 -ofps 25.00 -aid 1 -oac lavc -of mpeg -ovc lavc 
-lavcopts 
vcodec=mpeg1video:keyint=12:aspect=4/3:mbd=2:acodec=mp2:abitrate=224:vbitrate=1152:vrc_buf_size=327:vrc_maxrate=1152:vpass=1 
-vf scale=352:288,expand=352:288 -srate 44100 -o /dev/null
pass two:
mencoder $1 $2 $3 -ofps 25.00 -aid 1 -oac lavc -of mpeg -ovc lavc 
-lavcopts 
vcodec=mpeg1video:keyint=12:aspect=4/3:mbd=2:acodec=mp2:abitrate=224:vbitrate=1152:vrc_buf_size=327:vrc_maxrate=1152:vpass=2 
-vf scale=352:288,expand=352:288 -srate 44100 -o $1.tmp.mpeg
dvb-mplex -t VCD -o $1.mpeg $1.tmp.mpeg
-------------------------------------

-> convert to dvd compliant  mpeg2 with mjpegtools
-----------------------------
lav2yuv $1 | yuvscaler -O DVD | mpeg2enc -f 8 -q 4 -s -o video_tmp.m2v
lav2wav $1 | mp2enc -v 2 -b 224 -r 48000 -s -o sound_tmp.mp2
mplex -f 8 sound_tmp.mp2 video_tmp.m2v -o $1-dvd.mpg
----------------------------

-> rebuilding avi file index
-------------------------------------------
mencoder -ovc copy -ni -noodml -forceidx -of avi -noodml -oac pcm 
000000001.avi -o 1.avi
-------------------------------------------

-> writing vcd, svcd, with cdrdao
------------------------------------
vcdimager -t svcd 1.mpg 2.mpg 3.mpg
cdrecord -scanbus
if got 1,0,0
cdrdao write --device 1,0,0 --driver generic-mmc --speed 4 videocd.cue
------------------------------------

-> howto extract mpeg2 file from dvd
--------------------------------------
mencoder dvd:// -ovc copy -oac copy -aid audionumber -sid subtitlenumber -of mpeg -o some.mpg

-> how to  start kylix3 under modern linux distributions
-------------------------------
export LD_ASSUME_KERNEL=2.2.5
echo 1 > /proc/sys/vm/legacy_va_layout
startkylix
-------------------------------

-> mpg123
-------------------------------
mpg123 -q /folder/*.mp3 &
---------------------------

      Emulation
      
-> qemu

$ qemu-img create bb.img 100M
Formating 'bb.img', fmt=raw, size=102400 kB 
$ qemu -M pc -hda bb.img -cdrom /home/noch/iso/bluebottle/Aos.iso -boot d -m 64
 where -boot d boots from cdrom and -boot c boots from harddisk ;)      

qemu networking
make sure you compiled your kernel (2.6) with following options

 Device Drivers  --->   
      Network device support  --->   
             Universal TUN/TAP device driver support   

Then 
mdir -p /dev/net (if not exists)
mknod /dev/net/tun c 10 200

modprobe tun
echo "tun" >> /etc/modules (if debian)

if only root can access tun device then

chgrp users /dev/net/tun
chmod g+w /dev/net/tun

config

ifconfig tun0 192.168.0.1 up

configure your qemu system to have 102.168.0.2 ip address

now routing
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo "1" >/proc/sys/net/ipv4/ip_forward

that's all :)


-> reread partition table without reboot :)
------------------------------------
apt-get install parted
# partprobe
--------------------

:)


    Source: geocities.com/n0rayr/tips/unix

               ( geocities.com/n0rayr/tips)                   ( geocities.com/n0rayr)