Thursday, July 26, 2007

50 quick linux command tips part 1

I have compiled several linux CLI basic tips and quick tricks that solves simple issues of daily routines and objectives. Most probably they are most commonly used by others too, but who knows?

Here are a few old tricks and linux workarounds that still works with Fedora distro and probably works with CentOS and RedHat.

These commands were all done as super user root. I suggest not to try this if you don't know what the command is for, use at your own risk!!!

1. How to create a return email address when using mutt ?

# export REPLYTO=youremail@yourdomain.com

2. How to dump a website into your terminal screen ?

# elinks -dump "http://www.gmanews.tv/forex.php"
# lynx -dump "http://www.gmanews.tv/forex.php"
# links -dump "http://www.gmanews.tv/forex.php"

3. How to dump a website into a file ?

# elinks -dump "http://www.gmanews.tv/forex.php" > file1
# lynx -dump "http://www.gmanews.tv/forex.php" > file2
# links -dump "http://www.gmanews.tv/forex.php" > file3

3. How to sort batch of files containing alpha numeric characters in a file with one command ?

# cat filename101*.txt | sort -n

4. How to remove duplicate lines from a file ?

# uniq < filename01.txt

5. How to force rotate of all your defined log files located in /var/log/ ?

# logrotate -f /etc/logrotate.conf

6. How to change the interval time of your daily and weekly system cron jobs ?

# vi /etc/anacrontab

7. How to start X / Gnome from terminal ?

# startx

8. How to do a whole new xorg.conf setup for your nonworking/epileptic X which was caused recent xorg.conf misconfiguration ?

# mv /etc/X11/xorg.conf /etc/X11/xorg.conf.old
# gdmsetup

9. Do you have a very old and nice webtool for newbies or junior system admins?

Click here

10. How to launch and run a program into background ?

# program-name &

10. How to locate and find file(s) in CLI ?

# find /foldername -name name-of-file

Ex.
# find /home -name *vertito*
# locate *vertito*

11. For script kiddies who successfully hacked a box, LOL. How to know your current dropped user, shell id, group id, groups your shell belongs to after successfully hacking into a linux box? :)

# id

12. How to know who is currently active from ssh connection from your server ?

# w

13. How to know all your opened UDP ports and connections ?

# ss -u -a

14. What are the most commonly known world writeable and readable folders?

# cd /tmp
# cd /dev/shm

So watch out for any scripts or file changes there!

15. How to build rpm package from source file (*.src.rpm) ?

# rpmbuild --rebuild *.src.rpm

Most probably, you'll find the sources in /root/rpmbuild/SOURCES and the RPM file in /root/rpmbuild/RPMS . If not, try /usr/src/redhat/SOURCES and /usr/src/redhat/RPMS

16. How to find all files from a particular folder that contains this string and do it recursively ?

# find /home/vertito -exec grep -li myownstring {} \;

17. How to find a specific filename and delete it ?

# find / -name specific-filename.txt -exec rm -rf {} \;

18. How to trim my temporary files and delete the ones that are more than 1 month old?

# find /tmp -mtime +31 -exec rm -rf {} \;

19. How to know the descriptions, functions, and more info a a linux command ?
Ex.

# man elinks
# apropos elinks
# whatis elinks
# info elinks

20. How to know from which rpm package does a particular library belongs to ?

Ex. /lib/libcap.so

# rpm -qf /lib/libcap.so

21. How to find out interesting port of a particular host ?

# nmap host-IP-Address-here

22. How to ping one subnet class of IP address or group of IP address ?

# fping -g 192.168.100.0/27
$ fping -g 192.168.1.1 192.168.1.254

23. How to know if a port is open ?

Example: port 25

# telnet IP-address 25
# nc -dz IP-address 25

24. How to watch for file and file size changes of one folder live and not by email ?

# cd your-folder
# watch ls -la


25. How to divide 9999999999999999 by 3 directly from terminal ?
How to use a terminal based calculator?

# echo '9999999999999999/3' | bc -l




26. How to print line numbers of each output line of a text file ?

# cat -n yourfile.txt

27. How to negate a grep result?

# grep -v "null" yourfilename

28. How to list statistics from your network ?

# netstat -s

29. What is the country code for a particular country ?

# grep -i philippines /usr/share/zoneinfo/iso3166.tab

30. How to find out who owns and manages a particular domain ?

# whois google.com

31. How to get the resolved IP of a domain ?

# nslookup google.com
# host google.com
# dig google.com

32. How to say hello and goodbye to your system log file ?

# logger 'Hello and Goodbye'

33. How to list out all your USB current connections ?

# lsusb
verbose
# lsusb -v

34. How to list out all your PCI card connections ?

# lspci
verbose
# lspci -v

35. How to lock/unlock a bash enabled user shell account ?

# passwd -l useraccount
# passwd -u useraccount
# passwd -S useraccount

36. How to limit and change available shell accounts for user's shell assignment ?

# vi /etc/shells

37. How to change the default values when adding new user accounts ?

# vi /etc/default/useradd

38. How to create default files automatically every time a new user accounts is created ?

# cp /home/vertito/whateverfile.txt /etc/skel
# useradd -d /home/newuser newuser

39. How to go the easy way to home folder of a particular user if you have multinested virtual home folders?

# cd ~hisusername

40. How to browse and download the whole pages of a particular WWW site in one shot ?

# wget -p --progress=dot http://www.google.com

41. How to safely mark badblocks from another ext2/ext3 linux harddisk ?

# umount /dev/other-harddisk2
# e2fsck -c /dev/other-harddisk2

42. How to create a new ext3 filesytem with bad-block checking from your secondary harddisk?

# mkfs.ext3 -c /dev/other-harddisk2

43. How to compare bzip2 compressed files ?

# bzdiff file1 file2

44. How to detect hardware monitoring chips and load modules related to newly detected chips?

# sensors-detect
>45. How to know if your postfix or sendmail is running ?

# ps axuw | grep sendmail
# ps axuw | grep postfix

46. How to change the default port when spamassassin is launched?

# vi /etc/sysconfig/spamassassin

47. How to disable postfix permanently after reboot ?

# chkconfig --levels 345 postfix off

48. How to know the number of children spawned by apache ?

# ps axuw | grep http | wc -l

49. How to avoid a module from being loaded by kernel during startup and blacklist it permanently?

# vi /etc/modprobe.d/blacklist

50. How to quickly count all your queued mail when you box is really hogging due to spam bruteforce attacks and spam mailer?

# mailq | wc -l

How to smile ?

:)

Hope this helps abit.


0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy