Sunday, May 4, 2014

Copying multiple music files from multiple directories to a single destination

I came across another requirement of doing some task quickly by using the power of Linux shell commands. I had a directory called "Entertainment" which contained a huge collection of various kinds of files. One contained a collection of English songs while another contained Sinhala songs. Some other directories contained some miscellaneous things such as relaxing piano tunes, movies and stuff.

Suddenly, oneday I thought I should copy the mp3 music I have into my phone so that I can listen to them on the go. Filtering out the mp3 files from the complex directory hierarchy and copying them to a single destination directory seemed a hard work if I do it manually one by one. This is where the power of Linux shell comes into play a role. I had to search in the web to find the correct combination of commands to do the trick on the way I wanted it. Here is what finally I used to copy the mp3 files distributed over a hierarchy of directories inside the "Entertainment" directory into a single destination which is "~/Desktop/mp3music/".

find Entertainment/ -iname "*.mp3" -type f -exec cp {} ~/Desktop/mp3music/ \;


Sunday, April 20, 2014

Happiness on the way

Usually I stick around same places without traveling to new places. That's how I used to live for so many years. However, last 12 months proved me that there's a different kind of interest inside my body. I discovered that traveling to new places and exploring places where I have never been before is something that recharge the internal batteries of my body and refresh my imagination. I got the chance to travel long distances during last 12 months and sometimes I took the decision to step outside and travel when I did not feel like doing things which I was supposed to do. I know, there are lot of people who love to travel. It's not just about traveling to a new place that I'm talking about. This is about looking at every little detail of what we see and hear while being a complete stranger of a place and how the new train of thoughts affect our thinking pattern.

It's a long and a much painful story of how I returned home after taking one of the most difficult decisions I've made in my life. It is true that I had to step back from my first attempt towards the Ph.D dream. Besides getting more and more willingness to work for that dream, I earned an insight about life by being to new places during that troublesome time period. I never thought before that physically moving to different places and seeing around has this much great impact on my mind. A long bicycle ride in Ulsan (South Korea), another long bicycle ride along the Sincheon river in Daegu (South Korea) and a one day tour around Chiang Mai (Thailand) can be highlighted as some of the enlightening journeys. It is true that I've been traveling to many other places during that time period but somehow these few occasions added something into my thinking pattern than any other.

The first bicycle ride in Ulsan provided an important discovery of traveling for myself. That is, riding a bicycle along a silent road for a very long distance where I've never traveled before gives a great incomparable feeling to anything else. In Ulsan, when I was riding the bicycle, sometimes there was a river flowing parallel to me. Sometime there were paddy fields and other farm lands which cover the eyesight to the infinity. The sun was setting over the horizon. All those problems that bothered me seemed insignificant and pointless in front of the excitement filled into my body by the environment. The bicycle ride along the Sincheon river is another beautiful journey. There, you always have the river from one side parallel to your bicycle path. You can keep watching the river flowing throughout so many miles along the way. You can have an uninterrupted ride without facing road junctions or motor vehicles in your riding path, allowing you to enjoy the fresh thoughts of your mind which makes you feel better.

The tour around Chiang Mai was a completely different experience. I signed up for a one day tour. In an early morning, a jeep came and picked me from the hotel where I was staying. We went to few other hotels around the city to pick few more tourists. The fellow travelers with me in the jeep included an old Canadian couple, a young couple from UK, two young sisters from Chile, a French guy and a South African guy. There were few others but I can't remember where they came from or any other information. After having all the people on board, the journey began. We were taken to different far away places from the Chiang Mai urban city area. Among the list of places we traveled within that day, the bamboo boat ride and a visit to a poor village were the places which caught my mind so tightly. Throughout the journey, I had just one question in my mind; why didn't I love to travel so far in my life?. 

I've been in trips to visit different places around Sri Lanka but never revealed that I have a passion for traveling this much. Perhaps it's because so far in my life, I was looking into the future dreams so much. I was restless to achieve my academic dreams. So many other important components of a good life were missed while I was busy on academic dreams. Now I think, time has came for me to balance everything. Of course, still the academic dream is in the highest rank of my "ToDo" list. However, when one day I reach there and think back, I believe I will never feel satisfied unless I spare some more time to see the beauty of our world, the universe and everything included in it.
----- ~ * ~ -----

Saturday, April 19, 2014

Search for a string within a set of files in a directory hierarchy

Sometimes in Linux, we have to look for the existence of a particular string over
a huge collection of files distributed in a directory hierarchy. Rather than opening each file and using Ctrl+F to look for the string, we can use a command to search through a huge collection of files at once.

When searching for a particular string within multiple files such as object files,
executables and text files, we can use the following command. The "word" is the
string which we need to find within the files of current directory and also its
child directories in the hierarchy.

find . -type f -exec grep -l "word" {} +


Wednesday, March 26, 2014

Wandering around Seoul

I walked around Seoul city area in South Korea sometime back. Those days I didn't have enough time and enough peace in mind to write down a little note about it. I took lot of pictures and the main place I visited was the war memorial museum. Here we go with few selected photos from my camera. War is not something I value much, but aircrafts are obviously something that fascinates me. I saw lot of aircrafts at the war memorial museum. 












 

Tuesday, March 18, 2014

Using hibernation in Ubuntu 12.04

I missed the hibernate option in Ubuntu 12.04 since its not enabled by default in the system menu. The only option remaining was the suspend option. However, still the hibernate option is available as a command in the terminal.

First its better to check whether its OK to use hibernate command. We need to have equal or higher Swap space in hard disk than our RAM. In my current system, both are 2GB. I checked it from the system monitor application. Since the conditions are preferable, I decided to try the hibernate option. Issue the following command in terminal to hibernate the system.

sudo pm-hibernate

After entering the password, system will be turned off after few seconds. When I turn it on again, it came back to its last state without any problem. So, I hope everything works fine.

Monday, January 13, 2014

Humpty Dumpty: A Personal Voyage

In a recent day, I visited a friends house where about a 1 year old fellow was also present. His parents were playing so many nursery rhymes in a laptop to please the little guy so that he will stay calm. Among the various songs I heard there, I heard one with which I have a connection. Its about Humpty Dumpty, my good old friend. He reminds me my childhood.

Once upon a time I was a kid. I'm sure I was so little even though I cannot even guess the age. In a nice evening, I was sitting in front of the television and was eating a biscuit as I remember. My younger brother was sitting with me according to my memory but I'm not sure whether my elder brother was sitting there with us. We were waiting for Amma to make afternoon tea. The television was telecasting some kind of a kids programs with cartoons and songs. 

Now here's this little guy. He looked like an egg. He was wearing a hat and I had no idea what the nursery rhyme meant playing in the background. He was funny and looked happy in his mood. He walked on top of some place following the rhythm of the background music. Suddenly something went wrong. The little fellow lost his control and fell down from the wall where he was standing on. His face turned into red. His disfigured face reflected the pain he was suffering. I saw cracks over his body. Some people with a shocking look, gathered around him but I didn't see them put some fair effort to heal the fallen guy.  And thats all I heard about him on that day. I had tears in my eyes and I had no way to find out what happened to the poor guy. Amma was wondering what happened to me, but I think I didn't try to say anything.

From that day onwards for a long time in my childhood, whenever I see an egg, I remembered Humpty Dumpty. What exactly happened to him, why can't somebody fix him; so many questions flew around my head. He was happy for a moment. And then he is unhappy, suffering with an extreme pain till the death. When the time flies, I think I grew up and realized it was just a cartoon or something and nothing in real. However, there's a reality behind Humpty. Life is like a drop of water on a lotus leaf. The distance between the happiness and the sufferings is unimaginably small. The moment we loss it, there's nobody on this universe who can fix it for us. No matter how far we go, which wall we climb, I think its more important to save the most precious things in life which nobody else can fix for us when things go wrong.


" Humpty Dumpty sat on a wall,
Humpty Dumpty had a great fall.
All the king's horses and all the king's men, 
Couldn't put Humpty together again... "

~ *------------------------------------* ~

Tuesday, December 17, 2013

Processing PDF files in Linux

When preparing research papers on Linux using open source tools such as Latex, sometimes it is necessary to handle files in PDF format. For example, for a research paper submission, I had to attach all the diagrams and graphs included in the paper in a separate annex of the PDF file. However the Latex manuscript wants me to have my diagrams and graphs in EPS file format to be included in the paper. So I had to process the PDF of the paper and the diagrams in EPS format separately and then merge them together. For future usage, I'm noting down the tools I used and how they were utilized. 

When I prepare my diagrams I used DIA tool. Then I exported them as EPS files to be used in the Latex manuscript. If I want to convert such an EPS file to a PDF file, I can easily use a command line tool called "epstopdf". For example, lets say I have a EPS file named as "collision_ratio.eps". I can convert it to PDF format in the command line as follows.

epstopdf collision_ratio.eps

Another new requirement arose after the above conversion. The diagram in the PDF file is smaller and does not fit in to the total A4 page size. So, I wanted to resize it to the A4 size which was done by using "Ghostscript" tool as follows. The input file is "collision_ratio.pdf" and the resulting resized file will be "collision_ratio_A4.pdf".

gs  -sOutputFile=collision_ratio_A4.pdf  -sDEVICE=pdfwrite  -sPAPERSIZE=a4  -dCompatibilityLevel=1.4  -dNOPAUSE  -dBATCH  -dPDFFitPage  collision_ratio.pdf

Finally my requirement was to merge multiple PDF files together and sometimes to rearrange the pages inside the same PDF file accordingly. There are so many open source tools which can be used in Linux to perform such kind of a task. In my case I used a tool called "PDFMod". We can install it on Ubuntu Linux by the following command.

sudo apt-get install pdfmod

This tool is a GUI based tool and therefore users can graphically add many PDF files as possible, rearrange them and finally export the resulting new PDF file. It is a really useful tool for manipulating PDF files. Even though these are the tools I used for my recent work, there are so many other available tools for processing and manipulating PDF files.