Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

Lets say the folder structure is like so:


How could I change to asdf1234 without specifying the user? For example:

cd /home/*/asdf1234

How can I use "not" in bash? For example, lets say I want to go to /home/cool but use not capability:

cd /home/!user*/asdf is this possible?

Are these bash tricks possible?

share|improve this question
Hm, are you in fact asking two questions? The first question works as you describe it (if permissions are OK), with the * wildcard. Not in bash may look like ! or ^; check out man bash and search for those. Last, please make an effort to write better titles to your future questions. – Emanuel Berg Oct 19 '12 at 21:17
I am asking two questions as they are related. – jersten Oct 19 '12 at 21:23
Your two questions may be related in terms of a problem you're trying to solve (in which case, ask about that problem), but if you think about it from a web search point of view for someone trying to answer one of those two, they're different questions. – EightBitTony Oct 19 '12 at 22:19
This is not SEO; as you can see extblob solves the problem. – jersten Oct 19 '12 at 23:21
up vote 6 down vote accepted

Turn on the extglob shell option and then cd /home/!(user*)/asdf

share|improve this answer
So far I'm liking it; how would it work for other directories? cd /home/!(user*)coo*/ – jersten Oct 19 '12 at 21:37

You can use the following command to change to asdf1234 directory without specifying the username:

cd $(find . -name asdf1234 -type d | sed 1q)

sed 1q ensures that only one directory name is passed as argument to cd.

share|improve this answer
Is there any particular reason for using sed 1q instead of head -n1? – poige Oct 20 '12 at 11:00
@poige: i like sed and awk :) no other reason. – pradeepchhetri Oct 20 '12 at 11:19

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.