tag:blogger.com,1999:blog-8032022811235182759.post3818946029522833498..comments2024-03-23T08:25:23.254-07:00Comments on Linux Commando: How to find a file and cd to its dirname using command substitutionPeter Leunghttp://www.blogger.com/profile/05589860210899238688noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8032022811235182759.post-67717015662562581102010-03-22T13:00:46.169-07:002010-03-22T13:00:46.169-07:00Can you solve this using dirname .This does not in...Can you solve this using dirname .This does not involve the find command<br />http://stackoverflow.com/questions/2486065/display-contents-of-a-file-in-the-parent-directorySharjeel Sayedhttps://www.blogger.com/profile/15594195110791609902noreply@blogger.comtag:blogger.com,1999:blog-8032022811235182759.post-1979328617160575302008-06-08T06:14:00.000-07:002008-06-08T06:14:00.000-07:00Another possibility is:cd $(find / -name unknownfi...Another possibility is:<BR/><BR/>cd $(find / -name unknownfile.txt 2>/dev/null | head -n 1|xargs dirname)<BR/><BR/><BR/>This spawns one shell less, but performance isn't an issue here. So it's mostly a matter of style.<BR/><BR/>Also be aware that if the find command doesn't return anything, you go back to your home dir (cd without arguments). That may or may not be what you want.Anonymousnoreply@blogger.com