Xfce Forum

Sub domains
 

You are not logged in.

#1 2026-08-11 12:41:54

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Copy file contents with Thunar instead of broken symlinks

Hi,

it seems to me that it is impossible to work with Thunar once symlinks are involved. I got a collection of image files, hence a graphical file manager in use, while I normally would work in the shell. There are folders that just contain symbolic links to the actual image files in neighbouring folders. When I now select a number of image files, I'd expect a copy and the paste operation to do what

cp file1 file2 file3 /some/where/else

would do, so that I got the actual file contents copied to /some/where/else/. But instead, Thunar always copies the symlinks, resulting in broken links in the target, along with an error during the copy operation because it fails to set the permissions (as the symlink is broken … maybe that one warrants an actual bug report on Thunar).

I get that there can be a preference for copying links or the contents, and also the cp program is not a good model, as it changes its behaviour when copying recursively. My issue with Thunar is that I do not see this option exposed to the user anywhere, and also, that the equivalent of

cp -p -P

is the default for an application that doesn't even offer users a way to _create_ symlinks (as least I did not find it). My user model for Thunar would hence involve mainly people that would only stumble over symlinks that someone else created and thus it is doubly counter-intuitive that a copy operation creates symlinks instead of actual copies of the file contents.

In case I'm not simply seeing a bug here, is there a way make Thunars copy operation be more like

cp -r -L -p

to match what IMHO an ordinary user would expect? Having a choice for explicit symlink management is also something I'd expect, but do not see. I was confused not finding an option to create links, only the custom action to create a link on the desktop. UI for proper symlink handling (with relative and absolute targets) is not trivial for sure. But at least dealing with existing links someone else created  should be possible.

Right now, accessing a (network) folder with a symlinked structure and trying to copy a selection of files from to the local machine is just broken, AFAICS. But maybe I am mistaken and am just missing the obvious. So:

Can Thunar be convinced to follow symbolic links when copying, within the normal UI?

PS: When searching on the web about this issue I stumble upon lots of description on how to add custom actions to certain operations. So I guess one could create a 'copy to $HOME/foo/bar' action, but that would not integrate with the UI regarding progress information and would fix the target folder. Copying file contents seems to me to be a core functionality of a file manager, anyway.

PPS: When trying to copy a broken symlink to start with … I guess I'd expect Thunar to give me an error right then, instead of creating the broken link in the target and then complaining that it cannot set permissons on it.

Offline

#2 2026-08-11 16:11:07

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

Following links can be a security issue which can be exploited. A program open will follow the link read the file RO and open. Depending on permission boundaries, including files system types, thunar will copy a link intact and will still be a link. In order to copy a link on a networked file there is a boundary = you can't embed the network connection info, mount permission, etc.. Do the same on a local file system and thunar will properly copy a working link.
?

Offline

#3 2026-08-11 19:18:41

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

I am not sure I follow the security issue argument. Programs can be made to open files the user directs them to open? How is it different to access the file via a symlink before, after, or during a copy operation?

But apart from that: I just tried copying a symlink from a local directory and while I don't get an error about permissions (that seems to relate to specific permissions on the network sftp share being impossible to retain), I do get a broken link. considering this setup:

user@host:/dev/shm$ ls -l a/
-rw-rw-r-- 1 user user 0 Aug 11 14:17 bar
-rw-rw-r-- 1 user user 0 Aug 11 14:16 foo
lrwxrwxrwx 1 user user 3 Aug 11 14:16 link -> foo
total 0

I open /dev/shm/a with thunar and mark link, select copy, go one directory up, select paste. What I get is this:

user@host:/dev/shm$ ls -l link 
lrwxrwxrwx 1 user user 3 Aug 11 21:07 link -> foo
user@host:/dev/shm$ file link
link: broken symbolic link to foo

So Thunar directly copied the link to another location, breaking it. Did you intend to imply that Thunar should translate the link to point to a/foo instead, to make it work again?

Offline

#4 2026-08-11 19:41:50

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

As user I would not expect the paste to work, that would be bad.
With a root thunar, the link will be valid when pasting into root space.
With a user thunar the link will be valid only if pasted into user space, typically ~/.

That is a permission boundary. Across the network is another boundary.. In that case the link is referenced to local where the file does not exist, so broken.

To pull across the network either open the file according to mime type and 'save as' locally, or create a custom action using scp or rsync using their switches to follow links.

Or, navigate with thunar to the actual file...

Offline

#5 2026-08-11 20:10:28

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

I just checked nemo, pcmanfm, xfe, and dolphin: They all share the behaviour of copying the symlink without dereferencing, breaking it in the general case.

I am wildly puzzled. I cannot blame Thunar here. It does what everybody else does, apparently. It seem symlinks are just somethiing graphical file managers opt not to support in a useful way, with intention. They do access the linked files for generating an image preview, for example. They allow opening them with applications (wich just get the link resolved without caring about this, I presume). But you cannot copy the linked file contents in a meaningful way.

Seems my fading memories of working with (sym)links in graphical file managers are of the Windows Explorer and something with the shift key …

Of course people working with UI that doesn't present the concept of symlinks much won't end up with a collection of symlinks that then make trouble. My scenario is a user browsing a network share (say, of family photos) where another user created folders with selections of files, linking to other locations to avoid actual copies.

If the whole world of UI designers decided that this is not a use case for graphical filemanagers, I might have to reconsider my choices.

Maybe doing hardlinks instead is a way, which makes efficient backup harder. Or: Can one smuggle the option

sshfs -o follow_symlinks

into the VFS that accesses the remote share? That would do the trick in my use case: Just hide the fact that there are symlinks to the client. The client just wants to see the pictures and doesn't really care about symbolic or even hard links.

PS: Nice one … while testing sshfs options, I managed to put dolphin into a deadlock with its integrated shell window. I started sshfs there, forgot the prompt for my SSH keyphrase and clicked on the appearing network folder in the navigation pane. That freezes the UI that tries to access the not-yet-ready mount, while the SSH passphrase prompt waits, unable to get my input because the main window grabbed it … probably that is worth a bug report, too.

PPS: I got logged out of the forum while editing this post. Can the timeout be tuned somehow? I was lucky to have the text present in Firefox after going back, being able to copy and paste it.

Added later 06 min 47 s:

CwF wrote:

As user I would not expect the paste to work, that would be bad.
With a root thunar, the link will be valid when pasting into root space.
With a user thunar the link will be valid only if pasted into user space, typically ~/.

Putting the network question aside, can you help me understand this terminology? Are you saying that Thunar behaves differently when run by an unprivileged user as opposed to root?

I put the test directory from above into ~/ now. Opened with thunar, copied ~/a/link, went to ~/, pasted the file. The result: There is now a broken link ~/link that references a non-existing file ~/foo. How would I get a valid link from copying ~/a/link which is a symlink to foo in the same directory … only when copying into the same directory again? When I copy to anywhere else, including the user's home directory, I get a broken symlink.

What am I missing?

Last edited by sobukus (2026-08-11 20:17:52)

Offline

#6 2026-08-11 21:10:00

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

sobukus wrote:

Are you saying that Thunar behaves differently when run by an unprivileged user as opposed to root?

Not differently exactly, but with and without proper permission.

I can only think of one example in my case.
/etc/channels.conf is a legacy file for gnutv. Bad choices aside, some utilities reference it, some write to it, etc.

Over time I wrote a tickle (tcl/tk) app ‘free-to-air’ to control tuners with a nice gui and I could avoid using the root owned file, instead I thought around it..

I created a link with a root thunar (pkexec thunar) and left it as /etc/channels.lnk
I then used a user thunar to copy that link to ~/.config/mpv/dvb/ and renamed it to channels-by-number.conf
My programs then read/write to that file and the etc copy is updated and available for the rare occasion I use a legacy utility directly that needs that etc copy to be in sync.

I think that's right - did it abut 7 years ago....

A general summary could be - a single user and utility can't do that in one step unless we add ‘as root’ options, it takes both. The link created as root, then copied by user to user space.

Follow?

Offline

#7 2026-08-11 21:42:37

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

CwF wrote:

Follow?

Pun intended regarding symlink behaviour? ;-) But, to be serious… I do have trouble following.

CwF wrote:

I created a link with a root thunar (pkexec thunar) and left it as /etc/channels.lnk

In your example, what is /etc/channels.lnk, exactly? Is it a copy? Is it a symlink (I don't see how you would create such with Thunar)? You lost me right there, sorry.

CwF wrote:

I then used a user thunar to copy that link to ~/.config/mpv/dvb/ and renamed it to channels-by-number.conf

So you copied /etc/channels.lnk and pasted it into the dvb folder? And then programatically sync the copy (copies?) with /etc/channels.conf? What role does a symlink play here when things are synced via copies?

CwF wrote:

The link created as root, then copied by user to user space.

I have trouble mapping the concept of root and user space here. In my world, root and users can create symlinks as they want, anywhere they have write permissions.

The only way I've seen to create a symlink in Thunar is to Send To → Desktop (as link). This is a link with an absolute path. You can then copy that link to another place using Thunar, as it will not derefence it, and it won't be broken as the path is not relative. Are you talking about handling symlinks that way?

Offline

#8 2026-08-11 22:33:46

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

sobukus wrote:

In your example, what is /etc/channels.lnk, exactly? Is it a copy? Is it a symlink (I don't see how you would create such with Thunar)? You lost me right there, sorry.

Navigate to the directory, highlight the file → select from menu Edit>Make Link
The link is created in that directory with the same name.

sobukus wrote:

So you copied /etc/channels.lnk and pasted it into the dvb folder? And then programatically sync the copy (copies?) with /etc/channels.conf? What role does a symlink play here when things are synced via copies?

I just looked and I may have done an opposite procedure all those years back..
create link with user thunar...
Reach into that directory with root thunar and copy link, and past into /etc and rename.
Inverse from my first memory...
So I edit the user file in ~/.config/mpv/dvb/, and that file with a user thunar created the link, then copied by a root thunar to /etc.
Then the /etc file stays synced. This is messy way, avoid links if you can.

sobukus wrote:

I have trouble mapping the concept of root and user space here. In my world, root and users can create symlinks as they want, anywhere they have write permissions.

Well, it is something to wrap our heads around. Root is anywhere, but user space 'as root' should be avoided. User space is anywhere in home, or ~/.
There are other places where users have permission, like /run/user/, but usually not used directly by the user. Additional group permissions (staff, wheel) may grant rights in places like /usr/local/.

It is tricky, and it does bite users. Properly setup, it is possible to never use chown, a bad habit.

Hopefully, I'm not confusing!

Offline

#9 2026-08-12 07:26:07

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

I get what you mean with user/root space now, thanks.

I did not expect the option to create a link in the Edit menu. I did not see it in the context (right-click) menu of the file and just did not think about looking elsewhere. I did check under 'File' about the option to create a fresh link, next to create folder or create new (empty) file.

After creating a link to foo with Thunar, I see this:

$ ls -l a
total 0
-rw-rw-r-- 1 user user  0 Aug 11 14:17 bar
-rw-rw-r-- 1 user user  0 Aug 11 14:16 foo
lrwxrwxrwx 1 user user  3 Aug 11 14:16 link -> foo
lrwxrwxrwx 1 user user 18 Aug 12 09:07 link to foo -> /home/user/a/foo

So when you say 'same name', you mean 'link to ' + name. For someone working on the shell, with scripts, loops, etc., this enters the uncomfortable world where quoting really matters … you usually avoid spaces in file names. But this is the world of graphical desktops and 'normal' users, so I get that you use the expressiveness of the full character set, while I'd choose a different scheme.

Now the important bit is: Thunar creates a link to an absolute path. That link you can move around and it is not broken. But on my use case of a network share, I cannot predict where it will be mounted, so absolute links absolutely do not work. Or the other way around: User creates a directly with links to images in another directory locally and then copies both to the network share: The links will be broken unless they were created as relative links.

I see that Thunar is not the tool to create hiearchies of linked files, but one feature would totally fix the problem at hand of the family member accessing directories where some image files might be symlinks to neighbouring directories: When the user selected a number of files (after glancing at the image thumbnails and clicking a few dozen dimes), some of which are symlinks, Thunar could ask the user if the intention is to copy the links or the contents. It does already pose questions when trying to overwrite files, for example, so that would be well within expected behaviour and to be considered user-friendly, IMHO.

Do you think it feasible to add such behaviour? Follow symlinks on user request?

The grander picture has me wondering about hiding symlinks from the client (-o follow_symlinks in sshfs) or switching to using hard links instead on the server, but that, too, has implicatiions. But giving the user the option to copy the link or the linked file seems so obvious to me. I see that Dolphiin also doesn't do that. But it _does_ have the option to create fresh symlinks from the context or main menu, with UI for absolute (file selector) and relative (text field with autocomplete) paths.

PS: I know that there are desktop applications for image/media management, with separate databases and all. I avoided these as unnecessary complexity and lock-in into their databases. I guess that people writing integrated desktop environments rather work on media librariy applications/infrastructure than support people organizing things with symlink folders. But my expectation from a file management application is that it deals with all user-visible aspects of file systems, and that includes symlinks and also hardlinks, for that matter.

Last edited by sobukus (2026-08-12 07:32:41)

Offline

#10 2026-08-12 17:32:09

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

sobukus wrote:

Do you think it feasible to add such behaviour? Follow symlinks on user request?

I think it maybe could, but using a custom action is a better path since it does offer the mechanism to do what you need, without encumbering thunar itself with any extra weight.
https://docs.xfce.org/xfce/thunar/custom-actions

Offline

#11 2026-08-13 19:51:17

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

Do you mean something like

TARGET=$(ui-that-selects-a-folder) && cp -rpL %F "$TARGET"

I see two problems with that:

  • I need to start some path selector UI right from the UI for file management. Is there some

    thunar --select-path

    thingie? I presume not, since otherwise the custom actions docs wouldn't use a text entry field from zentiy for such tasks?

  • The copy action, again, evades the functionality of the file manager, giving no feedback about its operation.

It feels strange to have to leave the file manager UI for file management tasks. But that being said, you open a path there for my main mode of operation: I usually work in the shell myself (trying to settle thunar usage for a family member) and have the occiasional need for graphical file selection (images from thumbnails). I could actually launch thunar from a shell session just to pick some files and have a custom action print them out to me:

for f in %N; do printf "%%s\n" "$f"; done

I could then use that to do operations on the selected files in my workflow. But that somehow inverses the sitation. Now you've shown me a way to integrate thunar in a shell file management workflow by suggesting integration of shell file management into thunar;-)

That being said: What would your preferred UI be to launch from a custom action for selecting the target folder for the follow-symlinks copy?

Offline

#12 2026-08-13 21:55:48

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

I was assuming you would navigate to this share intending to highlight a few files and copy them locally. If these files are links, then use a CA to pass these highlighted files (%F) to a command line or a referred script which uses a method that will copy the actual file. I previously noted scp or rsync for that purpose.

This action when using scp or rsync will also need permission to ssh to/from the remote file system. So an additional password dialog will be needed, or for passwordless a valid key.

In this scenario a file selection dialog isn't necessary, thunar does that for us.

You will have to feel out the options for your use case. I did a check, went into a backup server from which user files are push/pull and made a link, renamed to linkcheck.jpg, moved the link to another directory, did a pull, and it did show up as a valid jpg, not a link. That is using scp.

From the local thunar, I highlight the directory ~/Pictures, right click to see the 'pull' selection and click, and it magically shows up. I use passwordless ssh keys for intranet connections.
The action cli with generic names;

scp -p backup@server:/home/backup/Public/.secret/Pictures/$(hostname)/* ~/Pictures/ ; notify-send "Pictures packed"

See what you can make of it...If you establish a ssh key, use thunar to select the files, right click and select  your CA, that would be something like this:

scp -p user@domain:%F ~/Pictures/
sobukus wrote:

That being said: What would your preferred UI be to launch from a custom action

It is not needed here, but I'll commonly use gxmessage for simple dialogs with a notify-send trailer and usually forego complex error checking and confirmations. I'm not that good...
For a few complex things I do use tcl/tk.  A tangent to the point here, but that does provide a file selection dialog if needed.

Offline

#13 2026-08-14 09:53:38

sobukus
Member
Registered: 2026-08-11
Posts: 7
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

I was assuming that, while Thunar is running and accessing the shares via gio framework, that the underlying mounts are accessible to a script from a custom action, so simple cp would do. Probably need to test this.

About the need for path selector UI: I don't want to hardcode the target of the custom copy action. I'd need to create a new action for each destination folder. In the image example, it would be differing folders for differing projects someone works on and wants a selection of images for.

But anyway, for the case at hand, I now converted all links to hard links and will try to remember to include respective options in any copy/move/sync operation to keep them intact. Probably I'll need a deduplicator script that finds and links identical files from time to time …

Offline

#14 2026-08-14 11:47:28

gogogadget
Member
From: EU
Registered: 2023-03-19
Posts: 71
LinuxFirefox 153.0

Re: Copy file contents with Thunar instead of broken symlinks

Hello,

sobukus wrote:

I'd need to create a new action for each destination folder. In the image example, it would be differing folders for differing projects someone works on and wants a selection of images for.

You can use Yad in a script to select the directory graphically :

https://yad-guide.ingk.se/file/yad-file.html#_directory


EndeavourOS
Xfce+gtk3-classic (no CSD)+Picom

Offline

#15 2026-08-14 16:16:25

CwF
Moderator
Registered: 2018-01-28
Posts: 341
LinuxFirefox 140.0

Re: Copy file contents with Thunar instead of broken symlinks

sobukus wrote:

so simple cp would do. Probably need to test this.

Your first post cp string may work fine as a custom action, true.
In my thinking I never browse the network and use all direct actions, so i thought right past that option.

sobukus wrote:

I don't want to hardcode the target of the custom copy action. I'd need to create a new action for each destination folder.

Yes, but there is a Submenu option within the CA dialog that allows a menu of options to be built for the action without any dialog helper

gogogadget wrote:

You can use Yad in a script to select the directory graphically :

Along with zenity, yet another possibility. The built in Submenu option can build a sophisticated selector, and of course these can be combined with any additional utility. I'll usually keep the complexity within Submenu and gxmessage.

Example of an all inline function without an external script, still using keyed scp:

Dest=$(gxmessage "Send file(s) to" -geometry 540x120 -borderless -print -buttons "Desktop,Downloads" ) ; scp -rp %F backup@server:/home/backup/$Dest/ ; notify-send "Sent to $Dest"

There is lots to explore!

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.031 seconds, 7 queries executed - Memory usage: 639.23 KiB (Peak: 672.21 KiB) ]