There are a couple of times I have been presented with some codes as solutions to problems. My question is how do write these type of scripts myself for some fairly routine tasks?
There is number of scripting languages available. The most common under Linux might be Bash, Phyton and Perl. They all have their advantages and disadvantages. It is a very vast field. For starters I'd recommend the Bash Guide for Beginners to learn how to automate routine tasks. Bash is ideal because it is present in almost all Linux distributions and often even the default shell - when you learn bash scripting you also learn how to use the shell very effectively. So that's a plus with Bash. Personally I like Perl the most.
What all scripting languages have in common is that you write a regular text file containing commands. These files are called scripts A script file should start with a line specifying the interpreter of your choice language (i.e. the program that executes the command in your text file). An example for this line would be this:
That tells your computer the following lines are bash commands to be executed with bash shell. What the available commands are can be learned in the various guides.
Once you have written that file, you need to make it executable. Say your file is named
After that you can run the script typing:
hitting ENTER afterwards. A very easy example for a full script would be:
And that's how I wrote and executed it in gnome-terminal, which is the default graphical terminal in Ubuntu: