Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
cat (concatenate) writes the content of one or more files to standard output. With one file you read it; with several files you join them; with a redirect you create a new file.
It is perfect for short files. For long files, use less (scrolling) or head/tail (parts).
tac does the same, but starts with the last line (useful for logs: newest first).
Zo schrijf je het
cat [OPTION]... [FILE]...
tac [OPTION]... [FILE]...Opties 15
Meest gebruikt
tac
Niets past bij dit filter.
Voorbeelden 12
$ als gewone gebruiker# als root (of met sudo)
1Show a short file
cat /etc/hostname server1.example.comThe fastest way to read a small file.
2Show line numbers
cat -n /etc/fstabEasy to talk about "line 7".
3Find hidden characters (tabs, Windows line ends)
cat -A deploy.sh | head #!/bin/bash^M$^M$means Windows line ends: Bash will fail.^Iwould show tabs (bad in YAML).4Join several files into one
cat part1.csv part2.csv part3.csv > all.csvThe files are added one after the other.
5Create a file with several lines (here-document)
cat > /tmp/test.conf <<'EOF' port=8080 log=/var/log/app.log EOFEverything until the line
EOFgoes into the file.6Add lines to a root-owned file
sudo tee -aappends as root.7Show the newest log lines first
tac /var/log/dnf.log | head -20The last 20 events, newest at the top.
8Show the OS version
cat /etc/os-releaseNAME, VERSION_ID and ID of the distribution.
9Squeeze empty lines while reading
cat -s notes.txtSeveral empty lines become one.
10Read kernel information
/proc files are created by the kernel when you read them.
11Show a file only if it exists
[ -f /etc/motd ] && cat /etc/motdNo error message in a script when the file is missing.
12Copy a disk image to a USB stick (as a simple dd)
cat rhel-10.iso > /dev/sdXWorks like dd for this job. Check the device name three times: it overwrites the whole disk.
Niets past bij dit filter.
Let op
cat bigfilefloods the screen; useless.cat file > fileempties the file before reading it. Never read and write the same file in one command.- "Useless use of cat":
cat file | grep xworks, butgrep x fileis simpler.
Tips om te onthouden
- cat = show/join, tac = backwards,
cat -A= invisible characters,cat > file <<'EOF'= new file.