Bash – “Chop lines” in `less` isn’t working

bashless

I'm doing:

less -S my_database_dump.sql

In order to see the files with the lines chopped (i.e. line wrapping.) But it's not working, the lines aren't being wrapped and I need to scroll horizontally to see the entire line. What can I do?

Best Answer

Try this:

fold -w $COLUMNS my_database_dump.sql | less

$COLUMNS is set to the terminal width by the shell. You can try other widths depending on your needs, of course. If you're running this in a script you may not have either $COLUMNS or $LINES defined - in that case you can use tput lines instead.

If you really want lines chopped (in this example, keep the first 80 chars) instead do this:

cut -c -80 my_database_dump.sql | less