The command above creates a symlink to the most recent directory under /home/. As usual, first try it without "| bash" at the end, so you can test what does it print out.
A blog about tips and tricks for linux - as I do some development, sometimes I find some good staff which I would like to store somewhere. I will be happy if you find this stuff to be useful for any reason.
Showing posts with label symlink. Show all posts
Showing posts with label symlink. Show all posts
Wednesday, October 3, 2012
Create symlink to the most recent directory
Recently I needed to find a way to create a symlink to the most recent directory so it can be synced up to some other place. Here is the command in linux which can do that:
find /home/ -maxdepth 1 -mindepth 1 -type d -printf '%TY-%Tm-%Td %TT %p\n' | sort -r | cut -d ' ' -f 3 | head -n 1 | awk -F" " '{print "ln -s "$1" latest-dir"}'| bash
The command above creates a symlink to the most recent directory under /home/. As usual, first try it without "| bash" at the end, so you can test what does it print out.
The command above creates a symlink to the most recent directory under /home/. As usual, first try it without "| bash" at the end, so you can test what does it print out.
Subscribe to:
Posts (Atom)