In bash
is there any way to expand a relative path into an absolute path, perhaps with tab completion?
I ask because sometimes I will search for a file, find it, then vim
it:
cd /etc
cd apache2
cd sites-available
vim 000-default
Then I will do some other things and change directories:
cd /tmp
ls
cd ~
ls
Then I'll find that I need to edit the same file again, but it is not possible to use history
, (or history search), because the file path is relative.
Current Workaround
If I know I'm going to be reusing a file a lot, after I find it I will grab the full path using something like realpath
:
$ realpath 000-default
/etc/apache2/sites-available/000-default
(copy and paste path into next command:)
$ vi /etc/apache2/sites-available/000-default
Caveats
This still requires copying and pasting. I believe there should be an easier way to get a file's full path into my history. What options do I have?
I believe that I have (accidentally) pressed some key combination before that expanded a relative path into a full path. I know in bash you can type:
cd /etc
ls bash_*(control+x *)
and get:
ls bash.bashrc bash_completion bash_completion.d
So is there a way I can expand a relative path into an absolute path, so that I can save operations on a file in my history with that file's full path?
pushd
andpopd
so it's easier to go back to a previous directory: http://www.gnu.org/software/bash/manual/bashref.html#The-Directory-Stack – glenn jackman Apr 16 '12 at 16:16cdargs
now. Thanks! ps: if nobody else has a better answer just post that and I will accept it. – cwd Apr 16 '12 at 17:37:sh
in vim to start a subshell, and thenexit
or CTRL+D to get back into vim. Or by doing CTRL+Z in vim to background (STOP) it and thenfg
to get it back. – phemmer Apr 16 '12 at 22:25