BIPEDU

my ideas in action

Tag Archives: computer tricks

loop all files inside a folder

Another command line trick.

Let’s say that you just come back from vacation and you have few hundreds pictures in a folder. And you want to rename them from DSCxxxxx.JPG to something else like Vacation_2012_xxx.JPG.

You can do this with just a single line command:

for file in DSC*; do mv “$file” Vacation_2012_”${file#DSC}”; done

So basically this command is taking all files from current folder, that start with DSC string. If your files start with different string the replace DSC with yours (example “IMG”…).

Then each file is renamed (mv command) in to Vacation_2012_xxxxx.JPG . As you can see the string replacement is just adding the “Vacation_2012_” to a string from which it deleted “DSC”.

 

Now lets say that you have somewhere a web photo album ( like a PHP or Picasa, or similar). You want to upload all pictures there but they are too big (12MP, or 16MP). Well, a similar strategy works here, like this command:

for file in *.JPG; do convert $file -resize 1000 $file; done

So the same looping in the current folder, but now the “convert” command is used and all pictures are re-sized to  1000 pixel width. Please run this on a backup , since the originals will be replaced !

for more option please use :

man convert

 

Advertisements

hard passwords but easy to remember

One of the important problems of the modern computing is the security, privacy and the personal data that must be protected .

Usually we are using passwords to protect our data or  accounts ( email, web…).  But one of the main issues is that the passwords must be easy to remember for the owner but very hard to crack for the enemy. So if we choose a password that can be easily remembered, then there is a chance that other persons know it ( like object names, famous places, books quotes…etc).

If we use hard passwords, then it is a risk that we ( owner of the data) forget the password. The alternative is to write down the hard ( complex ) password on a paper and put the paper on a hard to find place. But this solution rise also the problem of the aces to that password. We may need this password in various moments , at random places in time, when we do not have immediate access to our little paper with passwords.

An alternative is to have a easy to remember password but to code it in such a way that the results is a very complex and hard to crack password.

For the people that have access to a computer this is an easy task.

Just an example : we generate the md5sum of a password.

$ echo “password” | md5sum

286755fad04869ca523320acce0dc6a4  –

The md5sum is unique to a input and cannot be cracked. This means that based on the result you cannot recover the input.

If we need only a certain number of characters, we can trim this string to a desired length (example 10 characters), like this:

$ echo “password” | md5sum | head -c 10 ; echo

286755fad0

If we want more, we can go further. As you notice in this string there are only numbers and letters ( small cap letters ). We can now pipe the result to another level of encoding. For example base64 encoding. This type of encoding is reversible ( the input can be found based on output data). The purpose here is to introduce more variation in the string.

$ echo “password” | md5sum | base64 | head -c 25 ; echo
Mjg2NzU1ZmFkMDQ4NjljYTUyM

Here we obtain the md5sum of the “password” word and the the result is send to base64 encoding. Then the length of the string is reduced to only 25 characters.

So now we have numbers and letters ( big and small cap).

So , as you can see this results are very hard to remember and crack. But for the owner that know to make this easy steps, the solution is easier.

Now lets suppose that the enemy find the “password” word. Well, whatever he tries, he cannot take the account.

The owner will never remember the Mjg2NzU1ZmFkMDQ4NjljYTUyM password, so even if the enemy force the owner to tell him his password , he cannot get it.

 

Of course, the secret here is that the “easy to remember password” is processed so that we obtain a hard password. Of course this is just an example.

You can even encode few times the result, mds5sum again few times, cut the length, or even add special characters in certain positions. So the possibilities here are infinite.

 

So please use hard password !

the dictionary attacks are very common in our days and the computing power is rising every day. ( now the cracking tools use  also GPU for a even faster speed).

Fix GRUB2 errors with Gparted from Live Distro !

Recently a friend of mine came to me and asked me for some help with his laptop .  He is using Mint Linux ( based on Ubuntu edition 10.10) . So what happened ? During startup he pushed the power button to close fast the laptop. It is a Dell XPS 15 inch ( Intel I7 with Nvidia Optimis GPU card) with dual boot Win7 and Mint Linux.

After that the Dell laptop starts up in a GRUB prompt and not going further.
I started confident that I will fix it fast with my Linux/Grub knowledge. But to my surprize, after 4 hours of trials and errors I did not accomplished anything.

I tried the booting from USB and CD/DVD and various techniques to reinstall the GRUB. Acctualy I was able to see and access the data from HDD but I was not able to reinstall the GRUB. Each time the errors were more strange and the results was void. After each restart the GRUB prompt was there…

Then after such a long time I begin to think…
I remembered that after a partition resizing ( with Gparted tool) the pop-up menu was telling me that the Gparted tool will reconfigure the GRUB and read the new values. So I said : Why not ? Maybe it will work !

So I put the Ubuntu 12.04 Live DVD and after startup I opened the Gparted. I did not want to change to mush the partitions . So I took one partition and reduced the size with only 1Mb. The main idea is that I want Gparted to trigger the GRUB recovery ( re-install). So it did ! After resizing that 1Mb, the Grub was reinstalled and the new configuration was read. After reboot the Mint Linux was as new ! Thanks Gparted ! Acctualy I think that Gparted should habe a option ( somewhere in the menu) to fix the Grub or Boot problems. Anyway Gparted does this automatically at each partition change ( resize ).

So basically what I discovered is that is was easier to apply this method than to try all the crazy ideas found with Google. It take only 30 seconds. It is not necesary any root commands or any terminal tricks.

Gparted screen