Skip to content

Instantly share code, notes, and snippets.

@daffydowden
Created March 1, 2012 10:40
Show Gist options
  • Save daffydowden/1948992 to your computer and use it in GitHub Desktop.
Save daffydowden/1948992 to your computer and use it in GitHub Desktop.
Linux commands that I always forget...
# List all users
cat /etc/passwd | cut -d: -f1
# List all non-system users
awk -F: '{if ($3>=500 && $3<=1000) print $1}' /etc/passwd
# List all groups
cat /etc/group | cut -d: -f1
# Add an existing user to a group - http://www.cyberciti.biz/faq/howto-linux-add-user-to-group/
# usermod -a -G ftp tony
# Chmod usage - http://en.wikipedia.org/wiki/Chmod
chmod [options] mode[,mode] file1 [file2 ...]
# Modes
u user the owner of the file
g group users who are members of the file's group
o others users who are not the owner of the file or members of the group
a all all three of the above, is the same as ugo
Operator Description
+ adds the specified modes to the specified classes
- removes the specified modes from the specified classes
= the modes specified are to be made the exact modes for the specified classes
Mode Name Description
r read read a file or list a directory's contents
w write write to a file or directory
x execute execute a file or recurse a directory tree
X special execute which is not a permission in itself but rather can be used instead of x. It applies execute permissions to directories regardless of their current permissions and applies execute permissions to a file which already has at least 1 execute permission bit already set (either user, group or other). It is only really useful when used with '+' and usually in combination with the -R option for giving group or other access to a big directory tree without setting execute permission on normal files (such as text files), which would normally happen if you just used "chmod -R a+rx .", whereas with 'X' you can do "chmod -R a+rX ." instead
s setuid/gid details in Special modes section
t sticky details in Special modes section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment