Executing commands in a shell script

Until now have been understanding shell scripting's basic concepts and syntax.We have not done anything productive yet, but we are going to have some fun in this article. We will be creating very short but useful shell scripts .

In this article we will be automating Linux's tasks.All the commands that we run or execute from terminal we can actually place them in a bash file in some logical order and execute.

Place commands in a bash file and run

Yes as simple as that put the commands that you like the most in a file or follow along me. Save and execute the following script.

ls -l
mkdir linux java
free -m

On successful completion all the commands will be executed.ls will list all the content of your current directory.mkdir will create 2 directories java and linux, free -m will show free ram,hard disk , swap sapce in mega bytes and who will list currently logged in users.

In this way you can automate your Linux tasks.You can be more creative here .Use your imagination and make it useful.

Bash Script for cleaning,updating and upgrading Linux

This is definitely useful .We have to update Linux so often so we have to type some lengthy commands so let's wrap those into a single command. Save and execute the following command.

apt-get clean && apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y

Above script will clean your unnecessary packages then it will download and update the latest packages and finally if new distribution is available it will upgrade that.

Copy files with shell script


echo "Enter file  to be copied"
read old 
echo "Enter new file name "
read new
if cp $old $new 
echo "file successfully copied"
echo "file does not exits"

In the way guys you can use mv command for renaming and -r for copying and renaming directories.