I have a home directory in my unix box. I would like to setup a number or shortcuts in it to point to the latest file in another directory and the link will update if a newer file is created.
Is this possible?
So far I able to get the latest file:
ls -lrt | tail -n1
Thanks
[EDIT]
Perhaps I could even create a shell instead of a softlink which finds the latest file and returns it so I can open/grep/delete etc?
Symlink, also known as a symbolic link in Linux, creates a link to a file or a directory for easier access. To put it in another way, symlinks are links that points to another file or folder in your system, quite similar to the shortcuts in Windows.
The reason you get "xyz-file: can make relative symbolic links only in current directory" is because for the source directory, you specified a relative path. It'll work as you want it if you specify an absolute path for the source, like so: "cp -sR /root/absolute/path/name dest".
A symlink is a symbolic Linux/ UNIX link that points to another file or folder on your computer, or a connected file system. This is similar to a Windows shortcut. Symlinks can take two forms: Soft links are similar to shortcuts, and can point to another file or directory in any file system.
To create a symbolic link, use the -s ( --symbolic ) option. If both the FILE and LINK are given, ln will create a link from the file specified as the first argument ( FILE ) to the file specified as the second argument ( LINK ).
In bash, this will make a link to the latest file or directory in "target-directory" called "latest":
ln -s target-directory/`ls -rt target-directory | tail -n1` latest
And this will wait for a change in "target-directory" before returning:
inotifywait -e attrib target-directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With