How to make a shell script do not resolve a symbolic link
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to make a shell script do not resolve a symbolic link
Hi,
In my shell script I want to do a ls on the parent directory to a symlink in the path
ls -1 -tr $my_dir/../../../
the second directory above $my_dir is a symbolic link, and when a .. is done, it goes to the parent directory of the path which the symbolic link is referring to.
I do not want to go to the referred path, but to the actual parent of the symlink. How to achieve this. Please advice.
Do you know how to do this at the command line? What have you googled and started with? We like to see some effort on any OP's part and then offer assistance.
cd $my_dir/,,/,,/ to ignore symbolic link and go to the symbolic link parent directory
Still,
I am struggling with the same question, I did not get a way to ignore resolving the symbolic link in a relative path and go to the actual parent directory of the symbolic link.
I have code ready by parsing the string using SED, but I felt, there will be an option to get through this directly using cd /ls . Please advice.
to force the shell to not follow symbolic links using shell built-in like cd. It doesn't affect the behaviour of ls, which is an external command, anyway. A workaround might be:
Code:
(cd $my_dir/../../../ && ls)
Since it runs in a subshell, it doesn't actually change the working directory of the parent shell. Moreover, if you simply want to retrieve the path of the directory and use it in other commands:
Code:
my_path=$(cd $my_dir/../../../ && pwd)
find $my_path -name something
ls -lrt $my_path
echo "The path I'm looking for is $my_path"
Hope this helps.
Last edited by colucix; 02-06-2013 at 02:55 AM.
Reason: Changed variable name to avoid redundancy with the OP example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.