Saturday, October 30, 2010

The power of Linux, Lessons for Dummies part 1

Here is the beginning of a big Linux tutorial.
In most of the lessons we'll use bash.
Bash is the common Linux Shell, and stands for Bourne again shell!
The tutorials will have 2 parts: The case, that's the problem we face, a solution with common Windows knowledge, and a solution with Bash Script.
Vaslabs trials have made in an Ubuntu 10.04 Lucid Linux Machine, but there is no difference at all in every distribution you have. If you are new to Linux, Ubuntu is the best choice for you.

The Case:
We want to create 11 folders, each one will have the name photos and then a year number starting from 2000. In these folders we will put later some photos according the year they have been taken.

Solution:
1) In windows, or in Linux using file browser:
Go to the place you want to create the folders, right click, create folder, give it a name, e.g. photos2000, and keep doing that until you reach photos2010.
2)With a bash script:
So we want to make 11 folders in a specific location. It is not necessary to go to that location, so we won't change directory. Since you are new to Linux we won't even use a for, but will suggest that best solution later.
Even without a for the solution is faster.
So for that job will need:
1)a terminal (to write the commands)
2)the command mkdir which means make directory
3)the up arrow(it's on the keyboard)
4)and the path we want to make our folders.

So a simple solution is:
open the terminal.
write: mkdir /path/photos2000
press enter.
A folder named photos2000 has been created in /path.
then press the up arrow
The mkdir /path/photos2000 will show again.
Press backspace one time and then press 1.
now you will have mkdir /path/photos2001
press enter. etc...

But that is a very simple, and stupid solution. This is file browser thinking.
We can automate the above procedure by adding a for command.
So we'll need a couple of extra tools:
1) the for command
2)the let command (let allows mathematical operations)

So write that script instead.
for ((i=0;i<=10;i++)); do let number=2000+$i; mkdir "photos"$number; done
And press enter. The folders shall be created successfully. If you have any problems, don't
hesitate, write your problem on our facebook wall, or here as a comment.

No comments:

Post a Comment