edit, view or execute last modified file with a single key-press

f() { ls -lart;e="ls -tarp|grep -v /|tail -9";j=${e/9/1};g=${e/9/9|nl -nln};h=$(eval $j);eval $g;read -p "e|x|v|1..9 $(eval $j)?" -n 1 -r;case $REPLY in e) joe $h;;v)cat $h;;x) eval $h;;[1-9]) s=$(eval $g|egrep ^$REPLY) && touch "${s:7}" && f;;esac ; }
Copy this function to command line, press 'Enter' 'f'' 'Enter' to execute (sentence on the left written only for newbies). Hint 'e|x|v|1..9' in front of displayed last modified file name means: "Press 'e' for edit,'x' for execute,'v' for view or a digit-key '1..9' to touch one file from the recent files list to be last modified" and suggested (hidden files are listed too, else remove 'a' from 'ls -tarp' statement if not intended). If you find this function useful you can then rename it if needed and append or include into your ~/.bashrc config script. With the command . ~/.bashrc the function then can be made immediately available. In the body of the function modifications can be made, i.e. replaced joe editor command or added new option into case statement, for example 'o) exo-open $h;;' command for opening file with default application - or something else (here could not be added since the function would exceed 255 chars). To cancel execution of function started is no need to press Ctrl-C - if the mind changed and want to leave simple Enter-press is enough. Once defined, this function can with typeset -f f command be displayed in easy readable form
Sample Output
knoppix5@kanta:~/SKRIPTE$ f
1       rdiff_backup_to_sda3.txt
2       arrange_windows_simple_from_xfce_panel.txt
3       .config.sh
4       arrange_windows.txt
5       read1.sh
6       read3.sh
7       lsb.sh
8       board9.pgn
9       read4.sh
e|x|v|1..9 read4.sh?

By: knoppix5
2019-09-26 11:58:37

What Others Think

are there any recent updates with welding el paso?
looneyhans · 48 weeks and 1 day ago
financial advisor salt lake city you are soo inspiring! thanks for this!
yeoyeo · 41 weeks and 6 days ago
love this soo much! jet
sammm · 38 weeks and 5 days ago
SO cool!!! pole buildings salem or
geebranz · 23 weeks and 6 days ago
The writing process involves many steps to create a clear and logical research paper. Knowing all aspects of the writing process is an important part of becoming a better writer. There are many tips that can be learned by a student to become a better academic Independent essay writers, including understanding the writing process to develop the writing skills necessary for academic and professional careers.
GladysThom · 11 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: