Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
Hi, I am having a problem I hope you can help me to solve.
I have a shell script that is run by root, that moves some stuff to another location and leaves at the original place a symbolic link instead.
The problem is that the owner of the link is root, and I would like to have the original user as the owner of the link (so he can follow and access the original file)
Any ideas on how to do that? I looked at ln man pages, but found nothing about ownership
The problem is that this script is run for files belonging to several users, so I have to figure out how can I get the owner.group attribute of such files in order to use chown
Mainly because this is a script intended to move stuff to a offline disk. The idea is that users leave in a particular file the path to the files they want to move offline, and then this script runs on a daily basis, and moves those files offline leaving a link to the new location of the file. But then I would need to identify the user.group of each file being moved in order to create the link with the same user.group, unfortunatedly I do not know how to do this from inside the script.
Ok, I think that the script can get the owner.group info by issuing the following command:
ls -l filename | tr -s ' ' | cut -d ' ' -f 3,4
What do you think? I am not sure if this is totally ok, ls -l filename list the file, tr squeezes all extra spaces between fields, and cut get fields 3 (owner) and 4 (group)
Distribution: openSuSE Tumbleweed-KDE, Mint 21, MX-21, Manjaro
Posts: 4,639
Rep:
Code:
ls -la
(That's LS-LA) should show owner and group. Pipe it over to any tool to manipulate output (forgot the comand, sorry) and load the value to $OWNER. Then do a chown...
<edit> Hehe this is simultaneity for you
Glad you knew the comand as well...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.