fold is really nifty command line utility to make a text file word wrap. This is useful for large number of text files processing. There is no need to write a perl / python code or use a word processor.
fold command syntax
fold -sw {COUNT} {input.txt} > {output.txt}
Wrap input lines in each input.txt, writing to standard output.txt.
Where,
- -s: break at spaces
- -w: {COUNT} use COUN} as WIDTH columns instead of default 80.
For example, following command will wrap input.txt at 60 width columns:
$ fold -sw 60 input.txt > output.txt
A large number of files can be processed using for shell loop:
for i in *.txt do fold -sw 65 $i > $i.output done
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 2 comments… read them below or add one }
Ah, this is great for grepping through a corpus of longlines-text,
gzcat corpus.txt.gz | fold | grep fooI wish fold had an option no to fold lines unless they contain whitespace that provide a natural folding point.
The -s option helps some, but fold will still spli a long URL, for example, when I might not want that.
Perhaps a perl-based fold script is in order….