0

I grasp the heading of this question odd, but I do wonder if in some situations there should be a need to take extra caution and somehow "enforce" non-recursivness when changing permissions with chmod nonrecursively (without the -R argument).

Say I have a directory ~/x. This dir has a few files, as well as a sub-dir ~/x/y that also has a few files, and I decided to make all x files executable without effecting files at y. I could execute:

chmod +x ~/x/*

Surly the chmod should do the job and it's unlikely that in any Bash version (including future versions) the POSIX logic would be changed and the above chmod would effect the sub dir as well, but I do wonder if there could be any situations in Bash (or common shells) in which chmod +x ~/x/* will also cover the y files, and how to improve my command to protect from such undesired change?

  • Are you worried that POSIX might change ~/x/* to reflect files on sub-directories also? – Inian Feb 11 '18 at 10:58
  • Yes, or some unlikely in-shell bias I might not be aware of (I usually take great caution in what I install). – user9303970 Feb 11 '18 at 11:09
2

You can use find and restricting to get only files in the current directory

find ~/x -maxdepth 1 -type f -exec chmod +x {} +

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.