≡ Menu

Shell: How to wrap text files to fit specified width

You can use command called fold. It wrap each input line (or lines from file) to fit in specified width. Width can be specified in columns or bytes size. By default Wrap input lines in each FILE from standard input (keyboard ), writing to standard output (screen).

fold -b size -w width file-name


  • -b : Use bytes rather than columns
  • -w : use WIDTH columns instead of 80 (which is default)


$ fold -w 40 file.txt
$ cat file.txt | grep something | fold -b 20

{ 2 comments… add one }

  • cym13 November 16, 2014, 1:58 pm

    I was annoyed by the fact that the pager was always there so I wrote a small script that takes place of the pager and does not use the real pager if the output fits on the screen


    To use it, change the REAL_PAGER variable in the script and do:

    alias yaourt=”PAGER=smartpage yaourt –color –pager”

    (smartpage is the name of my script)

    • aclarke August 7, 2015, 6:18 am


      Since you’re using ‘less’ in your script, the whole issue is already covered by the -F flag. I also find combining with -X (so it doesn’t clear screen before or after) is a nice touch.

      Personally, I use

      export LESS=”-M -e -F -i -Q -X -R”

      in my profile. Check out all those options, your mileage may vary.


Leave a Comment

   Tagged with: