Linux Blog

How Android apps are useful to get new blogging ideas

Filed under: General Linux — at 9:51 pm on Thursday, October 18, 2012


This post is a guest post written by Brianne. She is blogger by profession. These days she is working on online promotion for Go Pilot

It is true that the bloggers will need some applications which will help them to connect with their blogging on the move. So the Android applications come handy in this connection. Moreover, you will keep touch always through these applications with your blog. Since, the Android applications provide the ample advantages to the bloggers. Even, these Android applications will give you an extra fillip for running smoothly your blogging habit. 

(Read on …)

Tar Archive Mischief.

Filed under: Shell Script Sundays — at 1:22 am on Sunday, June 1, 2008

I ran into a problem the other day when I downloaded a particular tar.gz archive (Simple Machine Forums to be specific.) The problem was that despite how good SMF might be the developers did not put the files in a folder before they tar.gz’d it. This is not the only time I have ran into this problem, a lot of developers actually do it. Over time its become a habit to assume that its in a folder.

Here’s a solution to delete all files that were extracted from an archive:

tar xvzf [filename] > [filename]-filelist.txt
cat filelist.txt | while read i; do rm $i; done;

If you want to, you can do a dry run of the script by putting an echo in front of the rm statement and looking at the output. All files that you had e.g index.php will have most likely been overwritten from the extract in the first place so, it doesn’t hurt to delete them.

Once you have deleted all of the files from the archive you can simply create a directory and use the following to extract to it:

tar xvzf  [filename] -C [yourdir]

Decision making in Bash If / Then / Else statements and Cases

Filed under: Shell Script Sundays — at 3:44 pm on Sunday, August 5, 2007

There comes a time in every shell script where a decision has to be made.

To make a decision in bash the following if then else syntax can be used:

if [ condition ]


[ elif [ condition ]


statements ]

[ else

statements ]


Anything in non bold [ brackets ] is optional, and they should not be typed but the bold in them is required. Anything in bold must be typed. Statements are generally other commands or flow control statements.

To give an example of how to use bash if then else statements in the real world take the following scenario:

A system administrator has a strict habit of firing people that have too many .png files. He checks the systems regularly and makes sure that nobody has too many. The following script will display a message depending on the number of .png’s that are in the directory.

gif_count=$(ls | grep .png | wc -l)
echo “Number of PNG’s: $gif_count”
if [ $gif_count -lt 10 ]
echo “He will be happy, you have less than 10 files”
elif [ $gif_count -gt 10 ] && [ $gif_count -lt 20 ]
echo “Consider deleting some files”
echo “you have too many files, DELETE SOME BEFORE HE FINDS OUT!”;

Using Cases.

Cases are similar to if statements in that they match a expression and perform a task if the pattern is matched.

bash case syntax:

case expression in

pattern1 ) statements ;;

pattern2 ) statements ;;


This is fairly simple and some people find this easier than doing if statements for simple logic. Take the following real world example:

The system administrator has recently gone on a bigger power trip than before. Since people got wise about using png’s and started saving images in other file formats he is now monitoring png’s gif’s and jpg’s. To combat the problem, you can use a case to count how many files you have of each type. (This is intended as an example, there are many ways to accomplish this task, this is just to demonstrate how cases work)

#set all variables to 0

# start loop
for wc in $(ls); do

case “$wc” in
*png ) let png=$png+1 ;;
*gif ) let gif=$gif+1 ;;
*jpg ) let jpg=$jpg+1 ;;

# end loop

echo “Png’s $png”;
echo “gif’s $gif”;
echo “jpg’s $jpg”;

There you have it, two ways to make basic decisions in bash. Just figure out what you want to do then use an if then else, or a case statement to do the logic. I myself prefer if statements over cases as they make more sense to me and I find it easier to perform logic within ifs.

Programs used in this post
ls, echo, grep, wc