Skip to content

cat MacOS command

The cat command in MacOS is a convenient utility for displaying the contents of files, concatenating them, or creating new ones. It is versatile and easy to use, making it a essential tool for working with text files in the terminal. By simply typing ‘cat’ followed by the file name(s), you can quickly view their contents. Additionally, you can combine multiple files into a single output, which can be redirected to a new file if needed. Its simplicity and effectiveness make it a valuable tool for any MacOS user.

Terminal window
cat [option] [file]
OptionDescription
-bNumber non-blank output lines
-eDisplay non-printing characters
-nNumber all output lines
-sSqueeze multiple blank lines
-TDisplay tabs as ^I
ParameterDescription
fileThe file to display

Concatenate two files and display the output

Section titled “Concatenate two files and display the output”
Terminal window
cat file1.txt file2.txt

Display the contents of a file with line numbers

Section titled “Display the contents of a file with line numbers”
Terminal window
cat -n file.txt

Output non-printing characters in a file using cat -vet

Section titled “Output non-printing characters in a file using cat -vet”
Terminal window
cat -vet file.txt

Display the first 10 lines of a file using cat and head

Section titled “Display the first 10 lines of a file using cat and head”
Terminal window
cat file.txt | head

Append the contents of one file to another

Section titled “Append the contents of one file to another”
Terminal window
cat file1.txt >> file2.txt
Terminal window
cat file.txt > newfile.txt

To use the cat command in MacOS, execute the following command:

Terminal window
cat filename.txt

How can I display line numbers with cat in MacOS?

Section titled “How can I display line numbers with cat in MacOS?”

To display line numbers with the cat command in MacOS, use the -n option like this:

Terminal window
cat -n filename.txt

How can I combine multiple files and display the output with cat in MacOS?

Section titled “How can I combine multiple files and display the output with cat in MacOS?”

To combine multiple files and display the output with the cat command in MacOS, simply list the files you want to combine like this:

Terminal window
cat file1.txt file2.txt

How do I create a new file using cat in MacOS?

Section titled “How do I create a new file using cat in MacOS?”

To create a new file using the cat command in MacOS, use the following command and then type the content you want in the new file:

Terminal window
cat > newfile.txt

How can I display non-printing characters with cat in MacOS?

Section titled “How can I display non-printing characters with cat in MacOS?”

To display non-printing characters with the cat command in MacOS, use the -v option like this:

Terminal window
cat -v filename.txt

How do I append the content of a file to another file using cat in MacOS?

Section titled “How do I append the content of a file to another file using cat in MacOS?”

To append the content of a file to another file using the cat command in MacOS, use the double greater than symbol (>>) like this:

Terminal window
cat file1.txt >> file2.txt

How can I view the beginning of a file with cat in MacOS?

Section titled “How can I view the beginning of a file with cat in MacOS?”

To view the beginning of a file with the cat command in MacOS, use the head command in combination with cat like this:

Terminal window
cat filename.txt | head

How do I display the contents of a file with line breaks in a single line using cat in MacOS?

Section titled “How do I display the contents of a file with line breaks in a single line using cat in MacOS?”

To display the contents of a file with line breaks in a single line using the cat command in MacOS, use the -s option like this:

Terminal window
cat -s filename.txt
  • Display the contents of a file on the terminal
  • Concatenate and display multiple files
  • Create new files
  • Append content to existing files
  • Redirect output to a new file
  • Create file backups
  • View and create text files
  • Print file contents with line numbers