Friday, September 11, 2009

Bash: Finding files between two dates in the current directory

Today my boss asked me for a bash command (or script) to find some files between two dates.
Thanks to Jadu Saikia over at Unstableme his post UNIX BASH scripting: Find Files between two dates, I had a starting point.

This will find all files between the two dates (20071019 & 20071121) in this case.
find . -type f -exec ls -l --time-style=full-iso {} \; | awk '{print $6,$NF}' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20071019 && $1<= 20071121 {print $2}'

Now, if you want just PGP files you would do:
find *.pgp -type f -exec ls -l --time-style=full-iso {} \; | awk '{print $6,$NF}' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20071019 && $1<= 20071121 {print $2}'

The second request that my boss was looking for with this is the file size, something that was being left out by awk. So we can fix that by updating the command to:
find *.pgp -type f -exec ls -lh --time-style=full-iso {} \; | awk '{print $6,$NF,$5}' | awk '{gsub(/-/,"",$1);print}' | awk '$1>= 20090624 && $1<= 20090901 {print $2,$3}'

We added in a $5 to the first awk command, and the final one had $3 added to it. Also I like human readable file sizes so I added -h to the ls command.

Howto Make a T1 Crossover Cable

I learned this one about a month ago while turning up the T1 connection for my fax server. The tech that installed the Cisco equipment left us with a crossover cable, but a data one, so I cut the ends off and re-crimped the cable like so:

You only have to worry about 4 of the 8 wires if you are using typical cat-5 cable like I did.

1 <—> 4
2 <—> 5
4 <—> 1
5 <—> 2
Or if you go by colors like I do
Side 1 (left is cable end, clip underneath):
Pin 1: Orange White
Pin 2: Orange Solid
Pin 3: none
Pin 4: Blue Solid
Pin 5: Blue White
Pin 6: none
Pin 7: none
Pin 8: none

Side 2 (left is cable end, clip underneath):
Pin 1: Blue Solid
Pin 2: Blue White
Pin 3: none
Pin 4: Orange White
Pin 5: Orange Solid
Pin 6: none
Pin 7: none
Pin 8: none

Then you are done!