KandZ – Tuts

We like to help…!

Linux CLI 48 🐧 nl, fold and fmt commands

a - nl command
nl command is used to number lines of text lines
It is useful when referencing or citing specific lines in a document
common options: -b a → number all lines, default -b t → number non blank lines, -n ln|rz|rn → sets specified format -i # →overrides default incremetn
nl filename.txt →numbers lines
nl -n rz filename.txt → numbers lines and sets right alignment and fills with zeros
nl -n ln filename.txt → numbers lines and sets left alignment
nl -n rn filename.txt →numbers lines and sets right alignment
nl -i 2 filename.txt → numbers lines but increments by 2

b - fold command
fold command wraps input text into a specified width
It is useful for formatting long lines of text into readable paragraphs
common commands: -w# → specifies the length(n) of the line
-s → breaks lines on spaces
fold longtext.txt → wraps the text on default length
fold -w20 longtext.txt → specifies the line length to 20
fold -s longtext.txt → breaks the lines on space

c - fmt command
fmt command formats text paragraphs
It automatically adjusts the length of lines to fit within width margins
Default length is 75 characters
common options: -w → specifies the line length
-c → paragraphs have consistent line length by breaking them at a natural stopping point
fmt format.txt → formats the text at 75 characters long
fmt -w20 format.txt → specifies the line length to 20
fmt -w20 -c format.txt → specifies the length and breaks them at a natural stopping point

Leave a Reply