1

I would like to know difference between below 2 commands cat and fold commands? I just used fold command and it acts like cat command.

fold file1.txt
cat fold.txt (both are using to display the contents of the file)
4

3 回答 3

6

fold command wraps text when cat displays text without wrapping :

enter image description here

于 2013-10-24T10:56:57.210 回答
1

Check their manpages

man fold
fold - wrap each input line to fit in specified width

man cat
cat - concatenate files and print on the standard output

Appearantly with fold you can specify a width, whereas no such option exists in cat

于 2013-10-24T10:52:39.660 回答
0

fold - Filter for folding lines. This breaks the lines to have a maximum of x width column position (or bytes).

Example : fold -5 myfile.txt > newfile.txt

In the above command, this would fold the lines of myfile.txt to 5 character width and re-route the results to the file newfile.txt

cat - Allows you to read the contents of file

Example : cat file1.txt file2.txt > file3.txt

Reads file1.txt and file2.txt and combines those files to make file3.txt.

于 2013-10-24T10:55:16.427 回答