linux

Finding lasted modifies files on Linux

Posted in find, linux, tips on May 13th, 2010 by fseek – Be the first to comment

Looking for a file that you just modified or downloaded? That’s the easy way:

1- Files modified in the last 5 minutes:

$ find ./ -type f -mmin -5

 
2- Files modified in the last hour:

$ find ./ -type f -mmin -60

 
3- Files modified in the last day:

$ find ./ -type f -mtime -1

 
If you want to process them and they have spaces in the name, use:

$ find ./ -type f -name “*.txt” -mtime -1 -print0 | xargs -0 cat

 
This one will cat all text files modified on the last day (with spaces or not in the name).

Removing empty lines from the top of a file

Posted in linux, tips on May 4th, 2010 by fseek – Be the first to comment

Nice one liner:

find ./ -type f | sed -i ‘/./,$!d’

Recovering deleted files on Linux

Posted in linux, tips on April 28th, 2010 by fseek – 5 Comments

Did you just rm’ed -rf a file by mistake? Well, that just happened to me as well.

I spent the whole day working on a PDF document and decided to forward it to a co-worker for review. Since the PDF was quite big, I gunzipped it:

$ gzip work-temp.pdf

Then I realized that my co-worker uses Windows, so I had to zip instead of the gzip. That’s what I did:

$ rm work-temp.pdf.gz
$ zip work-temp.pdf
zip warning: name not matched: work-temp.pdf

Uh-oh. I forgot that gzip deletes the original file. Crap!

To recover my file, I used my big friend “foremost”, a file recoverer for Linux. To install on my Ubuntu box, I did:

# apt-get install foremost

To recover my files, I ran foremost, specifying my partition (/dev/sdb2) and the file type (PDF):

# foremost -s 100 -t pdf -i /dev/sdb2
Processing: /dev/sdb2
|**********************************|

Once it was done, we had all the PDF files it could recover at /root/output/pdf. Easy and simple!

Note, that it will not recover the original file names. So all the PDF files (or whatever file type you were looking for) will be stored as /root/output/pdf/12345.pdf, /root/output/pdf/123456.pdf, etc). You will have to check each one to find the one you wanted.

Grep and long lines don’t mix too well

Posted in linux on April 16th, 2010 by fseek – Be the first to comment

Having issues using cat/grep and long lines? Well, we too!

Today we were trying to use “grep” to, well, grep some lines from the output of a tool we were testing. Something like that:

# /usr/local/bin/ourtool |grep -E “error: .* string”

It was matching fine when the string we were looking for happened on small lines (less than 4k). However, some of them were above 4k in size and if the string was after 4k character in the line, grep wouldn’t match.

We looked for that on google and all we found was some information about the TK_GREP_LINE_MAX environment varialble that didn’t make a difference for us.

At the end, we solved the problem by sending the output to a file and grepping it directly (instead of piping to grep):

# /usr/local/bin/ourtool >/tmp/logfile
# grep -E “error: .* string” /tmp/logfile

Why the later worked and the first one didn’t? I have no clue. Do you?

Real reasons why most companies don’t waste their time developing software for Linux

Posted in linux, rant on March 12th, 2010 by fseek – 13 Comments

I am a Linux fan and I use that all the time, but there are some things that really, (REALLY) have to be changed before most companies will even start to take it serious. Do you want to see that cool application ported to Linux? Or that software your uncle just bought at Best Buy? Here’s why it is not supported on Linux:

 
1-There is no binary compatibility between distributions (or even between versions of the same distribution)

That’s so annoying and probably THE reason why most companies don’t write software for Linux. If I get an executable that I compiled on my Windows XP, it will run on Windows 2000, Vista, 2003 and maybe on Windows 98. People complain about Microsoft and all the stuff they do wrong, but they are good at backwards compatibility. Linux should do the same!

Why, God, why the binary I just compiled on Ubuntu 7.10 won’t work on my 9.04? Why won’t it work on Red Hat?

I know there are technical issues, like dynamic libraries, GCC version, etc, but that is a solvable problem. It shouldn’t have to be that way anymore. My own company won’t even bother wasting time migrating our code to Linux because of that. Within the same distribution, the code should be backwards compatible, and the Red Hat, Ubuntu, SuSe guys need to talk to each other to get in sync! We, as the community have to demand that they do so. Let the competition to the side a bit and get that sorted out. It is just going to be better for everyone in the long run.
*crap, even a binary I compile on Solaris 9, works well on Solaris 7 and 8…

 
2-Installation nightmare!

I know, I know.. apt-get is awesome, yum is pretty good! synaptic allows you to install “anything” you want. Users don’t have to worry about dependency…

However, there is no universal way to install an application. Companies used to build Windows software have one installer and that’s it. Can you imagine having to do one RPM, one DEB, one .tar.gz, etc? Each one with different binaries because the SuSe RPM doesn’t work at Red Hat? I am not talking about the complications that the end-user faces with that, but the issue that software developers have with it.

If the Linux community want companies to start developing and migrating their software to Linux, we need an universal installer. Yes, Fedora can still use yum, same for Debian and apt-get. But they all need to support a single installation method. Which one? I don’t care, but they have to talk to each other and decide.

 
3- Not enough user base and complacent users

Linux users should stop using Wine. Should stop dual booting to Windows to use a software that is not supported on Linux. We have to complain to the companies and let them know that they are losing a client and money because of that.

 
4- VI is still installed by default everywhere!

That’s a crime! Who will waste time with Linux if it still comes with “vi” by default? Emacs is so much better that it is not even funny.

Ok, I am joking… I love vi :)

Generating a photo gallery on Linux

Posted in desktop, linux, tips on March 5th, 2010 by fseek – Be the first to comment

Looking for a quick way to create a HTML photo gallery on Linux? That’s how I did it.

I have a small child and my wife asked (err tasked me) to create a web site with his pictures. I didn’t want to host his pictures on picasa or flickr, so I used a simple Unix tool to create an HTML gallery and posted it on my on site.

The tool? jigl. Perl-based, command-line and very easy to use. To install on Ubuntu, I just did:

# apt-get install jigl

To create the gallery, you just need to run the command and specify a directory. For example:

$ jigl /home/me/pics/1yo

And it will create the gallery inside /home/me/pics/1yo/web/ . Note that the default theme and options are a bit ugly, so I decided to download the white theme (much better) and ran it with some extra options to reduce the noise from the final HTML:

$ cd /home/me/.jigl/themes/
$ wget http://xome.net/projects/jigl/themes/white-theme.tar.gz
$ tar -zxvf white-theme.tar.gz
$ cd /home/me/pics
$ jigl –theme white -it “My babys pics” -noskb -nosxy -nogi 1yo

There is an example of the white theme here: http://xome.net/projects/jigl/themes/white/

Hope you like!