- Mostly While setting up web server, I was run multiple commands as root user.
- After that I realize I’ve to change ownership of web root :(
- By using following command we can directly create directory, copy files with given username instead of root user.
Syntax
$ sudo -H -u <USERNAME> <COMMAND>
Examples
$ sudo -H -u mitesh mkdir ~mitesh/bin
$ sudo ls -ld ~mitesh/bin
drwxr-xr-x 2 mitesh mitesh 4096 Jul 8 20:32 /home/mitesh/bin
Post Navigation
Useful Bash Commands How to Create Directory and Change Permission With Single Command