How to Write a Script for Making Directories

On the Linux and Unix operating systems you can write a script that can create new directories using one of the shells (bash, sh, csh). A shell script uses common Unix commands to perform automated tasks. The following script requests the name of the directory from the user, creates the directory and returns the name and time the directory was created. It is written for the bash shell. Other shells use similar commands.

Instructions

    • 1

      Open a text editor such as vi or gedit.

    • 2

      Type the line "#!/bin/bash" to begin the script. This line tells the operating system which shell to use.

    • 3

      Type the next two lines to ask the user for the name of the directory and place that name in a variable called "directory."

      echo "What is the name of the directory?"
      read directory

    • 4

      Type the line "mkdir $directory" to create a directory with the name specified by the user.

    • 5

      Type the following two lines to let the user know that the directory has been created and show the time it was created.

      echo "Your directory has been created:"
      ls -la | grep $directory

Related Searches:

References

Comments

You May Also Like

  • How to Make an Online Directory

    Online directories contain helpful information to users who are searching for phone numbers, addresses and websites of listings such as restaurants, graphic...

  • How to Make a Movie Script

    If you love movies and have a lot of imagination, you may be thinking it would be fun to write a movie...

  • How to Write a TV Commercial Script

    Television commercials sell products. All of the flashy images, effects and dialogue you see and hear on the television screen start with...

  • How to Write an FTP Script

    FTP stands for file transfer protocol. It is exactly what it implies, a way in which files are transferred or fetched across...

  • How to Make a Logon Script

    Logon scripts can help a network administrator perform multiple functions such as mapping a network drive, which is basically assigning a shared...

  • How to Write a Bash Script in UNIX

    Enter commands in the next few lines. For example, the following script moves the contents of a directory into a new directory...

  • How to Write a Script

    Exciting and innovative scripts are essential to performing arts. Writing scripts for plays, films, TV dramas or sitcoms has many differences while...

  • How to Write a Radio Script

    Learning how to write a radio script is critical for proper execution of a radio performance. The script must include various cues...

  • How to Write a Script to Start Programs

    Linux and Unix users can use the bash shell to create a script that will open one or more programs. Once created,...

  • How to Make a New Directory in Linux

    Directories are an important component of keeping your files and your hard drive organized in Linux. Each directory can have its own...

Related Ads

Featured