How to give executable permission to all Python scripts in Linux?

后端 未结 4 895
说谎
说谎 2020-12-21 04:41

Suppose I have a python script called a.py like this:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author    : Bhishan Poudel
# Date             


        
4条回答
  •  鱼传尺愫
    2020-12-21 05:14

    Using the idea of @sjsam, I did following:

    Suppose I have a file hello.py in any location.

    cd to that location
    find $PWD -type f -name "*.py" -exec chmod u+x {} \;
    ./hello.py
    
    # Now, i can create any number of .py files in that folder and run ./filename
    
    # Note: if we are running as user permission, and also have sudo access,
       we can also do:
       sudo -H find $PWD -type f -name "*.py" -exec chmod u+x {} \;
    
    We should not use sudo unless absolutely necessary.
    

    Thanks to sjsam.

提交回复
热议问题