When looking at the content of files, I'd like to automatically cat short files but less those that exceed the screen size. I could use something with wc -l, but is there a better way that maybe also considers the window size / current amount of lines available?
Tell me more
×
Unix & Linux Stack Exchange is a question and answer site for
users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
|
To give you the formula which involves the
There is a
But
|
|||
|
|
Maybe 'less -F file_to_read' is the option : it exits less if the window is sufficient to display all the file, and wait on the pager if it is not the case |
|||||||||||
|
git logwhich does this exact thing. You never know in advance what you're going to get (do you have to hitq?). – bitmask Jun 22 '12 at 19:47catto view files. Typically you should only usecatto send the contents of a file to stdout so it can be piped to another process. The reason to avoid usingcatfor viewing is that it sends the raw bytes to the terminal, which can cause unexpected terminal commands to be executed (e.g., some users have gotten stuck when a file happened to contain the right bytes to disable the terminal keyboard). You should usually use a pager likelessor an editor, which will format special characters for display so they aren't interpreted by the terminal. – Chris Page Jun 25 '12 at 6:25cat -vso it escapes special characters. – Chris Page Jun 25 '12 at 6:26cating possible? which might be a better solution – Tobias Kienzler Jun 25 '12 at 8:15cat -vout – Tobias Kienzler Jun 25 '12 at 8:16