Friday, April 29, 2016

Bash: How to change recursively owner and group of files and dirs

Sometimes comes in hand to change recursively the owner and group for files in a directory. How to do this in bash?

With this command:

find /starting/path -user "original_owner"  -exec chown someuser:somegroup {} +
You can omit ":somegroup" if you don't want to change the group of the files/folder
For example to change from root to foo of foogroup in the folder /var/lol  use the command:

find /var/lol -user "root"  -exec chown foo:foogroup {} +
NOTE: You must be root to change the ownership of a root-owned file! 

Thursday, April 14, 2016

SSH and login prompt

If you log via SSH and you get a prompt showing only the bash version it means that .bashrc wasn't sourced. SSH sources .bash_profile not .bashrc.
To solve this problem,  create/update .bash_profile with the   following content :

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
 This is the way to go for docker too :)