Thursday, July 26, 2007

50 quick linux command tips part 2

Created Thursday 26/07/2007

As I go along and remember those linux commands, I'll be adding them here as time goes by. They don't pop out of my tiny-winny braincells easily when I needed them most.

Here goes nothing.

1. How to know which ports are listening from your IP address?

# nmap -sT -O your-ip-address

2. How to grep an exact match?

# grep -w textfile.txt

3. How to reverse grep matches?

# grep -v textfile.txt
#
4. How to know which service name is what port?

Assuming port 443

# cat testfile.txt | grep -w 443

5. How to get the first 10 lines of a file?

# head -10 testfile.txt

6. How to get the last 10 lines of a file?

# tail -10 testfile.txt

7. How to get the first column of a file?

# awk '{print $1}' testfile.txt

8. How to get the first and second columd of a file?

# awk '{print $1 " " $2}' testfile.txt

9. How to get the first column of a file having consistent field separator pattern?

Field separator character patterns is /

# awk -F/ '{print $1}' testfile.txt

10. How to get the second column of a file having consistent field separator pattern?

# awk -F/ '{print $2}' testfile.txt

11. How to show contents of a text file?

# cat testfile.txt

12. How to show contents of text file pausing ever page or one screenful at a time?

# more testfile.txt
# less testfile.txt

13. What is the big difference between more and less?

less linux command has much more extensive enhancements compared with more.
You can also scroll up interactively via control keystrokes using less while the other one does not allow you to do that.
less does not need to read the entire file to buffer when showing a screenful content of a file and furthermorel less is faster than more on accessing big filesize.

14. How do you delete all numbers and digits from contents of a file?

# tr -d [:digit:] < testfile.txt

15. How do you sort contents of a text file in descending order?

# sort -r newfile.txt

16. How do you create a file using touch (without opening it interactively for writing)?

# touch newfile.txt

17. How do you change the date of all files in one folder?

# touch *

18. How do you create a file using tee?

# tee newfile.txt

and start typing, press

19. How do you query currently installed package offline from your system?

# rpm -qa sendmail

20. How do you query packages for something-like package ?

# rpm -qa | grep sendmail
# rpm -qa *sendmail*

21. What files comes with a something package?

# rpm -qa postfix*
# rpm -ql postfix-2.4.3-2.fc7

22. What is this something package?

# rpm -qi postfix-2.4.3-2.fc7

23. Where does rpm stores its rpm database?

# cd /var/lib/rpm
# ls -la __*

24. How to mount CD drive after inserting the disk?

# mount /dev/cdrom /mnt/CD

25. How to know if fedora detects your Nokia N70 via USB?

# lsusb

26. How to change system date ?

# date -s "December 25 2007 01:01:01"

27. How to know your free base memory and other memory / swap statistics ?

# free

28. How to show disk space usage of your filesystem in human readable form?

# df -ah

29. How to get the top 10 of your mbox mail users?

# cd /var/spool/mail
# ls -lS | head -10

30. How to find process ID of a running service like httpd?

# pidof httpd

31. How to locate a binary file, command source and its man pages?

# whereis ping

32. How to find the location of a executable file that could have been executed when entered from a prompt?

# which ping

33. How to download ISO or any file from web using command line?

# wget -c www.google.com/testfile.txt
# wget -c ftp://google.com/google.ISO

34. How to transfer file via ssh?

# scp -c testfile.txt user@remote-hostname

35. How to transfer files that has been only changed from one host to another without taking comparison?

# rsync -avz remoteserver:/home/remotefolder /home/localfolder

36. How to transfer your identity.pub into a remote machine's authorized_keys?

# ssh-copy-id -i identity-rsa-dsa.pub user@remote-hostname

37. How to know who you are in a shell?

# whoami

38. How to get more real-time view linux process stats and info?

# top

39. How to issue a continuous trace route to a host?

# mtr host-ip-addres

40. How to trace route without resolving IP address?

# mtr --no-dns hostname

41. What is another text-based alternative to chkconfig?

# ntsysv

42. How to list out current cron jobs?

# crontab -l

43. How to get the CPU time?

# clock

44. How to set date and time from NTP server?

# ntpdate 0.fedora.pool.ntp.org

45. How to show current system path?

# set | grep PATH

46. How to list out currently loaded kernel modules?

# lsmod

47. How to know the total days of your system without reboot?

# uptime

48. How to get a system bootstrapped from redhat network?

# /usr/bin/go-rhn.sh

49. How to see current running user jobs?

# jobs

50. How to edit text files from terminal?

# vi textfile.txt
# nano textfile.txt
# joe textfile.txt
# vim textfile.txt
# pico textfile.txt (if pico is installed - Pico is a trademark of the University of Washington)
# tee vv


Hope this helps a bit.



0 comments:

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