List of quick reference commands compiled from several sources and consolidated for reference purpose

-- To list file with line number

nl 

-- Saves man pages to text

man cat | col -b > less.txt  

-- Mounting as a loop device

mount -o loop -t iso9660 /FC2-i386-DVD.iso  /iso 

-- To split a large file into multiple files

split --bytes 1m bigfile 1_ 

-- List of open files opened by raj under /dev/hda1

lsof -u raj -a /dev/hda1  

-- Find process who owns the port number

fuser -v -n tcp 992345   

-- List of users accessing the /mnt file, -k option to kill all using the FS

fuser -v /mnt/*    

-- Trace System calls

strace -aef cat afile

-- Run Top in batch file

top -b -d 5 -n 3 >> top.out  
b=batch, d=delay in seconds , n=number of iterations

-- To read headers of binary files (ELF)

readelf --file-header /bin/ls    

-- List all network services running

netstat -tanup    

-- List listening interfaces

netstat -l     

-- Shread and remove a file

shred -n 50 -zuv afile
n=shred the file "n" times, -z will zero out the file in the last pass (extra protection), u=truncate it every time, v=verbose.

-- Command line calculator

echo "10/2*10" | bc -l   

-- Search man pages for string

man -k string   

-- Merge pdf files into one

gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Merged.pdf -dBATCH img*.pdf

-- Create pdf file from man page

man -t cat | ps2pdf - > cat.pdf

-- Colors the string while grepping

grep --color string filename   

-- Copy files between Servers using netcat (Alternate option to consider if ftp is disabled ). On the server listening port 3333 is created and dummy.dat is tar'd. When netcat is executed with no default options, it basically connects to the server/port specified.

On Server (in my case host graphics) run
   tar -cvjf - dummy.dat | netcat -l -p 3333
On the Client ( in my case it was silicon) run
   netcat graphics 3333 | pv -b | tar -xjvf 

-- Rsync files between servers

silicon~> rsync -avrz . --include "init*.ora" --rsh='ssh' graphics:/usr/oracle/admin
Above syncs all init.ora files from silicon to graphics a=archive,v=verbose,r=recursive,z=compress 

-- Test FTP Speed. Use dd to create a large file, but instead of sending it to the disk send it to null device. Here

/dev/zero is the input and output of the dd is /dev/null. 
put "|dd if=/dev/zero bs=1024 count=1000000" /dev/null

-- Find all files with group owner is "oracle" and change it to "dba" group.

find . -group oracle -exec chgrp dba '{}' \ ;

-- Show files greater than a specific size

find ./ -size +10M -type f -print0 | xargs -0 ls -Ssh1 --color

-- Send e-mail attachments with mutt

mutt -a file.txt -s "A Text File" raj.anju@gmail.com < /tmp/junk

-- Kill multiple processes in one shot

ps -ef|grep dbconsole | awk ' { print $2} ' | xargs kill -9 
pkill -f dbconsole

-- Improve ftp speed with jumbo frames. Note: Read more on the Jumbo frames, as its applicable only on certain situations. On a 10/100 data the max mtu can only be upto 1500, but for a GigaBit Ethernet connection it can go upto 9000. The best throughput I got while doing an XO (Cross-Over) connection between two systems is when the mtu was 6000.


ifconfig eth0 mtu 6000

For a permanent change you have to edit the below file to include MTU 6000
/etc/sysconfig/network-script/ifcfg-eth0

-- Measure disk preformance using dd



Determine the total RAM size ():

[root@rbnetapp ~]# grep MemTotal /proc/meminfo
MemTotal:        1534352 kB


Determine the value of "count": = "memTotal" / 1024  + 1

[root@rbnetapp ~]# echo "`cat /proc/meminfo | grep MemTotal | awk '{print $2}' ` / 1024 + 1 " | bc -l
1499.39062500000000000000

count = 1498

Issue the dd command, with the calculated value of "count":

dd if=/dev/zero of=/u01/disperf.dat bs=1M count=1498 conv=fdatasync; 
dd if=/u01/disperf.dat of=/dev/null bs=1M count=1498; 

-- Write Speed
[root@rbnetapp ~]# dd if=/dev/zero of=/u01/disperf.dat bs=1M count=1498 conv=fdatasync;
1498+0 records in
1498+0 records out
1570766848 bytes (1.6 GB) copied, 3.73213 s, 421 MB/s

-- Read Speed
[root@rbnetapp ~]# dd if=/u01/disperf.dat of=/dev/null bs=1M count=1498;
1498+0 records in
1498+0 records out
1570766848 bytes (1.6 GB) copied, 1.86999 s, 840 MB/s