create script

Posted on 2004-11-05
Last Modified: 2010-04-20
i want to create a script that will aid in automating bash commands, such as making directories, changing permissions, moving files, etc...  

How do I do this?  I am under the impression I need to make an executable file that contains these commands, but what else needs to be done?  Is there some special syntax in the file or something else?  Any links, refrences, hints?
Question by:tecumsehjoe
    LVL 38

    Accepted Solution


    # vi
    ---- -----


    mkdir -p <directory>
    chmod < permission> <directory>
    mv <source path> <target path>
    # chmod +x

    Then you can run that script
    # ./   <enter>

    LVL 10

    Assisted Solution


    to create bash script you need to :

    create file
    edit file
    first byte of file has to contain interpreter:
    make file executable
    chmod +x
    run script

    Sometimes you do not really have to use script you can use just command. For example chanage permitions for all *txt files to rwxrwxrwx in your home directory u can use command:

    find /home/yourname -iname \*.txt -exec chmod 777 {} \;

    LVL 17

    Expert Comment

    I would use aliases for this rather that individual scripts. Edit .bashrc in your home directory and add any aliases you like. They wont  work until you open a new shell or run source .bashrc. A couple of examples that I use -
    alias xe="chmod +x"
    alias log="cd /var/log"
    alias mes="less /var/log/messages"
    alias erc ="vi ~/.bashrc;source ~/.bashrc"
    xe myfile will make myfile executable. log will change to the /var/log directory etc. You can alias several comands by putting a ; between them. I would only use scripts for more complex tasks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now