ā‰” Menu

Holiday Giveaway: Win Learning Nagios 3.0 Book

Learning Nagios 3.0 BookIt’s Holiday Season and I have a gift for you.

As part of the first contest at The Geek Stuff, I will be giving away three copies of Learning Nagios 3.0 PDF version of the book written by Wojciech Kocjan. All you have to do is let us know your favorite Unix command with a sample usage.

For those who’ve been following this blog for a while already know that I love Nagios and I have written few article on Nagios earlier.

For beginners, Learning Nagios 3.0 book will give you an introduction to Nagios and a jumpstart on how to setup and configure Nagios 3.0. For advanced users, this book explains about the Nagios 3.0 new features and details of advanced Nagios configuration.

How to Enter the Contest?

It is very simple. Leave a comment with one of the following or both:

  • Share your favorite Unix command with a sample usage.
  • Share your favorite vi, or vim, or emacs tips.


Three winners will be selected randomly from the comments and will receive PDF version of Learning Nagios 3.0 Book. The contest is open to everybody.Ā  Contest End Date: Tue, Dec 23, 2008 at Midnight.

Update: Contest is closed now. Three random winners was selected from the comments.

Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! ā€“ 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Bipin Tigga December 15, 2008, 10:33 pm

    My favourite command: ps
    Usage: ps -eo pcpu,pid,user,args,pmem | sort -k 1 -r | head -30

  • hybrid-kernel December 15, 2008, 11:22 pm

    grep is probably by far my most used command, can’t live without it. 99% of my scripts use it as well.

    Search process:
    ps xa | grep

    -e and -v are useful flags

  • Remin Raphael December 16, 2008, 2:05 am

    watch runs a program in a period of time, and displaying the output in real time.

    example: This command will run the command free in ten-second intervals, and display the output.

    watch -n 10 free -m

    Another example :

    watch -n 3 ‘cat /proc/interrupts’

    This command will display the interrupts in 3-second intervals.

  • Spark December 16, 2008, 2:14 am

    Copying a CD to a File on your Filesystem
    Here are a couple of mentods for copying a CD to a file:

    [root@server /root]# dd if=/dev/cdrom of=image.iso
    [root@server /root]# cat /dev/cdrom >image.iso

    Buring an ISO Image to CDR or CDRW

    [root@server /root]# cdrecord -v dev=3,0,0 image.iso

  • utku December 16, 2008, 6:00 am

    ls -l file* is the best command for me also whereis, locate and ofcourse nano file :)))

  • Bharath December 16, 2008, 6:34 am

    curl is my favorite command, one of the frequently used ones.

    curl -I http://www.thegeekstuff.com | head -5

  • Tai Quach December 16, 2008, 12:00 pm

    I love using these two commands when editing /etc/passwd and /etc/group safetly.
    vipw -s : Edit /etc/passwd file
    vigr -s : Edit /etc/group file

  • kidb0unce December 16, 2008, 12:25 pm

    Where would we be without the find command; lost perhaps šŸ™‚

    This command will list all log files that contain the IP address 192.168.0.1

    find /var/log -type f -exec grep -l “192.168.0.1” {} \;

    Even more fun if you wrap it in a for loop. This command will output the name of the log file that contains the IP address then the log entries from said file containing the IP address and dump it all into a text file (IP_in_logs.txt) for later review.

    for i in $(find /var/log/ -type f -exec grep -l “192.168.0.1” {} \;); do echo $i; grep “191.168.0.1” $i; done > IP_in_logs.txt

  • Ajith Edassery December 16, 2008, 12:54 pm

    You are asking the wrong person Ramesh… I know nothing about Unix/Linux as I have been on the Microsoft side most of my life. I am recently into a little bit of PHP though.

    Sorry, I cannot participate but I really wanted to come in here and comment to announce my support to your holiday give away!

    Cheers,
    Ajith

  • Kyle December 16, 2008, 1:32 pm

    find

    find is a marvelous command with far to many options to list, but it’s worth learning in detail.

    Here’s one that’s sometimes useful on file servers at work, it finds all directories in home with the word “music” in them.
    [root]# find /home -type d -iname “*music*”
    Of course if music on work servers is a real no-no, you could always do this, but some may think you’re mean for doing it… it finds all files that end with “.mp3”, and then removes them.
    [root]# find /home -type f -iname “*.mp3” -exec rm -f {} \;

    Of course the -type f (only find files), -type d (only find directories) and -exec options are only the tip of the iceberg! find is a treasure trove all on it’s own.

    –Kyle

  • SLM December 16, 2008, 2:11 pm

    Iā€™m a big fan of lsof, especially when diagnosing web server load problems. Usage (shows current http connections, with client IP address and state):
    lsof -i tcp:80

  • Derrick McNealy December 16, 2008, 2:27 pm

    Here’s a VI tip I use a lot. I’m no guru, so my tip may be of little help to others.
    Sometimes I need to make an edit, but only withing a certain parameter of lines — not in the whole text file. I tend to use this if I’m editing a http.conf or vhost.conf file.This VI command helps:

    :32,56s:originalstring:newstring:g

    The numbers at the beginning of the string represent the line numbers in the text file where I want to make the changes. So, the changes will only be made between line 32 and 56 and nowhere else. The “s” after the second line stands for “substitute”. The “g” at the end is for global — yet it’s only global within the line parameters which were set at the beginning of the command string.

  • Sly December 16, 2008, 2:43 pm

    To edit two files at the same time with vim you can split the screen.
    Start by editing the first file: $ vim file1
    Press Ctr + w then n (Opens new window)
    Read a file into this session by typing :r /path/file2
    To switch between the top and bottom press Ctl + w then w
    Use standard vim commands like yy to cut p to paste.
    To save the file you read in, type :w followed by the filename.
    Ctr + w then q will also attempt to quit the window.

    Optional:
    To turn line numbering on :set nu
    To turn text from wrapping off :set nowrap
    To turn syntax highlighting on :syntax on

  • VonSkippy December 16, 2008, 3:42 pm

    Shutdown

    As in:
    #Shutdown -h now

    Means the day is over and I can go home to my wife and kid and relax (until of course a priority email arrives or my Blackberry siren goes off).

  • Lex December 16, 2008, 4:58 pm

    ls
    Because I think I use “ls” more than any other command. I know that’s as boring as saying the word “the” is my favorite word in english, but “ls” is only 2 letters, very effective and simple to use with very predictable results …elegance.

  • gocyclones December 16, 2008, 5:54 pm

    The most valuable command I know is “screen -R” I use this along with a tweaked out .screenrc file. All I can say is learn to use screen.

  • Will December 16, 2008, 7:18 pm

    My Fave Command is : su and passwd

  • Jacky December 16, 2008, 8:44 pm

    The default ‘ps’ command only give you the starting timestamp of the processes which run at the same day when you issued ‘ps’; Older processes can just would shown as starting date but no time. Aliasing the ‘ps’ command with the following argument would give you the starting timestamp. Sometime it is useful to find some dead processes run over a period of time.

    alias psStartTime=’ps -eo pid,%cpu,%mem,user,args,lstart’

    In vi, I would like to share find and replace, in command mode, try
    :1,$s/word1/word2/gc
    will try to find from line 1 to the end of file with match ‘word1’ replace to ‘word2’ after your confirmation.
    :n1,n2s/word1/word2/gc
    do the same as above but between line number ‘n1’ to ‘n2’.

    Thanks.

  • unixuser December 16, 2008, 9:41 pm

    my most favorite command is grep which is the most powerful command,
    we can search for whatever pattern in a file, it will give you the lines from a file which is matched for the given pattern.
    – you can get the matched line’s line number.
    – count of the matched pattern, etc.

    rmmod – to remove the modules from the linux kernel

    insmod – to insert a module into the kernel

    lsmod – used to show the status of the modules in the kernel

  • Thanh Dat December 16, 2008, 10:20 pm

    My favorite is: Ctrl + R and type the keyword to search the commands that i used previously.

    Another favorite “history” is !$ which use the parameter in the last command in the current command.
    ex: $vim /very/long/path/to/the/file.txt
    $tail -n 15 !$ (!$ will be /very/long/path/to/the/file.txt)

    In vim, I love this tip:
    http://vim.wikia.com/wiki/Making_Parenthesis_And_Brackets_Handling_Easier
    which make me program faster and NEVER cause a “syntax error” because of missing brackets.

  • pushpraj nimbalkar December 16, 2008, 10:35 pm

    I can not forget shred command.

    #shred -n 5 -vz /dev/sda

    so my tip is to dont use shred command unless you know what your are doing.
    songs and movies of 150 GB lost in just few seconds. Other useful commands like
    #pidof –>>to show process id
    #df -h —>>disk usage status
    #fdisk -l /dev/sda –>> hard disk partition information
    #parted –>> beautiful partition editor

  • Geromyh December 16, 2008, 10:57 pm

    My favorite command: Ducks

    # du -cks ./* | sort -rn | head

    Shows the size of the largest files / directories in the path – great for answering the question of “What the heck is eating all my disk space?!”

    A close second, and one I’ve only needed twice so far (thankfully) is the magic key reboot:

    # echo 1 > /proc/sys/kernel/sysrq
    # echo b > /proc/sysrq-trigger

    (Used when I’m on a remote server, have a command line, but a hung process refuses to die for a reboot)

  • unixuser December 16, 2008, 11:10 pm

    In vim, you can mark the particular location in a file.
    If you are navigating through a huge file, you dont have to scroll up an down again again.
    you can mark that place using ‘m’ followed by name. (For ex: ma ).
    if you press `(backtick) a, the cursor will point that marked location.

  • Geromyh December 16, 2008, 11:16 pm

    Hah… didn’t even notice I picked up the sysrq command from this website šŸ™‚ Disregard the second one…

  • Tony December 17, 2008, 3:29 am

    Tunnel Traffic viah SSH Tunnel

    ssh -R destport:desthost:localport user@edgeserver

  • unixlearner December 17, 2008, 5:03 am

    VIM tip
    global mark – which enables you to come to the marked spot from anywhere.

    Explanation.
    Do mA in a place inside a file, from where ever you are press (backtick A ) `A,
    it will take you to the file, and the position where you marked it.

    Unix command

    Finding the 5 biggest file in my home directory.
    Sometime there will be a dump or a unwanted file occupies the space, and kills me for violating the quota, so i will use this command…. ( change the number in head command to see different number of output ).

    Command
    find ~ -type f -exec ls -s {} \; | sort -n -r | head -5

  • MR December 17, 2008, 5:27 am

    my favorite commands are
    1. ps -aux | grep
    2. tail -200f on log files
    3. vi / more

    and a lot of shell scipts …

  • Danton Cancella December 17, 2008, 5:32 am

    My favorite unix comand is ‘awk’ a powerfull command when combined with pipe, just a sample:

    df -kh | sed 1d | awk ‘{ printf(“File system: %s is %3s occuped\n”,$1,$5); }’

  • Liju Mathew December 17, 2008, 5:45 am

    Here is my tricks

    ########### How do I install Web can Ubuntu ##############

    Some useful commands
    #dmesg | tai
    # lsmod | grep video

    #sudo aptitude install kernel-package linux-source build-essential git-core exuberant-ctags cheese
    git clone http://repo.or.cz/r/microdia.git
    #cd microdia
    #make
    #sudo insmod ./microdia.ko
    #cheese

    cheers,
    Liju

  • Unix John December 17, 2008, 5:46 am

    My favourite Unix command….

    reboot

    e.g

    reboot (goes for a cigarette break)

    (sorry but I came from a windows background)

    šŸ™‚

  • Manuel Trujillo December 17, 2008, 6:16 am

    My favourite command is “ps”, and a cool tip for vi/vim is:

    : 1,$s/original_word/word_to_substitute/g

    With this command, you can substitute a word/etc into a text.
    The firsts parameters are the firts line and the last line (in this case from line number 1 up to the last line into file). Second part is the word you would like to substitute. Third part is the new word you would put into file.

    Have a nice day šŸ˜‰
    TooManySecrets

  • Edin husejnefendic December 17, 2008, 6:36 am

    wget -c -b –no-passive –limit-rate=50k -v ftp://[username]:[password]@[ip]/%5Bdirectory%5D/*.*
    cat /usr/local/etc/squid/squid.conf | mail -s “subject” lihnjo@gmail.com` # Send email from cat output

    find /var/spool/mqueue/ -ctime +100 -print | xargs rm # Delete files older than 100 days
    find /var/mail -size +20000k -exec rm ‘{}’ ‘;’ # Delete files >20000K
    find /var/mail/ -size 0 -exec rm ‘{}’ ‘;’ # Delete files – 0 size
    find . -inum 4003856 -exec rm -i {} \; # Delete file inode=4003856 ls -li
    find . -inum 4003856 -exec mv {} [filename] \; # Rename with inode

    # Remove Ctrl-M from dreamviewer file
    cat AD.php |tr -d ’15’ > AD1.php ; mv AD1.php AD.php ; chown e_hus:users AD.php ; chmod 700 AD.php

    grep ^# /etc/fstab # Show lines with “#”

    Cheers
    Edo
    http://www.edin.ba

  • Tapas Mallick December 17, 2008, 6:58 am

    Most of the system related announcement/Error/Information are printed on Linux server’s first Virtual console and if you logged in from remote system through putty/some other remote login client, you can still view the same through the below mentioned command:

    # cat /dev/vcs1

  • valqk December 17, 2008, 7:03 am

    Hi there, few interesting tips found here šŸ™‚ but noone told anything about the netstat command šŸ™‚

    netstat is my friend on a new setup machine to check the programs that are listening on the interfaces.

    netstat -nap|grep LISTEN
    -p works only in linux. in debian you can use netstat -n4lp to see what ipv4 progs are listening. be warned, ssh is listening on ipv6 addr.
    in freebsd I use sockstat -l ( or -4l )
    in freebsd to check out the routing table I use
    netstat -nr

    šŸ™‚
    in vi if you want to go at the begining of the line you press ^ at the end $ i you want to go a word after this w and you can also 8w or d8w (deletes 8 words)
    basiccly you are moving from word to word with w and b šŸ™‚

  • deantn December 17, 2008, 7:18 am

    My favorite is “top”.
    It is used by most to actually see what is going on in the processes area and also to see what memory is being used.
    Put it on desktop and keep track of all things going on in real time.

  • Bejoy Abraham Mathews December 17, 2008, 7:35 am

    Favourite command:
    awk and grep

    Eg: To kill all process ids of a process
    kill -KILL `ps -ef | grep process_name | grep -v grep | awk ‘{print $2}’`

    grep -v grep is to remove the process that has the “grepping for process_name” itself as a process.

    The column needn’t be 2. It could be any column where the process id shows up.

    vi tips:
    To start a coloured and numbered vi editing
    vi “+syntax on” “+set number” filename

  • Arvind Kumar December 17, 2008, 7:39 am

    My all time favourite command in linux is

    who am i

    depending upon your mood and login this can make you feel like God (or root as the case might be) or bring you down to earth very quickly.

  • sbz December 17, 2008, 7:53 am

    I can’t believe you guys forgot about rsync! šŸ˜› Most useful tool to do offsite backups, when you have to migrate servers, or just move a lot of data incrementally.

    rsync -av /some/dir /some/destination <- local

    rsync –progress -ave ssh /some/stuff/ user@ip_remote_srv:/some/remote/dir/

    hm vi tip….. ah! how to lowercase the whole file

    ggguG

  • Joseph Hedrick December 17, 2008, 8:02 am

    dd zero fill

    dd if=/dev/zero of=/dev/sda1

  • Fready D'Costa December 17, 2008, 8:09 am

    netcat(nc)

    I most used for copying the files accross the network and mostly when I have to overcome some firewall blockings

    1.. If you want to copy a file from host A to host B(may be on diffent network and behind the firewall )

    On host-A
    $cat file | nc -l -p 5555

    On host-B
    $nc host-A 5555 > file-from-host-A

    Looks like I am going to be the lucky winner šŸ™‚

  • Port Resi December 17, 2008, 8:11 am

    One of my personal favorites is the use of the chattr command.

    While I respect most of the people I work with their are a few malcontents in the group who, if I did not use chattr, may cause a bit of damage to the systems they access.

    So my favorite command is: chattr +i [name-of-file] .

  • rahul bodhe December 17, 2008, 8:21 am

    my favorite command is du -sh

  • Deepesh December 17, 2008, 8:29 am

    My favourite command is “ls -a ” for unix os

    to see the hidden file of the drives

    Have a nice day
    Regards
    Deepesh

  • Jason December 17, 2008, 8:57 am

    The command I tend to use the most is “tail -f” I suspect most people will know about this already, however for people transitioning from windows to Linux this is a great command to watch log files in real time. To use the command simply type “tail -f logfilename” to end the tail type CRTL-C. You can also use the command to see just the last n number of lines “tail -n logfilename”

    Hope this helps someone.
    Thanks,
    Jason

  • DD December 17, 2008, 9:01 am

    My favorite vi/vim tip is turning line numberiing on: “:set number” Really helps when trying to figure out what went wrong with your script!

    For linux/unix, a basic one: pipe to more (or less) “| more”

  • Rob December 17, 2008, 9:12 am

    My favorite command is … ok there are a lot of them, so I’ll just pick alias.

    alias lsl=”ls -aC –color=yes | more”

    This shows all directory files including hidden files in color and in columns, one page at a time.
    An argument could be made for using less rather than more, because less is more, but I get weird video effects when I do, so I just stick with more.

    Stuff your alias’s into bashrc (by whatever specific name) and they will be active when you log in.

  • Marc Riera December 17, 2008, 9:19 am

    command : sed (string substitution)

    example:

    you have a template, for vhosts or whatever.

    sed -e “s/%VARTOCHANGE%/USEFULVAR/g” $TEMPLATEFILE > $USEFULFILE

    usefull on scripting

    and for vi:

    1. ^V for block select
    2. Select the lines you want (10j for the next 10 lines)
    3. I for insert mode
    4. Type the # or whatever you want to prefix
    5.

    a good way to comment blocks or classes.

  • Jeffry December 17, 2008, 10:40 am

    II like the nmap Command as this help me scan a Subnet and lets me know what hosts are in this subnet and what ports are open on these hosts. nmap is extremely powerful command as you can scan with different options (example below for more options use Man or –help)

    nmap -v 192.168.1.0/23 or nmap -sP 192.168.1.0/23

    Try it out, and you will not be able to work without this command..

    Regards,

    Jeffry

  • jep December 17, 2008, 2:05 pm

    free -om

  • Craig December 17, 2008, 2:40 pm

    I really like the lshw command for finding info on the hardware :
    lshw -C CPU

    SSH what would we do without it?

    You can copy files between machines really easy with it:
    scp /etc/passwd user@othermachine:/etc/passwd

    Also a -r flag will copy directory.

    It is much use to gather data from multiple machines in a program. SSH makes that easy:

    @PS = system(“ssh othermachine ps -ef “);

    C

  • Trey Blancher December 17, 2008, 3:18 pm

    I like using screen to multiplex my terminals. This is also how I share terminals with customers, and nothing more is needed other than SSH and screen itself:

    screen -h 30000 -S arbitrary.title -T vt100

    This starts screen with a scrollback buffer of 30,000 lines, sets the screen title to “arbitrary.title” so you differentiate between multiple screen sessions, and sets the terminal type to a baseline VT100 terminal. You can then use screen to split the terminal window, so you don’t need to access other tabs or windows to see man pages, source files, etc.

  • Trey Blancher December 17, 2008, 3:23 pm

    Oh, yeah, about screen… you can detach from a screen session, connect from a completely different machine, and reattach to the screen session and it’s like you never left.

  • Akshay Sulakhe December 18, 2008, 12:47 am

    My fav command which i need to mount my ntfs drive with force…

    sudo mount -t ntfs-3g /dev/sda4 /media/data -o force…..

    i dont add force in fstab because i need this command incase of prob..

    my other fav command

    sudo nautilus

    formoving files here and there….

  • unixthirst December 18, 2008, 6:34 am

    CDPATH

    It is one of a simple and very useful hacker, learnt from this blog.

    export a CDPATH to a 4th level directory which i would use it often as,
    export CDPATH=/a/b/c/d/

    Using which i can go to the 4th level directory simply, without keying in all those dir names…..

    read http://www.thegeekstuff.com/2008/10/6-awesome-linux-cd-command-hacks-productivity-tip3-for-geeks/

  • Flynets December 18, 2008, 10:53 am

    My best tips:

    for vim : Replace Unix carriege (^M) – :%s/\r/\r/g

    for shell:

    – Remove backup files = find -iname “*~” -print|xargs rm
    – Replace space character =
    find . -type f -iname “*.mp3” -exec rename “s/ /_/g” {} \;
    – Resize and create new pictures with covert command (ImageMagick) =
    for k in $(ls *.jpg); do convert -resize 800 -quality 80 $k r800-$k; done
    – Resize pictures with mogrify command (ImageMagick) =
    for k in $(ls *.jpg); do mogrify -resize 800 -quality 80 $k ; done

    happy coding šŸ™‚

  • valqk December 18, 2008, 2:12 pm

    @unixthirst
    you can simply add an alias cspah forexample that does cd /long/path/here
    alias cspath=’cd /long/path/here’ in sh(bash)
    @Flynets
    you can simply do
    for k in *.jpg instead of calling ls

    instead of -print|xargs rm
    you can simply call -delete (work’s on most linuxes, depends on find version. on debian 4 works, on debian 3 not)…
    I couldn’t stopped myself posting this.
    sorry. šŸ™‚

  • nippip December 18, 2008, 9:06 pm

    many of my favorites have been already mentioned but one that I use for trouble shooting a process is;

    strace -p

    This will throw to stdout what the process is actually doing or not doing which can be very helpful.

  • Thierry December 19, 2008, 4:59 am

    hands down the following or how to remove ALL the .tmp files in one go. Can be obviously adapted for other file types or modified to one’s heart’s content.

    ls | grep .tmp | xargs rm -f

  • Siva December 19, 2008, 7:28 am

    Hi
    My favorite Linux Commaind : Nmap

    My fav Editor – Vim

    Siva

  • Jimmy M December 22, 2008, 4:22 am

    After all the operating systems I have used I have come across one command that simplifies everything from confusion to light. Some might take it lightly but these simply comand will make all linux jargon come to light.

    apropos *anything*

    this will give you a quick discription of the command or instruction you want to know. sub *anything* with any command eg. man , shell, gcc, shutdown. enjoy

  • Peter VG December 22, 2008, 12:01 pm

    We needed a script that had to remove from a directory all files except for a specific number of file names. This directory was filled by another script that extracted attachments from emails that were received on a dedicated email address. Finally a print script toke the valid attachments and printed them, afterwards removed them. Since it was a public email address a lot of garbage was unavoidable and as a result also a lot of garbage attachments. To remove the garbage attachments I used a “remove except for …” command:

    find . -type f ! \( -name ‘FA*’ -o -name ‘DE*’ -o -name ‘*.pdf’ -o -name ‘m2t*.wrk’ \) -exec rm {} \; > /dev/null 2>&1

    This command removes all files except for files with name “FA*”, “DE*”, “*.pdf” and “m2t*.wrk”.

  • Bob M December 24, 2008, 3:28 pm

    I know the contest is over but here is command that I think is a pretty good way of taring up a directory and transferring the file to a remote system in one step:

    tar zcvf – /some-filesystem | ssh user@some-machine “cat > /tmp/test.tar.gz”

    Saves me time of not having to wait for the tar process to finish and then scp it over to the remote system.