Super User is a question and answer site for computer enthusiasts and power users. 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

Using bash scripting I am trying to access another's users documents and search for a word in a file, how would I do this?

share|improve this question

migrated from Mar 18 '13 at 4:47

This question came from our site for professional and enthusiast programmers.

Well, you need permissions to do so. – squiguy Mar 17 '13 at 17:02
Yes, grep ~otherUser/foo.txt "bar baz quirk" should do the trick. – H2CO3 Mar 17 '13 at 17:02
@H2CO3, no, first the pattern, then the file... – Gilles Quenot Mar 17 '13 at 17:08
@sputnick Yes, right, I always confuse that... – H2CO3 Mar 17 '13 at 17:11

try this command-:

grep 'word' file
share|improve this answer
I know how to search the file, but I don't know how I would be able to access a file on another user's account? – user2179792 Mar 17 '13 at 18:49
Basically I want to change directory but to another users account how do I do this? – user2179792 Mar 17 '13 at 19:08

Are you allowed to do this?

First, you need to know where their home directory is. Let's say their name is bob. You can use the short-hand syntax cd ~bob to set the working directory to their home.

You will need to have sufficient privileges to do so. That means there must be read and execute permissions on that folder for 'all users' or for their group (if you are also in that group). The same applies to sub-directories and files that you wish to access.

As long as you have permissions, this is just a matter of locating and grepping the file.

If you don't have permissions, then you need to login as someone who does. That is likely to be the root or bob. I gather you do not have access to either of those accounts. I also wonder about your intent. You could always ask 'Bob' if he can make the file accessible to you.

share|improve this answer

You must log in to answer this question.