Theodoros Emmanouilidis

Notes & Thoughts
Browsing Tip Of The Day

How To Remount As Read-Write A Read Only Filesystem

May18

So simple but yet so usefull!

If you have to deal with a failling disk or similar emergency situations and you have to remount as read-write a read only filesystem….

just type

1
mount -o remount,rw /

ta da!

Make A List With All Unique Items In A List Python

March31

This is just an one-liner, but very useful and convenient.

Suppose we have a python list

list=[1,4,2,3,4,5,6,3,2,6]

and we only want to return a list containing all unique elements of that list. We can use the “set” python command and construct a new list with all the unique elements of the original list.

list_unique(set(list))

print list_unique

[1,2,3,4,5,6]

Python rocks!!

Clone Entire Hard Drive With dd

February10

Suppose you want to back-up your entire system hard drive to a remote location as an image that you can roll back your system in case of emergency or copy everything to a new hard drive that will substitute the original system drive that is failing.

The following command clones entire hard drive with dd. First of all you need to boot your machine using a live Linux distro like knopix. Then, supposing that the hard drive you want to clone is sda, give the command

1
dd if=/dev/sda | gzip -1 - | ssh username@remotehost dd of=backup_image.gz

If you want to recover the image give the following command

1
dd if=backup_image.gz | gunzip -1 - | dd of=/dev/sda

dd copies everything bit by bit which means that the whole process takes a very long time. The good thing is that the cloned image is exact, containing original disk’ s partition info, boot sector info, everything.

It helps out though, in terms of speeding up the process a bit, to zero out all unused space, before using dd, issuing the command

1
dd if=/dev/zero of=0bits bs=20M; rm 0bits

Better be safe than sorry!

posted under Tip Of The Day | Comments Off on Clone Entire Hard Drive With dd

awk Script That Adds Specified Prefix To Each Line

February10

This is a useful awk script that adds specified prefix to each line of a given text file.

1
awk -v PRE='THE_PREFIX_THAT_YOU_WANT' '{$0=PRE$0; print}' my_input_file.txt > my_output_file.txt

It’ s so simple with awk!

posted under Tip Of The Day | Comments Off on awk Script That Adds Specified Prefix To Each Line
« Older EntriesNewer Entries »