Reading logs made easy with bash.
Most of the web programmers would normally look into their applications/server error logs when they find issues, indeed it's a pain when the log path is filled with directories, it's sometimes annoying to do an
It would be very easy if we could cdn as in cd to the new dir ;)
So /me tired some silly script that would make my life easier, do add it to your
Here is the simple script to cdn :
cdn() { local file latest; for file in "${1:-.}"/*; do [[ $file -nt $latest ]] && latest=$file done; printf '%s\n' "$latest" [[ -d $latest ]] && cd $latest || tailf $latest }
Usage: cdn [dir]
Digging into the code:
Get all the file and dirs in the specified path or consider "." as the default path
"${1:-.}"/*
Using file and latest local vars : if
$file -nt $latest
True
if $file is newer than $latest (according to modification date).Finally check if it's a dir or file, if file cd to it else tail it!
Hope this helps you guys, as it's helping me, happy hacking!
Recent blog posts
- watir-webdriver web inspector
- gem list to gemfile
- Packing ruby2.0 on debian.
- Made it into The Guinness Book!
- to_h in ruby 2.0
- Filter elements by pattern jQuery.
- Better HTML password fields for mobile ?
- Grayscale image when user offline
- nth-child CSS pseudo-class Christmas colors
- EventEmitter in nodejs