• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

A view of Basic commands, creation of script file, and creation of cron job in Shell Scripting.

  • 00:56 ls
  • 01:12 mkdir scripts
  • 01:21 cd scripts
  • 01:40 echo $SHELL
  • 01:54 pwd
  • 02:01 date
  • 02:36 vim test.sh
  • 03:09 ls -la
  • 03:26 chmod +x test.sh
  • 03:31 ls -la
  • 03:40 ./test.sh
  • 03:49 ls -la
  • 03:57 vim test1.sh
  • 04:19 chmod +x test1.sh
  • 04:26 ./test1.sh
  • 04:30 ls -la
  • 04:36 vim store.txt
  • 05:06 date
  • 05:26 crontab -e
  • 06:07 crontab -l
  • 06:19 date
  • 07:08 ls -la
{{postValue.id}}

Basic commands, creation of script file, and creation of cron job in Shell Scripting

Introduction:

A shell script is a listing of commands in a computer program that is run by the Unix shell which is a command-line interpreter. It has comments that illustrate the steps. The various operations performed by shell scripts are program execution, file manipulation, and text printing. Steps: snap1

Basic commands:

List the directory:

[linuxhelp@linuxhelp ~]$ ls
Desktop  Documents  Downloads  minio  Music  Pictures  Public  Templates  Videos

Create a directory:

[linuxhelp@linuxhelp ~]$ mkdir scripts

Switch to scripts directory:

[linuxhelp@linuxhelp ~]$ cd scripts

Type the following command to find what type of shell we using:

[linuxhelp@linuxhelp scripts]$ echo $SHELL
/bin/bash

Type the following command to know the Present working directory:

[linuxhelp@linuxhelp scripts]$ pwd
/home/linuxhelp/scripts

Type the following command to see the date:

[linuxhelp@linuxhelp scripts]$ date
Thu Apr 22 02:44:44 PDT 2021

Create test.sh script file:

[linuxhelp@linuxhelp scripts]$ vim test.sh

snap2 List the directory:

[linuxhelp@linuxhelp scripts]$ ls -la
total 8
drwxrwxr-x.  2 linuxhelp linuxhelp   21 Apr 22 02:46 .
drwx------. 19 linuxhelp linuxhelp 4096 Apr 22 02:46 ..
-rw-rw-r--.  1 linuxhelp linuxhelp   31 Apr 22 02:46 test.sh

Give the execute Permission for that script file:

[linuxhelp@linuxhelp scripts]$ chmod +x test.sh 

Now, check the permission for the test file:

[linuxhelp@linuxhelp scripts]$ ls -la
total 8
drwxrwxr-x.  2 linuxhelp linuxhelp   21 Apr 22 02:46 .
drwx------. 19 linuxhelp linuxhelp 4096 Apr 22 02:46 ..
-rwxrwxr-x.  1 linuxhelp linuxhelp   31 Apr 22 02:46 test.sh

Run the Script file by using following command:

[linuxhelp@linuxhelp scripts]$ ./test.sh 
 Welcome To Linuxhelp

List the directory:

[linuxhelp@linuxhelp scripts]$ ls -la
total 8
drwxrwxr-x.  2 linuxhelp linuxhelp   21 Apr 22 02:46 .
drwx------. 19 linuxhelp linuxhelp 4096 Apr 22 02:46 ..
-rwxrwxr-x.  1 linuxhelp linuxhelp   31 Apr 22 02:46 test.sh

Create one more file:

[linuxhelp@linuxhelp scripts]$ vim test1.sh

snap3 Give the execute permission for script file:

[linuxhelp@linuxhelp scripts]$ chmod +x test1.sh 

Run the Script file by using following command:

[linuxhelp@linuxhelp scripts]$ ./test1.sh 

List the directory:

[linuxhelp@linuxhelp scripts]$ ls -la
total 28
drwxrwxr-x.  2 linuxhelp linuxhelp    76 Apr 22 02:53 .
drwx------. 19 linuxhelp linuxhelp  4096 Apr 22 02:53 ..
-rw-rw-r--.  1 linuxhelp linuxhelp   380 Apr 22 02:53 store.txt
-rw-------.  1 linuxhelp linuxhelp 12288 Apr 22 02:51 .store.txt.swp
-rwxrwxr-x.  1 linuxhelp linuxhelp    21 Apr 22 02:53 test1.sh
-rwxrwxr-x.  1 linuxhelp linuxhelp    31 Apr 22 02:46 test.sh
[linuxhelp@linuxhelp scripts]$ vim store.txt 

snap4 Type the following command to see the date:

[linuxhelp@linuxhelp scripts]$ date
Thu Apr 22 02:54:50 PDT 2021

Type the following command to create a cron job:

[linuxhelp@linuxhelp scripts]$ crontab -e
no crontab for linuxhelp - using an empty one
crontab: installing new crontab

Check the content in cron file:

[linuxhelp@linuxhelp scripts]$ crontab -l
01 03 22 04 05 mkdir cron /home/linuxhelp/scripts/

Type the following command to see the date:

[linuxhelp@linuxhelp scripts]$ date
Thu Apr 22 03:01:02 PDT 2021

List the directory:

[linuxhelp@linuxhelp scripts]$ ls -la
total 28
drwxrwxr-x.  3 linuxhelp linuxhelp    88 Apr 22 03:01 .
drwx------. 20 linuxhelp linuxhelp  4096 Apr 22 02:58 ..
drwxrwxr-x.  2 linuxhelp linuxhelp     6 Apr 22 03:01 cron
-rw-rw-r--.  1 linuxhelp linuxhelp   380 Apr 22 02:54 store.txt
-rw-------.  1 linuxhelp linuxhelp 12288 Apr 22 02:51 .store.txt.swp
-rwxrwxr-x.  1 linuxhelp linuxhelp    21 Apr 22 02:53 test1.sh
-rwxrwxr-x.  1 linuxhelp linuxhelp    31 Apr 22 02:46 test.sh

With this method Basic commands, creation of script file and creation of cron job comes to an end.

Tags:
rebeccajazz
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is meant by a scripting language?

A

A scripting language or script language is a programming language for a runtime system that automates the execution of tasks that would otherwise be performed individually by a human operator. Scripting languages are usually interpreted at runtime rather than compiled.

Q

What is the difference between scripting and programming?

A

Programming languages are generally compiled and create an executable file, whereas Scripting languages are interpreted and do not create an executable file. Programming languages are most often used to build something from scratch, whereas Scripting languages can be used to combined existing components or modules.

Q

Is scripting harder than programming?

A

Coding with programming languages is relatively difficult as many lines of code are required for a single function. Creating a code function with a scripting language is easier as it requires only a few short and specific lines to be written.

Q

When should shell programming/scripting not be used?

A

Generally, shell programming/scripting should not be used in the below instances. When the task is very much complex like writing the entire payroll processing system. Where there is a high degree of productivity required.

Q

Can we run a shell script on Windows?

A

With the arrival of Windows 10's Bash shell, you can now create and run Bash shell scripts on Windows 10. You can also incorporate Bash commands into a Windows batch file or PowerShell script.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Owen ?
How to add SSH key to my Gitlab account

I need to add the SSH key in my gitlab account. How to do so ????

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.