views:

65

answers:

2

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
+1  A: 

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
JayM
I'll try it out. And btw, here is what ack is http://www.fosscasts.com/screencasts/15-Power-Searching-with-Ack
Millisami
I tried. That works. Thanks. Now there is another situation, what if I want discard some directories??
Millisami
`find ~/dotfiles -wholename ’~/dotfiles/skip’ -prune -o -name "*.rb | -exec chmod 644 {} +"` You may read `man find` for additional information and mark an answer as helpful (click arrow up), to guide others.
user unknown
A: 

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).

user unknown