I am new to linux.

I made a python script that takes two inputs: a directory name and a file name. The file contains a pattern in each line. The output of the script is all the files that match the pattern and are in the given directory or its subdirectories.

Now I want to be able to invoke this python script using a command, like this:

user@machine:~$ search directory_path file_path

How can I do that?


Put the script in ~/bin if it is for a single user. If it is for multiple users put it in /usr/local/bin.

If you put it in /usr/local/bin, have it owned by root. (Enter root password where necessary)

sudo cp script /usr/local/bin
sudo chown root:root /usr/local/bin/script
sudo chmod 755 /usr/local/bin/script

Ubuntu automatically puts ~/bin on your user path (you have to log out and back in or start a new log in shell) and /usr/local/bin is already on the default path.

Make sure #! /usr/bin/env python is at the very top of the script and that the script is executable (chmod 755)

  • 1
    2 doubts. 1. If I have bash script do I need to do same as for python script 2.if I have saved my file in /usr/local/bin than I have add sudo before command??? – TLE Mar 14 '13 at 9:33
  • 1
    For a bash script , add #! /bin/bash at the top. If you need to run the script as root, I advise the script be owned by root and you call the script with sudo. – Panther Mar 14 '13 at 13:15

Make an alias for your command using this syntax:


This way, you made your own shortcut to your command ( And of course, you can pass parameters to your alias, as it's your command, nothing less, nothing more. Also you can link this alias to run an script, for example, I made an alias to open steam + dota2 instantly like this:

alias steamz='sh ~/Games/steam.sh'


But, your shortcut will be removed once you close your Terminal, so to save this alias and use it daily, add this piece to ~/.bashrc, this file contains commands running on each Terminal run, so if you add your alias definition to this file, your alias will be automatically defined on each Terminal run.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.