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?

  • 2
    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. Oct 19, 2012 at 21:17
  • 2
    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. Oct 19, 2012 at 22:19

2 Answers 2


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

  • 1
    See also: this answer which describes extglob in more detail and the accompanying question which shows how to set the shell option.
    – Jon
    Sep 6, 2018 at 14:14

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.

  • Is there any particular reason for using sed 1q instead of head -n1?
    – poige
    Oct 20, 2012 at 11:00
  • @poige: i like sed and awk :) no other reason. Oct 20, 2012 at 11:19

You must log in to answer this question.