Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 yesterday
    
I clearly didn't explain myself well enough and was simply a modification (in possible bad taste) of the example. –  saleemrashid1 1 hour ago

1 Answer 1

up vote 8 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

 
discard

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.