E-learningLatestNews

Learn Shell Scripting

Always try to Learn Shell Scripting or Shell Programming. Shell scripting gives you the ability to automate commands and repetitive tasks. Armed with the knowledge of shell scripting, you’ll be hunting down repetitive tasks in your life and scripting them out of existence. Learning to script your shell is the way to make it happen—don’t be afraid to give it a shot. 

In other words, wasting time on mundane, repetitive tasks is for the robots. Release yourself from the monotony. Therefore, learn shell scripting and automate your command-line tasks. This will save you lots of time and also save your company money.

Learn Shell Scripting

The command line is something every developer should learn and implement into their daily routine. Basically, it has become a Swiss Army knife of features behind deceptively simple commands, which allow you to gain greater control of your system, become more productive, and much more. For example, you can write scripts to automate daily, time-consuming tasks, and even quickly commit and push code to a Git repository with just a few simple commands.

Why Learn Shell Scripting?
Syed Raza: Enterprise Architect & Project Manager – CEO & Co-founder ClayDesk

“Learn how to automate scripts as it will have two effects: Career growth, save time and money.”

— Syed

Top Bash Commands

Quick note: Thus, anything encased in [ ] means that it’s optional. Some commands can be used without options or specifying files.

ls — List directory contents

ls is probably the most common command. A lot of times, you’ll be working in a directory and you’ll need to know what files are located there. The ls command allows you to quickly view all files within the specified directory.

Syntax: ls [option(s)] [file(s)]

Common options: -a, -l

In addition, some time might pass before you can reuse the name of a deleted bucket. If you want to use the same bucket name, we recommend that you don’t delete the bucket.

echo — Prints text to the terminal window

echo prints text to the terminal window and is typically used in shell scripts and batch files to output status text to the screen or a computer file. Above all, Echo is also particularly useful for showing the values of environmental variables, which tell the shell how to behave as a user works at the command line or in scripts.

Syntax: echo [option(s)] [string(s)]

Common options: -e, -n

Moreover, custom commands in Bash are known as “aliases”. Aliases are essentially an abbreviation, or a means to avoid typing a long command sequence. Basically, they can save a great deal of typing at the command line so you can avoid having to remember complex combinations of commands and options.

touch — Creates a file

touch is going to be the easiest way to create new files, but it can also be used to change timestamps on files and/or directories. You can create as many files as you want in a single command without worrying about overwriting files with the same name.

Syntax: touch [option(s)] file_name(s)

Common options: -a, -m, -r, -d


mkdir — Create a directory

mkdir is a useful command you can use to create directories. Hence, any number of directories can be created simultaneously which can greatly speed up the process.

Syntax: mkdir [option(s)] directory_name(s)

Common options: -m, -p, -v


grep — search

grep is used to search text for patterns specified by the user. It is one of the most useful and powerful commands. For instance, there are often scenarios where you’ll be tasked to find a particular string or pattern within a file, but you don’t know where to start looking, that is where grep is extremely useful.

Syntax: grep [option(s)] pattern [file(s)]

Common options: -i, -c, -n


man — Print manual or get help for a command

The man command is your manual and is very useful when you need to figure out what a command does. For example, if you didn’t know what the command rmdir does, you could use the man command to find that out.

Syntax: man [option(s)] keyword(s)

Common options: -w, -f, -b


pwd — Print working directory

pwd is used to print the current directory you’re in. As an example, if you have multiple terminals going and you need to remember the exact directory you’re working within, then pwd will tell you.

Syntax: pwd [option(s)]

Common options: options aren’t typically used with pwd


cd — Change directory

cd will change the directory you’re in so that you can get info, manipulate, read, etc. the different files and directories in your system.

Syntax: cd [option(s)] directory

Common options: options aren’t typically used with cd


mv — Move or rename directory

mv is used to move or rename directories. Without this command, you would have to individually rename each file which is tedious. mv allows you to do batch file renaming which can save you loads of time.

Syntax: mv [option(s)] argument(s)

Common options: -i, -b


rmdir — Remove directory

rmdir will remove empty directories. This can help clean up space on your computer and keep files and folders organized. Moreover, it’s important to note that there are two ways to remove directories: rm and rmdir. The distinction between the two is that rmdir will only delete empty directories, whereas rm will remove directories and files regardless if they contain data or not.

Syntax: rmdir [option(s)] directory_names

Common options: -p


locate — Locate a specific file or directory

This is by far the simplest way to find a file or directory. You can keep your search broad if you don’t know what exactly it is you’re looking for, or you can narrow the scope by using wildcards or regular expressions.

Syntax: locate [option(s)] file_name(s)

Common options: -q, -n, -i

DevOps Engineer

Keep the learning going.

Learn Bash without scrubbing through videos or documentation. ClayDesk’s course is easy to skim and features live coding environments – making learning quick and efficient.

File Test Operators

OperatorDescriptionExample
-b fileChecks if file is a block special file; if yes, then the condition becomes true.[ -b $file ] is false.
-c fileChecks if file is a character special file; if yes, then the condition becomes true.[ -c $file ] is false.
-d fileChecks if file is a directory; if yes, then the condition becomes true.[ -d $file ] is not true.
-f fileChecks if file is an ordinary file as opposed to a directory or special file; if yes, then the condition becomes true.[ -f $file ] is true.
-g fileChecks if file has its set group ID (SGID) bit set; if yes, then the condition becomes true.[ -g $file ] is false.
-k fileChecks if file has its sticky bit set; if yes, then the condition becomes true.[ -k $file ] is false.
-p fileChecks if file is a named pipe; if yes, then the condition becomes true.[ -p $file ] is false.
-t fileChecks if file descriptor is open and associated with a terminal; if yes, then the condition becomes true.[ -t $file ] is false.
-u fileChecks if file has its Set User ID (SUID) bit set; if yes, then the condition becomes true.[ -u $file ] is false.
-r fileChecks if file is readable; if yes, then the condition becomes true.[ -r $file ] is true.
-w fileChecks if file is writable; if yes, then the condition becomes true.[ -w $file ] is true.
-x fileChecks if file is executable; if yes, then the condition becomes true.[ -x $file ] is true.
-s fileChecks if file has size greater than 0; if yes, then condition becomes true.[ -s $file ] is true.
-e fileChecks if file exists; is true even if file is a directory but exists.[ -e $file ] is true.
In addition, become a HashiCorp Certified: Terraform Associate and pragmatic real world DevOps path allows you can use to build your modern application in the AWS Cloud.

Finally, mastering the Shell Scripting will give you an understanding of all the core concepts you need to gain complete control over your system.

Moreover, learn more about our AWS Certification courses and DevOps Engineer E-Degree program