Commands using cat (514)


  • 2
    cat /etc/passwd | column -nts:
    kev · 2011-08-31 02:08:20 6
  • This command shows a sorted list of the IP addresses from which there have been authentication errors via SSH (possible script kiddies trying to gain access to your server), it eliminates duplicates so it's easier to read, but you can remove the "uniq" command at the end, or even do a "uniq -c" to have a count of how many times each IP address shows in the log (the path to the log may vary from system to system) Show Sample Output


    2
    cat /var/log/auth.log | grep -i "pam_unix(sshd:auth): authentication failure;" | cut -d' ' -f14,15 | cut -d= -f2 | sort | uniq
    JohnQUnknown · 2011-10-25 04:58:09 8
  • - excel date compatible with a separate hour field - added a fixed 1 for easier request counter aggregation - split URL in directory, filename, fileext, query - used with tomcat valve with response bytes replaced by elapsed time Show Sample Output


    2
    #(see sample) $ cat x | perl -pe 'BEGIN{ print "TIME;...\n"; } s!(\S+) - (\S+) - \[(\d\d)/(\S\S\S)/(\S+):(\d\d):(\d\d:\d\d) \S+\] "(\S+) (.*/)(\S+)(?:\.([^?]*)(\?\S*)?) HTTP/\S+" (\d+) (\S+)!$3-$4-$5 $6:$7;$6;$2;$1;$8;$13;1;$14;$11;$10;$9;$12;!' > x.csv
    hute37 · 2012-02-10 16:58:50 3
  • Let's take a rest. How about watch a horror? The Shining http://en.wikipedia.org/wiki/The_Shining_(film) Show Sample Output


    2
    yes "" | cat -n | awk '{print "S=`echo All work and no play makes Jack a dull boy. | cut -c",($1 - 1) % 43 + 1 "`;echo -n \"$S\";seq 500000 > /dev/null"}'| bash
    nati · 2012-04-08 07:53:43 26
  • merge pdf from pg_0001.pdf until pg_0009.pdf into MyFile.pdf


    2
    pdftk pg_000{1..9}.pdf cat output MyFile.pdf
    eastwind · 2012-08-27 08:57:00 4
  • Alternative for machines without ssh-copy-id


    2
    cat ~/.ssh/id_rsa.pub | ssh user@host 'cat >> ~/.ssh/authorized_keys'
    eneko · 2012-12-08 17:00:47 15
  • This example will close the pipe after transferring 100MB at a speed of 3MB per second.


    2
    cat /dev/zero | pv -L 3m -Ss 100m > /dev/null
    bugmenot · 2012-12-15 10:17:52 5
  • PRoot is a user-space implementation of chroot, mount --bind, and binfmt_misc. This means that users don't need any privileges or setup to do things like using an arbitrary directory as the new root filesystem, making files accessible somewhere else in the filesystem hierarchy, or executing programs built for another CPU architecture transparently through QEMU user-mode. Also, developers can use PRoot as a generic Linux process instrumentation engine thanks to its extension mechanism, see CARE for an example. Technically PRoot relies on ptrace, an unprivileged system-call available in every Linux kernel. https://github.com/cedric-vincent/PRoot Show Sample Output


    2
    proot -r /media/user/ubuntu12.10/ cat /etc/motd
    totti · 2014-01-21 07:50:22 15
  • Feel free to put this in your ~/.profile: random(){ cat /dev/urandom | env LC_CTYPE=C tr -dc $1 | head -c $2; echo; } Then use it to generate passwords: random [:alnum:] 16 Or DNA sequences: random ACGT 256


    2
    cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16; echo
    yakovlev · 2014-02-05 15:04:07 6
  • Merge Multiple PDFs In Alphabetical Order


    2
    pdftk *.pdf cat output merged.pdf
    o0110o · 2014-03-02 01:53:37 7

  • 2
    cat /var/log/mosquitto/mosquitto.log | awk -F : '{"date -d @"$1 |& getline D; print D, $0}'
    ifebi · 2019-06-09 07:35:25 39
  • With this command you can convert a tab separate file (TSV) into a JSON file with jq. For example, this input.tsv i-0b9adca882e5e6326 172.16.0.188 i-088dd69e5c3624888 172.16.0.102 i-0e70eac180537d4aa 172.16.0.85 will produce the showed output. Show Sample Output


    2
    cat input.tsv | jq --raw-input --slurp 'split("\n") | map(split("\t")) | .[0:-1] | map( { "id": .[0], "ip": .[1] } )'
    nordri · 2019-10-01 10:52:35 220
  • Using the csv tool `miller` you can transform a csv file into a json array of objects, where the properties are the values of the csv header line and the values are the values of the subsequent lines. Show Sample Output


    2
    mlr --c2j --jlistwrap cat file.csv
    pepa65 · 2019-12-06 07:16:58 99
  • Useful for containers and environments where you need to know if a port is currently in listen mode but you have not easy way or privileges to install net-tools like netstat or ss. "0A" is the code for listen state. The IP hex is reverse order and all in hex format. Show Sample Output


    2
    cat /proc/net/tcp | grep " 0A " | sed 's/^[^:]*: \(..\)\(..\)\(..\)\(..\):\(....\).*/echo $((0x\4)).$((0x\3)).$((0x\2)).$((0x\1)):$((0x\5))/g' | bash
    glaudiston · 2020-05-23 12:36:21 151

  • 1
    cat /proc/cpuinfo
    kumara · 2009-02-05 12:46:50 36
  • Takes input from the connected terminal and dumps it to the specified file. Stop writing and close file with control + D or the end of line character. Useful for copying+pasting large blobs of text over SSH to a new machine. Show Sample Output


    1
    cat /dev/tty > FILE
    Jo · 2009-02-25 01:43:47 11

  • 1
    $ cat /etc/*-release
    unixmonkey1855 · 2009-02-26 21:04:43 8
  • Displays the duplicated lines in a file and their occuring frequency.


    1
    cat file.txt | sort | uniq -dc
    Vadi · 2009-03-21 18:15:14 7
  • xml with verbose commenting can be difficult to read. remove comments from xml.


    1
    cat <filename> | perl -e '$/ = ""; $_ = <>; s/<!--.*?-->//gs; print;'
    unixx · 2009-04-15 20:29:11 36
  • replace "/usr/src/linux/kernel/signal.c" with any file you want and listen to its output ! :P you can also replace "cat" with "echo" or anything you can come up with have fun :-}


    1
    while true; do cat /usr/src/linux/kernel/signal.c > /dev/dsp; done
    JesusSuperstar · 2009-05-16 14:44:57 6
  • The variable WIRELESSINTERFACE indicates your wireless interface


    1
    while [ i != 0 ]; do sleep 1 | dialog --clear --gauge "Quality: " 0 0 $(cat /proc/net/wireless | grep $WIRELESSINTERFACE | awk '{print $3}' | tr -d "."); done
    ncaio · 2009-05-31 16:09:23 12
  • Ever compress a file for the web by replacing all newline characters with nothing so it makes one nice big blob? It is a great idea, however what about when you want to edit that file? ...Serious pain in the butt. I ran into this today in that my only copy of a CSS file was "compressed" with no newlines. I whipped this up and it converted back into nice human readable CSS :-) It could be nicer, but it does the job.


    1
    cat somefile.css | awk '{gsub(/{|}|;/,"&\n"); print}' >> uncompressed.css
    lrvick · 2009-06-02 15:51:51 37
  • command | my_irc Pipe whatever you want to this function, it will, if everything goes well, be redirected to a channel or a user on an IRC server. Please note that : - I am not responsible of flood excesses you might provoke. - that function does not reply to PINGs from the server. That's the reason why I first write in a temporary file. Indeed, I don't want to wait for inputs while being connected to the server. However, according to the configuration of the server and the length of your file, you may timeout before finishing. - Concerning the server, the variable content must be on the form "irc.server.org 6667" (or any other port). If you want to make some tests, you can also create a fake IRC server on "localhost 55555" by using netcat -l -p 55555 - Concerning the target, you can choose a channel (beginning with a '#' like "#chan") or a user (like "user") - The other variables have obvious names. Show Sample Output


    1
    function my_irc { tmp=`mktemp`; cat > $tmp; { echo -e "USER $username x x :$ircname\nNICK $nick\nJOIN $target"; while read line; do echo -e "PRIVMSG $target :$line"; done < $tmp; } | nc $server > /dev/null ; rm $tmp; }
    Josay · 2009-06-11 22:14:48 7
  • This just combines multiple mp3's into one mp3 file. Basically it is a easy join for mp3's


    1
    cat 1.mp3 2.mp3 > combined.mp3
    scottix · 2009-07-27 18:39:44 9
  • use find to grep all .c files from the target directory, cat them into one stream, then piped to wc to count the lines Show Sample Output


    1
    find . -type f -name "*.c" -exec cat {} \; | wc -l
    foremire · 2009-07-30 10:06:51 14
  • ‹ First  < 5 6 7 8 9 >  Last ›

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands


Check These Out

Multiple variable assignments from command output in BASH
No command substitution but subshell redirection

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Find files that were modified by a given command
Traces the system calls of a program. See http://linuxhelp.blogspot.com/2006/05/strace-very-powerful-troubleshooting.html for more information.

rename a file to its md5sum

Remove all mail in Postfix mail queue.

Perform a branching conditional
This will perform one of two blocks of code, depending on the condition of the first. Essentially is a bash terniary operator. To tell if a machine is up: $ ping -c1 machine { echo succes;} || { echo failed; } Because of the bash { } block operators, you can have multiple commands $ ping -c1 machine && { echo success;log-timestamp.sh }|| { echo failed; email-admin.sh; } Tips: Remember, the { } operators are treated by bash as a reserved word: as such, they need a space on either side. If you have a command that can fail at the end of the true block, consider ending said block with 'false' to prevent accidental execution

Find usb device
I often use it to find recently added ou removed device, or using find in /dev, or anything similar. Just run the command, plug the device, and wait to see him and only him

Read PDFs in the command line
Turns a PDF into HTML (without images) and prints it to the standard out which is picked up and interpreted by w3m.

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

Convert all WMF images to SVG recursively ignoring file extension case
This assumes you have the package installed necessary for converting WMF files. On my Ubuntu box, this is libwmf-bin. I used this command, as libwmf is not on my wife's iMac, so I archived the directories containing the WMF files from OS X, ran them on my Ubuntu box, archived the resulting SVGs, and sent them back to her. Quick, simple and to the point. Searches directories recursively looking for extensions ignoring case. This is much more readable and clean than -exec for find. The while loop also gives further flexibility on complex logic. Also, although there is 'wmf2svg --auto', it expects lowercase extensions, and not uppercase. Because I want to ignore case, I need to use the -o option instead. Works in ZSH and BASH. Haven't tested in other shells.


Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: