Saturday, November 29, 2008

Useful Unix Commands..

1. Trim space and replace it with add new line?
cat file |  tr -s ' ' '\n' ..redirect output into a file
2. Opening remote file through Vim
 vim scp://root@74.125.45.100//root/harendra_file.txt
3. Printer command to print
 lpr -Pprintername file 
 lp -dprintername file
4. Write a command to kill the last background job?
 kill $!
5. Write a command to print success/failure of last executed command?
 echo $?
6. To mount disk
 mount /dev/sda5 /data/
 mount /dev/sda1 /mnt/winxp/
7. Putting an entry in crontab
crontab -e
* * * * * /sbin/ifconfig eth0 arp
* * * * * /sbin/ifconfig eth1 arp
8. adding welcome message when ssh 
 /etc/motd
9. To set date on system
date monthdayhourminutyear
date 010100302000
 or
============================
date - Would list the date and time of the server. Below is an example of the output.

Thu Feb 8 16:47:32 MST 2001
date -s "11/20/2003 12:48:00" - Set the date to the date and time shown.

date '+DATE: %m/%d/%y%nTIME:%H:%M:%S' - Would list the time and date in the below format:

    DATE: 02/08/01
    TIME:16:44:55
=============================
10. extracting/list/zip a file file1 from tgz File.tgz
 tar -xz file1 -f File.tgz
 tar -tzvf File.tgz
 tar -czvf File.tgz
 tar -xzvf File.tgz
11. Allowing all incoming packets
iptables -I INPUT -j ACCEPT
12. Printing.. required librabies for an executable 
ldd ./sipp_tls
13. Printing disk uses
du -chS
14. alsamixer volume controller for linux
alsamixer //volume controller
15. Adding route manually
route add -net 172.16.26.0/24 gw 192.168.0.101
16. pearl command to replace a string in a file
perl -pi -e 's/svk//' `find . -name Root`
perl -pi -e 's/svk@bilbo:2/harendra@172.16.45.102:9/' `find . -name Root`
17. write a message for users connected with different terminals.
wall and ctrl-d
18.  command to kill a process by a signal. 
pkill -USR1 -x tgist
19. tethereal command 
tethereal -i any -R "sip||h225||h245||q931" -S -w file.cap -b file:5 -a filesize:500
20. To print interface details using snmp walk.
snmpbulkwalk -r 1 -Oe -Ot -v 2c -c public localhost ifTable
21. Running valgrind command for memcheck.
valgrind --tool=memcheck --leak-check=full --leak-resolution=high --show-reachable=yes --num-callers=20 --log-file-exactly=/var/log/valg.log --error-limit=no -v ./tgist
22. On fedora Linux starting a service at startup time, list the services
    #chkconfig --add servicename
    #chkconfig --level 2345 servicename [on|off|]
   #chkconfig --list
23. Redirecting output, error to a file on fedora linux
   command &> filename
  command > filename 2 > &1



No comments: