3

I heavily use Bash to automate my work. Hence I often [re]write long chunks of code right in the prompt. Is there a way to make commands in any way affect only files from current directory? So in case I'll write something like rm -r /home/user/ tmp/pwd it won't get to all user's files while I'm in /home/user/tmp/pwd. AFAIU chroot is not an option here.

2
  • Yes, I have no idea why you posted this and I'm flagging the comment, @saleemrashid1. I hope you either understand why you shouldn't post such commands or get banned.
    – int_ua
    Aug 28, 2014 at 19:11
  • I clearly didn't explain myself well enough and was simply a modification (in possible bad taste) of the example.
    – user92200
    Aug 29, 2014 at 18:57

1 Answer 1

9

Create a user who has access to only this directory:

 useradd -d "`pwd`" -s /bin/bash -c "Temporary" temporary
 passwd temporary
 su temporary

Do whatever you want with this user. The current directory is his home directory, he can't destroy anything outside of it. Once you're done, exit the su with Ctrl-D, then do:

userdel temporary

You could make shortcut commands for this in your .bashrc file

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .