How to make bash not to wrap output

bashcommand line

Whenever some command generates long lines as output ( for example, when ls -l a folder which contains files with long names ), the long lines are wrapped to next line, thus messing up the column structure.

Is there any way of avoiding this ? Something akin to the 'nowrap' vim option ?


update

I noticed an issue with the accepted answer:
if I make an alias like: alias ll="tput rmam; ls -l; tput smam"
and then try to grep it's output: ll | grep foo
it will still print all files, like without the grep.

The solution I found is to put brackets around the whole alias:
alias ll="(tput rmam; ls -l; tput smam)"

Best Answer

Note that this has nothing to do with bash (once you've launched the command, bash just waits for it to finish) and everything to do with the terminal.

Most terminal emulators wrap at the right margin by default. But this can be turned off by using the appropriate control sequence, if the terminal emulator supports it; then long lines are simply truncated:

printf '\033[?7l'
ls -l /a/folder/that/contains/files/with/long/names
printf '\033[?7h'
Related Question