How to remove execute permission from all txt files in Ubuntu

I have a Ubuntu 16.04 64 bit desktop in which I had installed wine in the past and later removed it. Now when I try to open txt files in nautilus, in many cases I get a dailouge box saying the file is executable and whether should I run or display it. I am annoyed by this behaviour and want to revoke execute permissions from these files. If anyone can show me how to do this it will be helpful.

Thanks

2

2 Answers

To remove the execute bit from all .txt files in your home directory and all its subdirectories, try:

find "$HOME" -type f -executable -name '*.txt' -execdir chmod a-x {} +

How it works:

  • find "$HOME"

    This starts find looking for files starting with your home directory and recursively including all subdirectories

  • -type f

    This tells find to look only for regular files, not directories.

    It is important to restrict the search to regular files because, if we remove the execute bit from a directory, that directory become inaccessible.

  • -executable

    This tells find to look only for files which have the executable bit set.

  • -name '*.txt'

    This tells find to look only for files whose names match the glob *.txt.

  • -execdir chmod a-x {} +

    This tells find to execute chmod a-x on any such files found.

    We use -execdir, as opposed to -exec, because it is more reliable should the names of directories change while this command is running.

    The + at the end of the form -execdir chmod a-x {} + tells find to run fewer instances of chmod by putting many files on each chmod command line if possible.

6
find . -name "*.txt" -exec chmod a-x {} \;

find command is self explanatory. It finds the files according to given arguments. Usage : find location comparison-criteria search term

find . -name "*.txt" -exec chmod a-x {} \; Here . means root directory, -name "*.txt" means find all files which include ".txt" in their names. -exec chmod a-x {} \; means execute the chmod command on all matching files.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like