Apply permissions only to files

chmod 644 $(find . -type f)
To apply only to dirs: chmod 755 $(find . -type d) Use -R parameters for recursive walk.

By: takeshin
2010-06-10 07:57:53

These Might Interest You

  • -x, --extract, --get extract files from an archive -p, --preserve-permissions, --same-permissions extract information about file permissions (default for superuser) -f, --file=ARCHIVE use archive file or device ARCHIVE -v, --verbose verbosely list files processed

    tar -xvpf file.tar.gz
    shajeen · 2014-04-25 10:23:03 0
  • This may seem like a long command, but it is great for making sure all file permissions are kept in tact. What it is doing is streaming the files in a sub-shell and then untarring them in the target directory. Please note that the -z command should not be used for local files and no perfomance increase will be visible as overhead processing (CPU) will be evident, and will slow down the copy. You also may keep simple with, but you don't have the progress info: cp -rpf /some/directory /other/path Show Sample Output

    dir='path to file'; tar cpf - "$dir" | pv -s $(du -sb "$dir" | awk '{print $1}') | tar xpf - -C /other/path
    starchox · 2010-01-19 19:05:45 0
  • requires: a directory with borked permissions and a backup directory that has the correct permissions. works with chown or chmod

    for x in `find /dir_w_wrong_ownership/`; do y=`echo "$x" | sed 's,/dir_w_wrong_ownership/,/backup_dir/,'`; chown --reference $y $x; done;
    foucault · 2011-02-21 22:15:33 0
  • The -r is for recursive, -F for fixed strings, --include='*.txt' identifies you want all txt files to be search any wildcard will apply, then the string you are looking for and the final * to ensure you go through all files and folders within the folder you execute it. Show Sample Output

    grep -rF --include='*.txt' stringYouLookFor *
    maxleonca · 2010-02-12 18:07:07 0

What Others Think

Could get an arguments too long error.
kaedenn · 419 weeks and 2 days ago
Very cool! I'm curious though about how many files can be passed to chmod this way as args.. this is recursive after all.. I would prefer xargs like: find . -type f -print0 2>/dev/null |xargs -0 -I'{}' chmod 644 '{}'
AskApache · 419 weeks and 1 day ago
I usually use built-in reverse of this: chmod a+X makes directories readable without making files executable.
pornel · 419 weeks and 1 day ago
Correct me if I'm wrong but find, by very nature is recursive; adding the -R operator to chmod would be redundant.
sudopeople · 419 weeks and 1 day ago
Hmm, xargs is way too long ;-) why not find . -type f -exec chmod 644 {} \; ?
oernii2 · 419 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: