Linux Cool Tips and Tricks Log 7

Overview

Linux Tips and Tricks continued….

Convert unix timestamp to something readable

If you are a system administrator just like me, I bet you have a bitter sweet relationship with log files. They are the first thing we peek into when something goes wrong. One thing that you will find is the unix time stamp used by most of these. To convert these to human readable date and time format you can use the date command just like this


% date -d @1347213569

 

Find your favorite command

If you ever wish to find your most used command, try look through your history just like this


% history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
Advertisements

Linux Cool Tips and Tricks Log 6

Overview

Linux Tips and Tricks continued…

The destroyer command

If you are planning to throw or dump your old hard disk (Since you are big rich lad and can buy super cool SSDs) it is always advisable to wipe and erase data on your old one. You would like to make it as hard as possible for anyone to pull out any data out of your old thrown hard disk. Data can still be restored after you delete everything and perform a format. Shred is a popular utility that comes pre installed with almost every linux distribution. Lets use shred to remove anything from my second attached disk.

A word of caution, never try this on a disk you love, this would result in complete data loss.

shred -v -n 1 -z /dev/sdb-v : show progress
-n 2 : overwrite hard disk with two pass of random data (Advisable is to perform more than one pass of randaom data, the down side it is that the process takes bit long to complete)
-z : finish cleaning with one pass of zeros

 

Which process uses which files?

How many times have you tried unmounting a drive and faced with an error. The fuser command can tell you which user is still accessing the drive making it unmountable. You can easily kill the process then and unmount the drive.

List processes using the cdrom drive (usefull for a clean unmount):
/sbin/fuser -v /mnt/cdrom
List processes using the sound card:
/sbin/fuser -v /dev/dsp0

Cheers…

Linux Cool Tips and Tricks Log 4

Overview

Linux Tips and Tricks continued…

Find which operating system you are running

Finding the OS information is easy in Linux, I have seen most people jump to /etc/issue file to find it. This is absolutely correct however this file can be easily modified and changed by the sysadmin, to give you false information. A sure shot method of finding OS name and details is to fire this command on your terminal.

lsb_release -a
Example: when ran on my system
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise

Find all files larger than some value and less than some value

If you want to free up some disk space quickly and find all big files use the command below

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

Cheers…

Linux Cool Tips and Tricks Log 3

Overview

Linux tips and tricks continued..

Public IP Address Finder

If you wish to find the public address associated with your machine curl utility can help you. I used to go to some popular website like whatismyip.com to find my public ip address however now I use curl just like this.

curl ifconfig.me

 

Combine the goods of ping and traceroute

My TraceRoute or mtr as it is called is a sweet little utility that combines trace route and ping together to form a powerful interface that can help you find packet drop rates at each hop. Use mtr to find how it can enhance your normal ping or traceroute commands

mtr linuxdrops.com

Cheers!!!

Linux Cool Tips and Tricks Log 2

Overview

Continuing the tips and tricks series here are the some more tips that you can use to save some time.

The Copy Cat command

So you have a package installed on a system and you have another system require the same package, can’t u just copy it. Yes you surely can. Login to the server which has the package installed and run the following command

ssh root@servername “rpm -qa” -grep -i vsftp | xargs yum -y install

Adding readability Super”MAN” pages

So you wish to convert manuals to pdf on the fly. Lets use ps2pdf to perform it. You can convert long html pages, man pages to pdf files for easy access and readability. Lets convert the man manual to pdf.

man -t man | ps2pdf – manpage.pdf

Cheers till next time…

Linux Cool Tips and Tricks Log 1

Laziness is a natural human quality. Also, we human beings are getting busy each passing day, so we are always short on time. You combine these two and we see big hindrance in our learning curve. This beautiful Sunday morning I thought why not start a small informative series highlighting some of the greatest tricks that Linux has up its sleeves. Here are some of the commands, tips and tricks that you may not know. I have purposely kept these articles small with couple of tricks so that you learn them, remember them and try them.

Lets Start

The bond and bourne of linux commands.

What if you need to fire of a command without leaving a tarce. So to execute a command without saving it in the history, just put a blank space before it.

#[space] command
Example
#   pwd

For the forgetful.

You just opened a file to edit in your favorite vi/vim editor and just when you tried saving it you were greeted with a warning “Can’t open file for writing”. Ouch you forget to open it using root. So to save it use the trick below.

:w !sudo tee %