开发者

How to change the permissions on the files nested in subdirectories with single ack command?

开发者 https://www.devze.com 2022-12-28 18:49 出处:网络
I have the following directory tree. When moving around to/from VirutalBox, the file permissions are changed.

I have the following directory tree.

When moving around to/from VirutalBox, the file permissions are changed. So, I know/not that ack can be used to do it recursively from the command line.

Can someone please show the command for ack to chmod 644 all the *.rb files?

[~/dotfiles (master)⚡] ➔ tree
.
|-- cap_bash_autocomplete.rb
|-- dotfile_bash_aliases
|-- dotfile_bashrc
|-- rake_bash_autocomplete
|-- tidbits
|   |-- README
|   |-- lib开发者_运维技巧
|   |   `-- aliasdir.rb
|   |-- mhsrc
|   |-- proxy.pac
|   |-- rails-template.rb
|   `-- tasks.thor
`-- usage


You don't need xargs. find has the options exec, execdir and ok builtin:

find ~/dotfiles -name "*.rb" -exec chmod 644 {} +

execdir executes the command from the subdirectory, where the file is sitting, ok asks for confirmation. You may end the command with \; or +, the plus will execute multiple files at once which will sometimes gain more performance, but is often not relevant, and may sometimes harm performance, or not even work (if the underlying command doesn't allow processing of multiple files).


I have no idea what ack is, but you can do it with standard shell commands:

find <top of directory tree> -name \*.rb | xargs chmod 644
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号