Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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 '14 at 19:11
I clearly didn't explain myself well enough and was simply a modification (in possible bad taste) of the example. – spudowiar Aug 29 '14 at 18:57
up vote 9 down vote accepted

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.