Useful Linux Commands

Commonly used Linux commands.

//change permissions recursively on Directories:
find . -type d -exec chmod XXX {} ;

//change permissions recursively on Files:
find . -type f -exec chmod XXX {} ;

//extract .tar.gz file:
tar -zxvf [file].tar.gz


//switch user:
su [username]

//change owner of a directory recursively
chown -Rv [username] [somedir]

//change group of a directory recursively
chgrp -Rv [usergroup] [somedir]

//add a user and add to group
useradd -G [group-name] [username]

//add a group
groupadd [groupname]

//add an existing user to group
usermod -a -G [group name] [username]

//SSH into another server
ssh -i [path/to/private/keyfile] [username]@[ip]

//Find files / folders greater than a size
du -h / | grep ^[0-9.]*G
du -h /usr/ | grep ^[1-9][0-9][0-9][0-9]*M