I feel like this should be simple, but can't figure it out: What's the bash command(s) to look through a folder and open the largest file using VIM?
+13
A:
vim "`ls -S | head -1`"
Sort by size, pick just the first. The double quotes make this work if the file name contains spaces or other unusual characters.
FYI, do not use xargs with vim. For most commands the following would also work, but with vim it complains that "input does not come from a terminal" and it can screw up your xterm. (On mine it stopped echoing my input and I had to blindly type reset
to fix it.)
Bad
ls -S | head -1 | xargs vim
John Kugelman
2009-10-28 13:00:52
Using Bash and GNU xargs, `xargs -a<(ls -S | head -n 1) -d'\n' vim` works. Both what you have and this will fail if the filename has an embedded newline, though.
ephemient
2009-10-28 15:46:14
Having an newline character embedded in a filename sounds like it would cause all kinds of problems. Fortunately, none of my files do. Thanks for the second option
David Oneill
2009-10-28 17:06:56