How to Create a File in Shell Script

How to Create a File in Shell Script thumbnail
How to Create a File in Shell Script

A shell script is a text file on the Linux and Unix operating systems that contains a sequence of commands that are meant to be executed in order. It is executed by the system shell. There are various system shells, including bash, tsch and c shell. The bash shell is one of the most widely used system shells on the Linux operating system. The "touch" command can be used within a shell script to create a file.

Instructions

    • 1

      Open a blank document in any text editor.

    • 2

      Type line "#!/bin/bash" to start the shell script. You can change this line to reflect the shell you want to use.

    • 3

      Type the line "touch filename.txt" to create a blank file named "filename.txt." You can replace "filename" with any descriptive file name.

    • 4

      Type the line "ls -la" to print out the files in the directory.

    • 5

      Save the shell script as "create_file.sh" and close the file.

    • 6

      Open a terminal window.

    • 7

      Type the command "chmod +x create_file.sh" to make the file executable.

    • 8

      Type the "./create_file.sh" to execute the script. The script will create the file called "filename.txt" and print out a list of all the files in the directory along with the creation date of each file.

Related Searches:

References

  • Photo Credit Thinkstock Images/Comstock/Getty Images

Comments

You May Also Like

Related Ads

Featured