Using wildcards to match a directory in bash
8,852
Turn on the extglob
shell option and then cd /home/!(user*)/asdf
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Author by
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
Lets say the folder structure is like so:
/home/ --user1/asdf --user2/asdf1234 --user3/asdf325234 --cool/asdf
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?
-
Emanuel Berg over 11 yearsHm, 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 outman bash
and search for those. Last, please make an effort to write better titles to your future questions.
-
-
poige over 11 yearsIs there any particular reason for using
sed 1q
instead ofhead -n1
? -
pradeepchhetri over 11 years@poige: i like sed and awk :) no other reason.