Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
A missuse of the tool "fslint" created many (realy many) hardlinks in my /home folder.
Now I am looking for a script, which converts all those hardlinks into softlinks. The difficult part will be to select a "major file". This is normally the file with the shortest path.
Better than the filename-size (or path-size) is for me the path depth (find's print's %d-argument). The filenames size can be used as a second argument. Anyone knows how to print the filenames size?
But back to the main problem:
The following code shows all my files in the right order:
I'm looking for the same solution. However, I want to use it on files that contain spaces in the names. I reviwed the proposed solution above and it looks weak to me. Has anyone got an improved solution by any chance?
My paths do include newlines, unfortunately. (Personally, I wish operating systems had not adopted this convention of allowing file and directory names with newlines. I don't name my stuff with spaces when I create the names myself.)
I tried using code like this earlier without success yet.
Code:
IFS=$'\n'
...
unset IFS
I guess I'll keep experimenting a bit and searching for a solution. I appreciate any other ideas.
My paths do include newlines
...
I guess I'll keep experimenting a bit and searching for a solution.
It may be possible to fix my code to accomodate paths with newlines by changing -printf '%i:%p\n' to -printf '%i:%p\0' and exploring sort's --files0-from=- and --zero-terminated options. According to my understanding of the options they should have worked but I probably messed up some detail.
EDIT: and the while IFS= read -r path_info to while IFS= read -d '' -r path_info
It may be possible to fix my code to accomodate paths with newlines by changing -printf '%i:%p\n' to -printf '%i:%p\0' and exploring sort's --files0-from=- and --zero-terminated options. According to my understanding of the options they should have worked but I probably messed up some detail.
EDIT: and the while IFS= read -r path_info to while IFS= read -d '' -r path_info
Thanks again. I will definitely try your code. I'm going to do that right now.
But I have to apologize because I seriously misread your prior post. Somehow when I read and wrote the word "newlines" I really meant "spaces"! Don't ask me how/why I did that. :-/
Generally, my paths do not contain newlines, but they do contain spaces. Now that I re-read your post, everything is clear to me and I'm going to try your solution as-is.
However, even though my paths do not generally contain newlines, there are a few rare exceptions. Something (possibly a Mac OS X client) is writing files with the name "Icon" followed by a newline. The names show up either as "Icon?" in the terminal or "Icon^M" in other places. I delete these files every time I find them. Your code gives me the idea to do this:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.