quarrel4you@piefed.socialtoAsk Lemmy@lemmy.world•Linux question: I like to browse using ls. Than when I find what I'm looking for, I would like to directly move there with cd without having to retype the path. Is there an elegant solution for that?English
27·
4 days agoYou 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_2012
Here the string “!!$:h” is basically the last command’s [ !! ] last argument [], stripped of its last path component [:h].
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.