Hacker News new | ask | show | jobs
by unhammer 843 days ago
I have an old note named the same as this blog post:

    cat /dev/sdb > backup.img # make a disk image

    cat /dev/sdb > /dev/sdc   # clone disk

    cat ~/Downloads/*         # play Russian roulette with your terminal

    cat > file                # minimalistic text editor, ^D to exit saving, ^C to exit erasing the file

    cat << wq > file          # nearly complete emulation of ed

    grep -r bongo . | cat     # shorter than typing --color=never

    cat -v file               # cause 20 points of damage to wizards of bell labs

    cat file > file           # empty a file without removing the file

    cat meow meow > meows     # duplicate file contents
1 comments

Oh and another one I use all the time is as an "identity transform" when selecting between filters, e.g.

    dostuff () { 
        if [[ $1 = clean ]]; then 
            grep -v dirt
        else 
            cat
        fi | do_other_stuff
    }

See also https://www.in-ulm.de/~mascheck/various/uuoc/ (via https://lobste.rs/s/rtvp2u/useful_uses_cat#c_0xpqkr )