4 Unix / Linux Chroot Command Examples

chroot command is used to change the root directory to a given directory. Once you change it to this directory, you can execute a command by using this directory as the root directory.

1. Basic Usage

For example, if you make /home/john as chroot directory, and if you try to execute /bin/mycommand command, it will really use the mycommand from /home/john/bin directory.

# chroot /home/john /bin/mycommand

Note: Make sure the /home/john/bin/mycommand is statically linked. If not, you should find all other dependencies, and put it in the appropriate location under /home/john for the above to work properly.