access to last touched or created file with arrow_up_key immediately after displaying the file list

lsa() { ls -lart; history -s "joe \"$(\ls -apt|grep -v /|head -1)\"" ; }
Display recursive file list (newest file displayed at the end) and be free to access last file in the list simply by pressing arrow_up_key i.e. open it with joe editor. BTW IMHO the list of files with newest files at the end is often more informative. Put this 'lsa' function somewhere in your .bashrc and issue . ~/.bashrc or source ~/.bashrc to have access to the 'lsa' command immediately. . (the function appends command "joe last_file_in_the_list" at the end of command history)

3
By: knoppix5
2016-07-07 21:27:55
ls

What Others Think

Hmm... This has promise. Finding the most recent file looks a bit clumsy, but I'm struggling to do any better. . Filtering out the directories isn't easy. I hoped that this would work: ls -I'*/' Ignore directory glob. Nope. ls -p | grep -v / will have to do . After you've filtered out the dirs, you can swap ls -tr | tail -1 for ls -t | head -1 which will be quicker. . Also, I suggest escaping the use of ls (to prevent unexpected behaviour). Lots of people have it aliased. lsa() { ls -lart; history -s "joe $(\ls -apt|grep -v /|head -1)" ; }
flatcap · 115 weeks and 1 day ago
Corrected. Thanx for the comment!
knoppix5 · 115 weeks and 1 day 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: