Total Pageviews

Showing posts with label Linux Command Hacks. Show all posts
Showing posts with label Linux Command Hacks. Show all posts

Monday, November 29, 2010

bmp to Jpeg Conversion Tool

Convert a bunch of bmp files to jpeg on linux command line.

You can use ImageMagick's mogrify tool

mogrify -format jpg *.bmp

or

convert image.png image.jpg
 
 

 

Monday, August 30, 2010

dd

Quick way to create 50 qand 100MB files on your linux box

dd bs=50M if=/dev/zero of=rhel5-extra.img count=1

dd bs=100M if=/dev/zero of=aaa count=1


TO create 1 GB file using dd type the below command


dd bs=1000M if=/dev/zero of=/storage/file1 count=1


To create 10 GB file you can use


dd if=/dev/zero of=/storage/file1 bs=1024k count=10240

To create another file of 10 GB you can use


dd if=/dev/zero of=/storage/file2 bs=1024k count=10240


Even you can copy some big directory directly onto your /storage partiton.


Reference : http://maarten.lippmann.us/?page_id=116

find command tips

1) Replace all the files under the directory containing the word pradeep to paps

find ./ -type f | xargs perl -pi -w -e 's/pradeep/paps/g;'

2) To check the size of each directory

find . -maxdepth 1 -type d -print | xargs du -sh | sort -rn

/bin/cp: Argument list too long

yesterday when i copy a files using this commands:

cp -p *.txt /home/dralnux/projects/files

i got this message (/bin/cp: Argument list too long) i want to bang my head to the floor because i need to copy all the files in a rush.

Explanation about this error:

The shell can hold a maximum of 131072 bytes for command line arguments. If you try to pass more than that number you will greeted with an error that read as follows:

Argument list too long

Remember each character requires one byte of storage.

Solution:

try to use find command for example:

find . -name ‘*.txt’ -exec cp -p {} “/tmp/dralnux” \;

and yehey it’s works :)

Making Bootable ISO

creating-bootable-iso-in-linux

growisofs -speed=2 -dvd-compat -Z /dev/dvd=RHEL5.2-Server-i386-dvd.iso


growisofs -dvd-compat -Z /dev/dvd=ubuntu-7.10-desktop-amd64.iso


Ref Link : http://crazedmuleproductions.blogspot.com/2008/02/creating-bootable-iso-in-linux.html

history Command With Timestamps

History is a common command for shell to list out all the executed commands. It is very useful when it comes to investigation on what commands was executed that tear down the server. With the help of last command, you be able to track the login time of particular user as well as the the duration of the time he/she stays login.

last
...
mysurface tty7 :0 Mon Oct 6 20:07 - down (00:00)
reboot system boot 2.6.24.4-64.fc8 Mon Oct 6 20:06 (00:00)
mysurface pts/8 10.168.28.44 Mon Oct 6 17:42 - down (01:58)
mysurface pts/7 :0.0 Mon Oct 6 17:41 - 19:40 (01:59)
mysurface pts/6 :0.0 Mon Oct 6 17:27 - 19:40 (02:13)
mysurface pts/5 :0.0 Mon Oct 6 17:27 - 19:40 (02:13)
mysurface pts/5 :0.0 Mon Oct 6 15:52 - 15:59 (00:07)
...

If the command line history could provides the date time of the commands being executed, that may really narrow down the scope of the user actions that cause the server malfunction. By default, history do not append with timestamp, but it is easy to configure it to display timestamp, you just need to set one environment variable HISTTIMEFORMAT.

HISTTIMEFORMAT takes format string of strftime. Check out the strftime manual to choose and construct the timestamp that suit your taste. My favorite is “%F %T “.

export HISTTIMEFORMAT="%F %T "

Execute history again and you will see the effect on the spot, bare in mind that the timestamp for command lines that executed at previous sessions may not valid, as the time was not tracked.

...
994 2008-10-16 02:27:40 exit
995 2008-10-16 01:12:20 iptables -nL
996 2008-10-16 01:47:46 vi .bash_profile
997 2008-10-16 01:47:55 history
998 2008-10-16 01:48:03 . .bash_profile
999 2008-10-16 01:48:04 history
1000 2008-10-16 01:48:09 exit
1001 2008-10-16 02:27:43 history
...

I would suggest you to put the export into ~/.bash_profile as well as /root/.bash_profile. In case you do not have .bash_profile, you can choose to put into ~/.bashrc.