سؤال

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)
هل كانت مفيدة؟

المحلول

fold command wraps text when cat displays text without wrapping :

enter image description here

نصائح أخرى

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

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top