10

I want a quick way to open the last modified file in the directory, perhaps in a form of alias.

Currently, I do ls -ltr. Then copy-and-paste the filename

Assume that I am using tcsh

vehomzzz
  • 42,832
  • 72
  • 186
  • 216

2 Answers2

21
vi `ls -tr | tail -1`
GJ.
  • 4,518
  • 1
  • 19
  • 26
  • 1
    May want to add --groups-directories-first to the ls, that way files are always at the end. – Randy Morris Jan 14 '10 at 20:22
  • i saved file using :x firstVimFile.txt using Vim for Windows and it quit dont know where file got saved and how to open it back..:/ –  Jan 01 '13 at 06:08
2

Creating an alias for the mentioned answer will avoid typing the command every time.

Add below entry in .tcshrc file and reload.

alias v='vi `ls -tr | tail -1`'

To avoid going to log folder and executing the command, create below alias and reload.

alias -- -='cd -'
alias v='cd /path/to/log/folder; vi `ls -tr | tail -1` ; -'
Subhash
  • 568
  • 1
  • 5
  • 21