Quick Links
Bash scripting is one of the best ways to level up your Linux expertise, but it can be intimidating to learn. Here’s what you need to know about Bash and how you can get started with basic scripting.
What Is Bash in Linux?
Bash (Bourne-Again SHell) is the default Command Line Interface (CLI) that you’ll use in most Linux distributions. It’s the interpreter that you use within the Terminal. You can use it to install apps, run command-line programs, and add new functionality via scripting.
Shell scripting lets you do things in Bash that you’re able to do with other basic programming languages, all with convenient access to your operating system and files. Commands in the Terminal are often very simple scripts. You can take your use of the Terminal to the next level bywriting your own Bash scripts.

Bash and other CLI shells are more difficult to use than a Graphical User Interface (GUI) utility, but they do have some advantages:
What Can You Use Bash For?
Bash scripting is useful for automating basic tasks. You’ll have a slow start when you first start scripting, but as you grow more confident and knowledgeable, you’ll find ways to finish nearly any complex task with just a few minutes of focused scripting.
One easy way you can start using Bash is to make use of cron, a Linux service that schedules tasks. You can use it to run specific scripts or other tasks at particular times or intervals. cron uses a text file (the crontab, or ‘cron table’) to track which commands are scheduled and when.

For example, if you wanted to make your Ubuntu system automatically update its package repository and software once per week, a well-written cron task could help. You could start making this task by opening the Terminal, enteringnanoto open a text editor, and writing the following script in a file namedautoupdate.sh:
After writing, saving, and closing that script (ideally saving it within yourhomedirectory), the next step is adding it to your crontab. you’re able to open crontab for editing by entering the following command in the Terminal:
Once crontab opens, your next step would be to add the task. To make autoupdate.sh run once per week, you would need to write something like this before saving and exiting from the file:
you may evenwrite cron tasks to clean up your filesoruse the at command to schedule non-repeating tasksthrough the Bash shell. By combining both of these utilities, you can automate most of the repetitive or predictable tasks that you need to do on your computer. You can create scripts to automatically:
The best way to learn Bash scripting is by example. There is a practically limitless number of ways that you can improve your system with Bash. Following tutorials and reading about syntax will gradually improve your ability to write your own scripts. If you’re interested in learning more about Bash, consider trying:
How to Script With Bash in Linux
If you’re short on ideas, you can also learn Bash by playing online games. Some of the best games you can play to learn Bash scripting include:
How to Run a Bash Script in Linux
You cancreate and run a Bash script in Linuxusing your preferred text editor.vimandnanoare both great options, and you can open either by entering their name in the Terminal. You can save and name your file right away, ensuring that its file name ends with.sh(the shell script file extension).
Once you’ve written your script, you can run it with the following Terminal commands:
You might need to start small with Bash scripting. With enough practice, however, it’s possible to turn complex, unwieldy, repetitive tasks into tiny challenges that you can solve in minutes. It’s an essential skill for tech professionals and power users, and the best place to learn is just one Terminal window away.