Change the root directory of a command or a process, and its children.
1# create the "jail" directory
2J=$HOME/jail
3mkdir -p $J
4mkdir -p $J/{bin,lib64,lib}
5cd $J
6
7# copy the binaries and their libraries into the jail
8cp -v /bin/{bash,ls} $J/bin
9
10list="$(ldd /bin/bash | egrep -o '/lib.*\.[0-9]')"
11for i in $list; do cp -v "$i" "${J}${i}"; done
12
13list="$(ldd /bin/ls | egrep -o '/lib.*\.[0-9]')"
14for i in $list; do cp -v "$i" "${J}${i}"; done
15
16# enter the jail
17sudo chroot $J /bin/bash