Control our terminal color using tput

“tput” is a standard Unix operating system command which is used to set terminal features.

Depending on the system, tput uses the terminfo or termcap database, as well as looking into the environment for the terminal type.

Change the Terminal Background Color using tput setb

Using tput, the background color of the screen can be changed as shown below.

$ tput setb 4

Change the Foreground Color using tput setf

You can also change the foreground color of the terminal as shown below.

$ tput setf 4

Note: If you set foreground and background to the same color you cannot see the cursor. So, to reset, execute “tput reset”.

1: red, 2: Green, 3= Yellow, 4= Blue, 5= Purple, 6= Cyan, 7= White

More info:

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html

Leave a comment

Filed under Uncategorized

For disk IO subsystem total statistics

vmstat – For disk IO subsystem total statistics since last boot use
the -D option

$ vmstat -D
27 disks
2 partitions
2766536 total reads
526906 merged reads
61184034 read sectors
21233780 milli reading
8849711 writes
3719803 merged writes
100480938 written sectors
181253052 milli writing
0 inprogress IO
12854 milli spent IO

The last stat shows 12854 ms spent reading from the disk.

Merged reads and merged writes happen when the kernel tries to
combine requests for contiguous regions on the disk for a performance
increase.

If you want more detailed totals, use the -d option.

An important note, vmstat can provide totals on disk performance whereas
iostat provides data rate of change during the sample.

Leave a comment

Filed under Uncategorized

Extract images from a PDF document

Extract images from a PDF documentExtract images from a PDF document

$ pdfimages -j foo.pdf bar

This will extract all images from foo.pdf and save them in JPEG format (option -j) to bar-000.jpg, bar-001.jpg, bar-002.jpg, etc.

From the man page:

DESCRIPTION:
Pdfimages saves images from a Portable Document Format  (PDF)  file  as
Portable Pixmap (PPM), Portable Bitmap (PBM), or JPEG files.
Pdfimages  reads  the  PDF  file PDF-file, scans one or more pages, and
writes one PPM, PBM, or JPEG file for each  image,  image-root-nnn.xxx,
where  nnn  is  the image number and xxx is the image type (.ppm, .pbm,
.jpg).

OPTIONS:

-j     Normally, all images are written as PBM (for monochrome  images)
or  PPM  (for  non-monochrome  images) files.  With this option,
images in DCT format are  saved  as  JPEG  files.   All  non-DCT
images are saved in PBM/PPM format as usual.

Leave a comment

Filed under Uncategorized

Find out how long the system has been running

$ uptime

uptime gives a one line display of the following information. The current time,
how long the system has been running, how many users are currently logged on,
and the system load averages for the past 1, 5, and 15 minutes.

Ex:


  [suresh@mercury ~]$ uptime
  13:12:56 up  1:54,  2 users,  load average: 0.65, 1.18, 1.22

uptime command gives a one line display of the following information.

  • The current time (13:12:56)
  • How long the system has been running (up 1:54 )
  • How many users are currently logged on (2 users)
  • The system load averages for the past 1, 5, and 15 minutes (0.65, 1.18, 1.22)
* This is the same information contained in the header line displayed by the w and top *

Leave a comment

Filed under Uncategorized

Save the list of all available commands in your box to a file

 

$ compgen -c | sort -u > commands

When you press TAB twice in your prompt, bash tells you something like

“Display all 4113 possibilities? (y or n)”

But when you press “y” you only get the list in the terminal output and, if you want to save it to a file, you have to copy it by hand from the vterm screen. With this utility you save the list to a file or pipe it to another command at will

You can use the file saved list to grep for a particular pattern, useful if you are searching for a command but you only remember a few letters

Leave a comment

Filed under Uncategorized

Find the All the related words from Local Dictionary

Find the All the related words from Dictionary in Terminal

  $ < /usr/share/dict/words egrep ^some english word^

It’ll print all the related words to the word given.

 Ex:

  [suresh@mercury ~]$ < /usr/share/dict/words egrep geek
  geek
  geekier
  geekiest
  geeks
  geeky

Leave a comment

Filed under Uncategorized

Simple Encryption in command line

Simple Encryption in command line

To encrypt single file, use command gpg as follows:

$ gpg -c filename Output:

Enter passphrase:

Repeat passphrase:

This will create a filename.gpg file.

Option: * -c :  Encrypt with symmetric cipher. Caution if you ever forgot your password aka passphrase, you cannot recover the data as it use very strong encryption.

more info: http://www.gnupg.org/gph/de/manual/r1023.html

Ex:

To Encrypt:

    [suresh@mercury Desktop]$ gpg -c test.rb
    Enter passphrase:
    Repeat passphrase:

    To Decrypt:

    [suresh@mercury Desktop]$ gpg test.rb.gpg
    gpg: CAST5 encrypted data
    Enter passphrase:

Leave a comment

Filed under Uncategorized