Linux Commands - fold (wrap text)

by
Jeremy Canfield |
Updated: July 14 2020
| Linux Commands articles
Let's say foo.txt contains a very long string, like this.
asdfakjdslkfjkllk343lk434l3klkjvsdfsiwqepoqwpisdfsddslkjpizndf3498sdf
The fold command with the -w option can be used to wrap the content of foo.txt. In this example, the string will be wrapped at every 10th character.
fold -w 10 foo.txt
asdfakjdsl
kfjkllk343
lk434l3klk
jvsdfsiwqe
poqwpisdfs
ddslkjpizn
df3498sdf
Note that fold will not actual update the file in question. Redirection can be used to create a new, folded file.
fold -w 10 foo.txt > bar.txt
Did you find this article helpful?
If so, consider buying me a coffee over at