Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 890  / 2 Years ago, sat, january 15, 2022, 3:50:32

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?


More From » 12.04

 Answers
3

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)


[#32226] Saturday, January 15, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aslity

Total Points: 336
Total Questions: 133
Total Answers: 98

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;