Maybe there is a tool that does that? Maybe I’m doing this all wrong and there is a different way I should browse?
You may want to learn about the shell’s “history expantion” functions. as an example:
~$ ls ~/Documents/taxes/tax_year_2012/2012-12-01.txt /home/tom/Documents/taxes/tax_year_2012/2012-12-01.txt ~$ cd !!$:h cd ~/Documents/taxes/tax_year_2012 ~/Documents/tax_2012$ pwd /home/tom/Documents/taxes/tax_year_2012Here the string “
!!$:h” is basically the last command’s [!!] last argument [], stripped of its last path component [:h].There’s already some great answers in the thread, so I won’t add to those.
Some shortcuts are shell-specific. For example,
!!,!:$, and^old^neware inbash, but not infish.Some things, like
Alt-.andCtrl-a, are implemented byreadline, which can be used elsewhere, as well, for example in the python interpeter.Depending on your context, it may be better to invest time learning methods implemented by
readline. While not necessarily universal, they are more versatile.There were heaps of functions I was using not realising they were from readline. For example,
Ctrl-rfor reverse interactive search,Ctrl-a/efor start/beginning if line,Ctrl-wfor deleting a word.Looks like no one has mentioned this yet. So I’ll be the FZF champion in this thread.
The ZSH plugin for FZF gives you a few commands that use the fuzzy search to find files by name, keyword in content etc.
It could be very easy to add something like that for your use case where you can use <your custom command> <file path> and you pick the file name from the output and it automatically cd’s into the selected file’s directory.
Bookmarking this whole thread
You mean something like this?
ls /your/long/path/name
cd !$In some shells (e.g. fish), “running” a directory changes to it so you can save keystrokes and just delete the "ls ".
Holy fucking shit. I’ve dabbled in Linux for so long to not know. Thank you!
To add,
!$ gets replaced with the last word from the previous command line
!! Repeats the most recent command
!-N Repeats the Nth previous command
!string Repeats the most recent command that began with ‘string’
… How have I used Linux for two decades and not run into this once. Amazing stuff
I’ve never come across this before, and I am completely unsurprised it exists.
If
!$isn’t pronounced “ba-ching!” I’m quitting LinuxBetter than “bang-ching” which sounds racist to me. lol
Great, now omarchy is going to adopt it
the (ng) is silent when used in compound punctuation in ba(ng)
okay, but now THAT sounds racist for whole OTHER reasons… ;-)
it probably is, that professor who taught me it was belgian
!!:nwhere n is the nth word after the command in your last linecp file1 file2 nano !!:2Here nano opens file2.
Love it
I’m loving this
!!is the goat when you needed to run the last command usingsudoHot damn, and here’s me thinking thefuck was the way to do this.
I just learned more about Linux than I did from my whole IT degree.
You learned more about shells than you knew. This stuff works on BSD and some UNIX systems too, you know
Most POSIX-compliant systems?
And there goes my daily new knowledge snippet! Thanks!
I like the way you think! Too bad a I replied to a seaming empty post some 26 min after you. I always disliked this about Reddit. Seeing someone rewording the top reply for karma.
I think, if your using bash
alt + .
Does the same thing as typing
!$
ls /super/long/path/to/dir
cd alt + .
I believe if you hit it again, it cycles through all previous last words
so you have better answers but still going to do mine. up arrow and change ls to cd.







