Bash – How to find and run a bash script

bashfindpathshell

I have a script named script.sh. I don't know where it is in the file system, but I do know it exists.

How do I find the script, make it executable, and run it all in one line through the command line?

I would like to run it with a single command. Find, make executable and execute.

Best Answer

  1. Use the find command for it in your home:

    find ~ -name script.sh 
    
  2. If you didn't find anything with the above, then use the find command for it on the whole F/S:

    find / -name script.sh 2>/dev/null
    

    (2>/dev/null will avoid unnecessary errors to be displayed) .

  3. Launch it:

    /<whatever_the_path_was>/script.sh
    

And all at once would give; more on how to find and exec:

find / -name "script.sh" -exec chmod +x {} \; -exec {} \; 2>/dev/null 

(beware if you have more than one "script.sh", it will run them all)

Related Question