🖥️tail

➡️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 tail command with important options and switches using examples.

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

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

														  
# To show the last 10 lines of file
tail file

# To show the last N lines of file
tail -n N file

# To show the last lines of file starting with the Nth
tail -n +N file

# To show the last N bytes of file
tail -c N file

# To show the last 10 lines of file and to wait for file to grow
tail -f file

#==============================#
# CMD TAIL
#==============================##==============================#
tail -f udp.log |gawk '{printf("%s %s\n",strftime("%Y-%m-%d_%T", $1),$0)}'
# Prefix the epoch time in column 1 with the local time.

tail -f foo.log|egrep --line-buffered --color=auto 'ERROR|WARN|$'
# tail log & highlight errors (if your grep supports --color) 

tail -f *.log
# You can actually follow more than one log at once and get new updates on them. Use -q to not print filename header.

tail -f access_log | awk '$1~"googlebot"'
# Wait for the friendly Googlebot to pay your site a visit. 

tail -f /dev/ttyACM0 |gawk '{print strftime("%Y-%m-%d %T") " " $0)}' |tee temperature.log
# Arduino temp sensor to timed logfile and view.

tail -f /var/log/syslog | grep CRON
# grep for all cron in syslog following

tail -F 
# will monitor a file, such as a log file, until you type Ctrl-c.

tail -F /var/log/syslog | awk '{printf("\033[%dm%s\033[0m\n",31+NR%2,$0)}'
# Holiday sysLog! Its ready for the new year too. ;)

tail -F syslog |while read -r line;do printf "\033[38;5;%dm%s\033[0m\n" $(($RANDOM%255)) "$line";done
# Random color per log line.

tail !^
# In bash, $^ expands to 2nd word of previous command.
# Just noticed error in previous tweet: s/$^/!^/. 
# Can pull up second word (i.e. first argument) of previous command with !^ in bash.

tail -n2000 /var/www/domains/*/*/logs/access_log | awk '{print $1}' | sort | uniq -c | sort -n | awk '{ if ($1 > 20)print $1,$2}'
# Count number of hits per IP address in last 2000 lines of apache logs and print the IP and hits if hits > 20

tail -n100000 large.log | head 
# Get a sample of 10 lines from a large log file, 100,000 lines from the end of the file.

rsstail -u $FEEDURL -n 50 | while read line; do mail -s "FeedUpdate" $user <<<"$line"; done
# Sending new RSS entries to email 

tail -f /var/log/messages | toilet -f term --gay
# Log in Rainbow Colors

tail -F some_log_file.log | grep --line-buffered the_thing_i_want
# Grep live log tailing

tail -F some_log_file.log | grep the_thing_i_want
# Grep live log tailing, tracks file open/close. "-F" will continue tailing if file is closed and another file opened with same name. This is handy for tailing log files that segment while watching them without having to issue the command again.

tail -f some_log_file.log | grep the_thing_i_want
# Grep live log tailing

tail -f some_log_file.log | grep --line-buffered the_thing_i_want
# Grep live log tailing

# Tail all /var/log text log files - Tails all the human-readable /var/log files and stays on the same filename to work with log rotations.    
tail --follow=name --retry $(ls -altr $(find /var/log -type f  |grep -v -e "gz$" -e "mysql/.*relay" -e "[0-9]$" | xargs file | grep ASCII | cut -d: -f1) | awk '{ print $9 }') &  

tail -F firewall.log |while read -r line;do printf "\033[38;5;%dm%s\033[0m\n" $(($RANDOM%255)) "$line";done 
# Random color per log line.

# Tail all /var/log text log files - Tails all the human-readable /var/log files and stays on the same filename to work with log rotations.
tail --follow=name --retry $(ls -altr $(find /var/log -type f  |grep -v -e "gz$" -e "mysql/.*relay" -e "[0-9]$" | xargs file | grep ASCII | cut -d: -f1) | awk '{ print $9 }') &     

# Is there a trick to get an oneliner that this to run: 
tail -n1001 path/to/file > path/to/samefile?
# If i understand right that you want to omit the use of '>' operator, than you can use tee: tail -n1001 path/to/file | tee path/to/samefile - however without ">/dev/null" at the end tee will also output the file/content on stdout - so if such an extra output is a problem (and you can't add '>/dev/null' at the end of your command) then tee isn't the best solution
tail -n1001 path/to/file | echo > path/to/samefile
tail -n 1001 <<<$(<file1) >file1 works fine

tail -f messages | awk '/ec:8a:dc:09:e1:2f/' 
# I find it easier to use awk to search for lines with a string when using tail -f than trying to use grep options or the stdbuf program.

# `tail -f` a file until text is seen
tail -f /path/to/file.log | sed '/^Finished: SUCCESS$/ q'
# Explanation: 
	tail -f until this exact line is seen:
	Finished: SUCCESS
# The exit condition does not have to be an exact line, it could just well be a simple pattern:
... | sed '/Finished/ q'

# Realtime lines per second in a log file, with history - This is similar to standard `pv`, but it retains the rate history instead of only showing the current rate. This is useful for spotting changes. To do this, -f is used to force pv to output, and stderr is redirected to stdout so that `tr` can swap the carriage returns for new lines. (doesn't work correctly is in zsh for some reason. Tail's output isn't redirected to /dev/null like it is in bash.)
tail -f access.log | pv -l -i10 -r -f 2>&1 >/dev/null | tr /\\r \ \\n
    # Sample output
	    # [2.00  s]
	    # [2.00  s]
	    # [4.20  s]
	    # [20.4  s]
	    # [8.20  s]
	    # [11.6  s]

#==============================##==============================#
# CMD TAIL
#==============================##==============================#
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

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

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

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

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