commandlinefu.com is the place to record those command-line gems that you return to again and again.
You can sign-in using OpenID credentials, or register a traditional username and password.
Subscribe to the feed for:
Back up /etc directory with a name based on the current date and the hostname of the machine, then chown the file for the current user for use.
Using $_ in the chmod command saved a good bit of typing ? obviously the $_ will contain the path to the file we?re talking about, as it was the last argument to the previous command.
be careful where you execute this from
do a 'sudo ls' beforehand to prime sudo to not ask for your password
requires: a directory with borked permissions and a backup directory that has the correct permissions.
works with chown or chmod
I often use it at my work, on an ovh server with root ssh access and often have to change mod after having finished an operation.
This command, replace the user, group and mod by the one required by apache to work.
Set Permission to user and group
This will change the ownership of /../../somedirectory as well as all its subdirectories so they will be be owned by user2 - typically used when a directory is owned by root:root
In the example, uid 0 is root. foo:foo are the user:group you want to make owner and group. '.' is the "current directory and below." -print0 and -0 indicate that filenames and directories "are terminated by a null character instead of by whitespace."
Finds all files in /home owned by UID 1056 and changes to 2056.
Changing files ownership in a directory recursivley from a user to another
useful if you want to start running a svc as a non-privileged user instead of root.