Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to configure Bash to print a newline or horizontal line after commands that provided more than N lines of output? For instance, after a simple cd I don't need a newline or horizontal line, but after a long cat a visual indication of the end of each command's output would be great when I am comparing the output of various commands.

share|improve this question
Maybe, I did not understand you well. If you want to add a newline, you can just use echo after each command. – Khaled Jan 4 '12 at 8:50
up vote 2 down vote accepted

Actually you could use a wrapper script like the one below:



eval $CMD | while read line; do
    echo "$line"
    if [ $((i % $N)) -eq 0 ]; then
        echo '================================================================';

Save it in your homedir, lets say as a ~/ Make alias for it in your .bashrc file:

alias wrap="~/ "

Now you can invoke command of your choice with 'wrap' prefix:

wrap cat veryLongFile

stdout from your command will be post-processed by the (I'm adding horizontal line after each 1o lines)

share|improve this answer
That is great! Is there any way to have all commands automatically wrapped? – dotancohen Feb 3 '12 at 16:17

This cannot be done in bash. The program's output to the terminal does not pass through shell (bash), so there is no way for bash to determine how many lines were printed.

Personally I just manually hit enter once or twice in case when I need visual separation. If you would like to have a newline on every command, the best way is to export PS1='\n'"$PS1"

share|improve this answer
Thank you kubanczyk. I actually do currently have a newline character there but seeing a new line after every command is a real waste of screen space. It drives me nuts like source code with the opening bracket on a line to itself. – dotancohen Jan 4 '12 at 13:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.