🖥️cat

➡️This is a command-line reference manual for commands and command combinations that you don’t use often enough to remember it. This cheatsheet explains the cat command with important options and switches using examples.

▁ ▂ ▃ ▄ ꧁ 🔴☠ COMMANDLINE-KUNGFU WITH CHEATSHEETS ☠🔴꧂▅ ▃ ▂ ▁

#                 ██████╗ █████╗ ████████╗
#                ██╔════╝██╔══██╗╚══██╔══╝
#                ██║     ███████║   ██║   
#                ██║     ██╔══██║   ██║   
#                ╚██████╗██║  ██║   ██║   
#                 ╚═════╝╚═╝  ╚═╝   ╚═╝   
                                         
                                         
                                     
#==============================#
# CMD CAT
#==============================##==============================#

cat
    Catenate
    "Catenate" is an obscure word meaning "to connect in a series", which is what the cat command does to one or more files. This is not to be confused with C/A/T, the Computer Aided Typesetter. For more, see Combine several text files into a single file in Unix

cat -E
# Show line endings in a file 

cat -T
# Show tabs in a file

cat -n or nl
# Display a file with line numbers

cat -v
# Output a file, displaying non-printing characters: 

cat </dev/tcp/time.nist.gov/13
# Fetch the current time in bash using this special device path hostname/port. 

cat <(printf "HTTP/1.1 200 OK\nContent-type: text/html\n\n") - |nc -l 80
# Give your visitors truly live updates. Type a message + Ctrl-D

cat /bin/sh > it
# Put the sh back into it.

cat split-xaa split-xab split-xac > rejoinedlargefile
# Join the splits back together.

cat longdomainlist.txt | rev | sort | rev
# group subdomains by domain. Good use of rev.

cat access_log-*|awk '{print substr($4,5,8)}'|uniq -c|gnuplot -e "set terminal dumb;plot '-' using 1:xtic(2) with boxes" 
# Web request chart

cat /dev/zero > foo & rm -f foo

cat access_log-*|awk '{print substr($4,5,8)}'|uniq -c|gnuplot -e "set terminal dumb;plot '-' using 1:xtic(2) with boxes" 
# Web request chart

cat /var/log/secure.log | awk '{print substr($0,0,15)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
#Show me a histogram of the busiest minutes /sconds  in a log file:

cat DATEI | mail -s MAILSUBJEKT [email protected]
# Datei sich per Email zusenden

cat matching_files.txt | xargs sed -i '' "s/require('global-module')/require('..\/some-folder\/relative-module')/"
# Basic sed usage with xargs to refactor a node.js depdendency

cat uuoc.txt | rev | cut -c 3- | rev 
# Use rev twice to get around cut not being able to relatively remove 3 letters from the end of lines.

cat externs.json | jq ".efExports | .[] | (keys|.[0]) as \$kind | {kind:\$kind,value:(.[\$kind] |.Ident?)}"
# Get purescript externs just some jq code...

cat aws.json | jq -r '.Reservations[].Instances[] | [.PrivateIpAddress, .SecurityGroups[].GroupId,.SecurityGroups[].GroupName,.NetworkInterfaces[].NetworkInterfaceId,(.Tags[] | select(.Key =="Name") | .Value),([.InstanceId| tostring] | join(";"))]|@csv'
# Use JQ to get a csv list of assets in aws with security groups, names, and ENI ID for tracking VPC Flows from JSON -> You need to use the aws ec2 describe instances to get the JSON file. 

cat /proc/net/tcp 
# In a crunch and lacking better tools, you can get Linux's local (non-external) IPv4 address from this file. It's usually the most common non-zero src address in byte form, reversed. So 050010AC -> AC 10 00 05 -> 172.16.0.5

#Backup all databases in a MySQL container
cat databases.txt | while read db; do docker exec $container_name bash -c "mysqldump -uroot -p\$MYSQL_ROOT_PASSWORD ${db}" | gzip -9 > $HOME/backups/${db}_`date +%Y%m%d_%H%M%S`.sql.gz; done

#==============================##==============================#
# CMD CAT
#==============================##==============================#

# Basic cat command in Linux with examples | LinuxTeck
#------------------------------------------------------#

# The Global Syntax of the cat command:
cat [OPTION]... [FILE]...

# Mostly, everyone using the cat command to view the content of the file, so let's begin with the same.
# 1. How to display the content of a file?
# (Let's say we have a file named linux.txt which contains few lines)
# Note: The very simple way to display the content of a file

cat linux.txt
    # Train
    # Bus
    # Aeroplane
    # Ship
    # Car

# 2. How to use line numbers in a File?
# (In the above file there are about 5 lines, let's see how to use line number in the file)
# Note: -n is the option to apply for line number

cat -n linux.txt

    # 1 Train
    # 2 Bus
    # 3 Aeroplane
    # 4 Ship
    # 5 Car

# 3. How to use number nonempty output lines in a file?
# (For line number we have used the '-n' parameter, whereas here we will be using '-b', this is also similar to '-n', but the difference is '-b' will count only the non-blank lines (Means it does not calculate the empty/blank lines. In the below example I have added one space between Aeroplane and Ship))
# Note: The above command shows the difference between '-n and -b' parameters of using the line numbers

cat -n linux.txt                                                                                 cat -b linux.txt

    # 1 Train                                                                                                      1 Train
    # 2 Bus                                                                                                         2 Bus
    # 3 Aeroplane                                                                                              3 Aeroplane
    # 4
    # 5 Ship                                                                                                       4 Ship
    # 6 Car                                                                                                         5 Car

# 4. How to display the content of a file per page?
# (For eg: If we have a file which contains more than a page of content that won't fit into the screen and it goes directly the last page of the file)
# Note: Use 'more and less' combined with cat command to see the content per page. To combine the commands we need to use pipe (|) sign as above.

cat linux.txt | more
cat linux.txt | less

# 5. How view the multiple files contents together?
# (Let's say we have files named 'linux.txt and teck.txt'. we need to see contents of the files together in a single command )
# Note: The above command will display the contents of the two files together.

cat linux.txt teck.txt
    # Train
    # Bus
    # Aeroplane
    # Ship
    # Car
    # India              -          Delhi
    # Canada          -          Ottawa
    # Germany       -         Berlin
    # Malaysia        -         Kuala Lumpur
    # Japan             -         Tokyo

# 6. How to Sorting the contents of different files?
# (Let's say, files named 'linux.txt and teck.txt' having different contents line by line. The output content of the two files can be sorted )
# Note: Use 'sort' combined with cat command to see the sorted contents of the above files. To combine the command we need to use pipe (|) sign as above.

cat linux.txt teck.txt | sort
    # Aeroplane
    # Bus
    # Canada            -          Ottawa
    # Car
    # Germany         -          Berlin
    # India                -         Delhi
    # Japan              -         Tokyo
    # Malaysia         -          Kuala Lumpur
    # Ship
    # Train

# 7. How to use redirect standard output?
# (We can redirect the standard output contents into a new file or the existing with '>' greater-than-symbol. If you choose the existing file then be careful, it will be overwritten.)
# Note: The above command combines the sorted content of 'linux.txt and teck.txt' into a new file named 'testing.txt'. This command will check if the file exists or not. If not it will create as a new file else it will overwrite the new content.

cat linux.txt teck.txt | sort > testing.txt

# 8. How to avoid multiple blank spaces?
# (We can squeeze multiple empty lines breaks in the file with one single empty line). Don't confuse, the below example will show you what exactly it is:

# I have a file named 'teck.txt' with some content, but there are big line breaks between the content of India and Canada. If we use a normal command 'cat teck.txt' it will display exactly as how the content is inside. But when you use the '-s' parameter, it will avoid the big line breaks between the content of India and Canada with a single line break. It will not affect the content of the file, it will only display the content of the format. Just see the difference below :

# Before                                                               After

    cat teck.txt                                                cat  -s teck.txt

#-----------------------------------------------------------------------///

cat split-xaa split-xab split-xac > rejoinedlargefile 
# Join the splits back together.

cat longdomainlist.txt | rev | sort | rev 
# group subdomains by domain. Good use of rev..

# cat = the; grep = what; find = where; while = every; for = these; sleep = um; && = and ; ';' = '.' ; > = here; awk and sed = fuck and shit

# convert JSON object to JavaScript object literal
# install json-to-js as a npm global package
cat data.json | json-to-js | pbcopy

cat /tmp/log.data |colrm 1 155|colrm 60 300

# Explanation: 
    # cat: prints the file to standard output
    # colrm: removes selected columns from a file
    
    
    
# Find all the unique 4-letter words in a text
cat ipsum.txt | perl -ne 'print map("$_\n", m/\w+/g);' | tr A-Z a-z | sort | uniq | awk 'length($1) == 4 {print}'

# Explanation: 
    # The perl regex pattern m/\w+/g will match consecutive non-word characters, resulting in a list of all the words in the source string
    # map("$_\n", @list) transforms a list, appending a new-line at the end of each element
    # tr A-Z a-z transforms uppercase letters to lowercase
    # In awk, length($1) == 4 {print} means: for lines matching the filter condition "length of the first column is 4", execute the block of code, in this case simply print
    
    
  
# remove comments from #Arduino #ino #files 
cat code.ino | sed -r ':a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba' | sed 's/\/\/.*$//' | grep '\S' | sed 's/^[ \t]*//' | grep -v '^$'  

# (I used ru because it is a public project, but I do it with a little script called ruby-all-lines (or just ruby -e))
cat names1.txt names2.txt | ru "sort_by { |l| l.split.second }" 

# Check whether laptop is running on battery or cable -> 1 = on ac, 0 = on bat
cat /sys/class/power_supply/AC/online

# Print your cpu intel architecture family
cat /sys/devices/cpu/caps/pmu_name

#-----------------------------------------------------------------------///
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

  █║▌│║█║▌★ KALI ★ PARROT ★ DEBIAN 🔴 PENTESTING ★ HACKING ★ █║▌│║█║▌

              ██╗ ██╗ ██████╗  ██████╗ ██╗  ██╗███████╗██████╗
             ████████╗██╔══██╗██╔═══██╗╚██╗██╔╝██╔════╝██╔══██╗
             ╚██╔═██╔╝██║  ██║██║   ██║ ╚███╔╝ █████╗  ██║  ██║
             ████████╗██║  ██║██║   ██║ ██╔██╗ ██╔══╝  ██║  ██║
             ╚██╔═██╔╝██████╔╝╚██████╔╝██╔╝ ██╗███████╗██████╔╝
              ╚═╝ ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝╚══════╝╚═════╝

               █║▌│║█║▌ WITH COMMANDLINE-KUNGFU POWER █║▌│║█║▌

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░