Google Plus

11 useful commands for Linux/Unix administrators

Written by M. Zinoune on . Posted in linux command, Unix Tutorials

Command line is more powerful because you can do  lot with them,  you can tell your computer exactly what you want and get the appropriate answer, while GUI application can only tell your computer what the GUI programmer has defined.  Recently, CLI is mostly used by Linux/Unix administrators since most popular linux distros come with a complete set of GUI applications that make the user use less and less the command line.

In this post, i will show you 10 most rated linux commands for last past weeks at commandlinefu.

1- Save man-page as pdf

 man -t awk | ps2pdf - awk.pdf

2- Duplicate installed packages from one machine to the other (RPM-based systems)

ssh root@remote.host "rpm -qa" | xargs yum -y install

3- Stamp a text line on top of the pdf pages to quickly add some remark, comment, stamp text, … on top of (each of) the pages of the input pdf file

echo "This text gets stamped on the top of the pdf pages." | enscript -B -f Courier-Bold16 -o- | ps2pdf - | pdftk input.pdf stamp - output output.pdf

4- Display the number of connections to a MySQL Database

Count the number of active connections to a MySQL database.
The MySQL command “show processlist” gives a list of all the active clients.
However, by using the processlist table, in the information_schema database, we can sort and count the results within MySQL.

mysql -u root -p -BNe "select host,count(host) from processlist group by host;" information_schema

5- Create a local compressed tarball from remote host directory

ssh user@host "tar -zcf - /path/to/dir" > dir.tar.gz

This improves on #9892 by compressing the directory on the remote machine so that the amount of data transferred over the network is much smaller. The command uses ssh(1) to get to a remote host, uses tar(1) to archive and compress a remote directory, prints the result to STDOUT, which is written to a local file. In other words, we are archiving and compressing a remote directory to our local box.

6- tail a log over ssh

This is also handy for taking a look at resource usage of a remote box.

ssh -t remotebox "tail -f /var/log/remote.log"

7- Print diagram of user/groups

Parses /etc/group to “dot” format and pases it to “display” (imagemagick) to show a usefull diagram of users and groups (don’t show empty groups).

awk 'BEGIN{FS=":"; print "digraph{"}{split($4, a, ","); for (i in a) printf ""%s" [shape=box]n"%s" -> "%s"n", $1, a[i], $1}END{print "}"}' /etc/group|display

8- Draw kernel module dependancy graph.

Parse `lsmod’ output and pass to `dot’ drawing utility then finally pass it to an image viewer

lsmod | perl -e 'print "digraph "lsmod" {";<>;while(<>){@_=split/s+/; print ""$_[0]" -> "$_"n" for split/,/,$_[3]}print "}"' | dot -Tpng | display -

9- Create strong, but easy to remember password

Why remember? Generate!
Up to 48 chars, works on any unix-like system

read -s pass; echo $pass | md5sum | base64 | cut -c -16

10- Find all files larger than 500M and less than 1GB

find / -type f -size +500M -size -1G

11- Limit the cpu usage of a process

This will limit the average amount of CPU it consumes.

sudo cpulimit -p pid -l 50

For questions please refer to our Q/A forum at : http://ask.unixmen.com

  • http://web.ncf.ca/shawnhcorey/ Shawn H Corey

    Grep your command history: history | grep /pattern/

    Show mounted volumes in a table: mount | column -t

  • Paulo Renato

    Thank you so much, very useful, but I don’t understand how to use the generate password

    • Gdd

      First learn what each command does, then the whole set of commands should make sense.

  • Asd

    #9? Hangs…

    • Anon

      for the n00bz out there:

      echo -n “type password   : “;read -s pass; echo -ne “nhashed password : “; echo $pass | md5sum | base64 | cut -c -16

  • Asd

    Oh. Run as root. But then the same generation each time?

  • http://twitter.com/dhanusuraasi தனுசுராசி

    Hi, i get error when used 10th command

    $ find / -type f -size +500m -size -1gfind: Error in processing the argument 500m

    • Oppiet35

      That is a capital M not m.  Linux is case sensitive. And that is a G not a g.

  • Ngô Chin

     after running #9, echo $pass. Voila!

    • nicky

      Append ‘pass=’ to the command line.

      read -s pass; echo $pass | md5sum | base64 | cut -c -16; pass=

  • Jjzp

    awesome

  • husain barri

    great list, made my life easy. thanks.

  • Steven Tuxfield

    I like the first one “Save man-page as pdf”

  • Verdurmen

    This is making my life easier ;) thanks.

    http://www.squidoo.com/download-ubuntu

  • zakaria

    Nice commands. Thanks

  • Dho00om1991

    how to know every things you have installed in ububtu 11.10

    • ekrava

       dpkg –list

    • http://twitter.com/d3m0n35 Tom Mac

      sudo dpkg-query –list

      you can then | grep [string]

  • http://twitter.com/d3m0n35 Tom Mac

    locate big files

    sudo cd / ; sudo du -h –max-depth=2 

    then you can | grep G

    to search for folder containing Gb’s of data

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

SK

|

Yes i will. Keep visiting. Subscribe us to get daily updates. Thanks for the comment

Rakesh Vijayan

|

Hi SK

I am Rakesh vijayan thanks for your great work ,by your work I start to learn what is ldap , my request is will you make tutorial for ldap and samba pdc for us on ubuntu 12.04

Guest

|

It was a typo. Now its corrected. Thanks for pointing out.

Michael T

|

You shouldn’t be so stupid, in the first time.

PrestaShop

|

Hi! Thank you for this nice article. We’ve 130,000+ active stores, you forgot the “1″ ;-)

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .