I would find it very convenient to be able to use cd with a file argument.cd myDirectory/anyname.anyExtensionwould be equivalent tocd myDirectory/What would be the best alias or function to achieve this behavior ?EDIT:Sorry I didn't mention it in the 1st place: I use zsh
How to make `cd dir/filename` take me to dir/?
shell;cd command
In zsh, I often do:cd /path/to/somefile(:h)(h for head).If somefile is a symlink, you can also do:cd somefile(:A:h)To get to the directory where the target of the symlink may be found.The zsh equivalent of Chris' now bash-only solution would be:cd() {  [[ ! -e $argv[-1] ]] || [[ -d $argv[-1] ]] || argv[-1]=${argv[-1]%/*}  builtin cd $@}In zsh, you can also redefine what words Ctrl-W removes.In zsh, words in the context of the word-based motion/transpose/delete widgets  are sequences of alnums plus the characters in the $WORDCHARS variable which by default includes /.You could remove / from $WORDCHARS so that Ctrl-W only deletes one path component:WORDCHARS=${WORDCHARS/\/}Another useful extension is the select-word-style widget which you can use to interactively choose between different word styles.autoload select-word-stylezle -N select-word-stylebindkey '\ew' select-word-styleThen pressing Alt-W allows you to choose between different word styles.$ cd /blah/blih<Alt-W>Word styles (hit return for more detail):(b)ash (n)ormal (s)hell (w)hitespace (d)efault (q)uit(B), (N), (S), (W) as above with subword matching?