# Find palindrome dates in the Linux command line - explained

DevFeed: [Find palindrome dates in the Linux command line - explained](<https://devfeed.tech/articles/find-palindrome-dates-in-the-linux-command-line-explained-37456.md>)

Original publisher: [Read original article](<https://iridakos.com/programming/2020/02/06/shell-palindrome-dates>)

Author: Lazarus Lazaridis

Published: 2020-02-06T10:00:00Z

Content type: tutorial

Language: en

Sources: [Lazarus Lazaridis](<https://devfeed.tech/sources/lazarus-lazaridis.md>)

Topics: [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Terminal](<https://devfeed.tech/topics/terminal.md>)

Tags: [awk](<https://devfeed.tech/tags/awk.md>), [bash](<https://devfeed.tech/tags/bash.md>), [climagic](<https://devfeed.tech/tags/climagic.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [commands](<https://devfeed.tech/tags/commands.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [linux](<https://devfeed.tech/tags/linux.md>), [opensource](<https://devfeed.tech/tags/opensource.md>), [programming](<https://devfeed.tech/tags/programming.md>), [scripts](<https://devfeed.tech/tags/scripts.md>), [terminal](<https://devfeed.tech/tags/terminal.md>)

## AI overview

A tutorial explains a Linux command-line pipeline for finding palindrome dates. It breaks down brace expansion, date formatting, whitespace removal, reversing and comparing date strings with standard command-line tools.

## Source excerpt

Yesterday I saw a great command that finds the palindrome dates between now and x days ago. The command was posted on Twitter by @climagic (a great account to follow if you want to find awesome command line stuff). In this post we are going to break it down and explain how it works. What is a palindrome Palindrome is a word/number/phrase or other sequence of characters that reads the same backward as forward. - Palindrome - Wikipedia Few days ago, the date was 02/02/2020 which was a palindrome: The command printf "now - %d days\n" {1..332044} |date -f- +%Y%_m%_d$'\n'%Y%m%d |tr -d ' ' > alldates.txt; rev alldates.txt >revdates.txt; paste alldates.txt revdates.txt |awk '$1==$2{print $1}' And here's a more readable version using new lines after each pipe. printf "now - %d days\n" {1..332044} | date -f- +%Y%_m%_d$'\n'%Y%m%d | tr -d ' ' > alldates.txt; rev alldates.txt >revdates.txt; paste alldates.txt revdates.txt | awk '$1==$2{print $1}' I am going to explain each part of the command separately. Note that the output of each part is the input of the next part (following the pipe |). printf "now - %d days\n" {1..332044} The first part seems pretty straight forward but it does have an interesting part, the brace expansion mechanism, which I didn't know of. Open a terminal and type the following commands: # From 1 to 10 $ echo {1..10} 1 2 3 4 5 6 7 8 9 10 # From a to z $ echo {a..z} a b c d e f g h i j k l m n o p q r s t u v w x y z # From 10 to 20 $ echo Before-{10..20}-After Before-10-After Before-11-After Before-12-After Before-13-After Before-14-After Before-15-After Before-16-After Before-17-After Before-18-After Before-19-After Before-20-After As you can see, the brace expansion allows the generation of values based on a "sequence" we set. Learn more about the Brace expansion mechanism here. Part explained we print the phrase "now - x days" so many times as the number of values expanded from the sequence {1..332044} will generate 332044 values starting from 1 and in