Created
April 15, 2013 08:25
-
-
Save robinnorth/5386691 to your computer and use it in GitHub Desktop.
Bash: Cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chmod all files in directory, including .hidden files | |
chmod [MODE] .[a-zA-Z0-9_]* | |
# create gzipped tarball, preserving permissions | |
tar -c -p -v -z -f /home/example/www.example.com_site-2013-04-15.tar.gz -C /home/example/ . | |
# Recursively chmod only directories | |
find . -type d -exec chmod 755 {} \; | |
# Similarly, recursively set the execute bit on every directory | |
chmod -R a+X * | |
# The +X flag sets the execute bit on directories only | |
# Recursively chmod only files | |
find . -type f -exec chmod 644 {} \; | |
# Recursively chmod only PHP files (with extension .php) | |
find . -type f -name '*.php' -exec chmod 644 {} \; | |
# Change the ownership of all files owned by one user. | |
# Finds all files in /home owned by UID 1056 and changes to 2056. | |
# See: http://www.commandlinefu.com/commands/view/892/change-the-ownership-of-all-files-owned-by-one-user. | |
find /home -uid 1056 -exec chown 2056 {} \; | |
# Changing files ownership in a directory recursivley from a user to another | |
# See: http://www.commandlinefu.com/commands/view/414/recursive-ownership-change | |
chown -cR --from=olduser:oldgroup newuser:newgroup * | |
find path/to/dir -user fred -exec chown barney '{}' \; | |
# Or, if you wish to change also the group name of the file's ownership | |
# to match the new user name, find the new user's group name and plug it into this: | |
find path/to/dir -user fred -exec chown barney:barneygroup '{}' \; | |
# Caveats: | |
# 1. Not only will this change the files under the specified directory, | |
# but it will change the directory itself, if the ownership matches. | |
# 2. Changing files owned by root can hose your system. | |
# See: http://www.linuxforums.org/forum/linux-programming-scripting/132312-changing-all-files-owned-root-assigned-other-user.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment