The cat command

concatenate files and print on the standard output 33 examples from the lessons of the IVski Linux Playground — try them in the terminal next to them.

Options in the examples

-n, --number
number all output lines

Examples

cat README.txt
cat documents/hello.txt
cat file1.txt file2.txt
cat > newfile.txt
cat >> existing.txt
cat -n myfile.txt
cat file.txt | wc -w

Count words via pipe

cat /etc/sudoers

Sudo configuration (use visudo to edit!)

cat /etc/passwd | grep '/bin/bash'

Find bash users

cat /etc/passwd | cut -d: -f1 | sort | head -10
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn
cat file.txt | tr -s ' '

Squeeze multiple spaces

cat /etc/passwd
cat /etc/group
cat /etc/hosts
cat /proc/meminfo

Detailed memory info

cat ~/.bash_history
cat urls.txt | xargs -P 4 wget

Download 4 at a time

cat names.txt | xargs -I{} echo "Hello, {}!"
cat /etc/apt/sources.list

Where packages come from

cat /etc/nginx/sites-available/default
cat /etc/nginx/nginx.conf
cat /etc/passwd | grep -E '/bin/(bash|sh)$'

Users with shell access

cat /etc/passwd | grep ana
cat /home/ana/.ssh/id_ed25519.pub
cat /etc/resolv.conf

Which DNS server does the system ask?

cat ~/RESTORE-NOTES.txt

What was done during the restore?

cat ~/.ssh/config

How is web01 configured?

cat ~/handover.txt

What did Marko change?

cat -n /etc/nginx/conf.d/shop.conf

Look at the file with line numbers

cat ~/ticket-4521.txt

What does the user see?

cat ~/note-from-ana.txt

What happened?

cat /etc/nginx/sites-available/shop

Where does nginx send /api/?

Lessons that use cat

Related commands