[SOLVED] Why does Kate replace spaces in filename with "%20", thus preventing opening it?
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.
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.
Why does Kate replace spaces in filename with "%20", thus preventing opening it?
I'm using the the Kate editor ver 16.04.2 on live knoppix 7.7.1 on a usb stick.
When I double-click on a normal text file in pcmanfm, Kate opens but it
replaces the spaces in the filename with "%20", and a message says "New", which
I presume means "new file". The contents of the file I double-clicked on do not
appear in Kate, but the text window is empty.
Say the true filename is "my notes", then Kate changes it to "my%20notes".
If I open Kate separately, then opening the file in the following ways DOES
work:
a) Using File/Open from Kate's menu, and selecting the file from there.
b) Clicking and dragging the file from pcmanfm across to the Kate window.
My humble question:
Why does the double-click opening method replace spaces with "%20", and how do
I fix it?
On my main Debian system on the hard drive, Kate (ver 3.8.4) opens a
double-clicked file fine.
Why does the double-click opening method replace spaces with "%20", and how do I fix it?
You should not have files names with spaces in them. Change my file to my_file or something with allowed characters. If your file name has spaces in it then you'll have to quote the name. Or better yet, don't put spaces in file names.
I'm not sure teckk is exactly right. %20 is the hexadecimal equivalent to the space character. Spaces in file names have been "ok" to use in both linux and windows (and I think in whatever version of the OS Apple's been using) for quite some time. There are some rules, though.
If your using a terminal emulator (I use KDE, and Konsole alot) it will take spaces for the names of files, but you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character (the space, in this case, which usually means "here is the next part of the command on this line") and take it as a plain character. So the command to list my file.txt should be typed as
Code:
#ls my\ file.txt
No quotes needed, but it often becomes hard to read.
But here's something I discovered about kate. I often create playlists for my mp3 player using VLC. The standard play list has two lines for every file, the first being a comment, the second being the file name. When I use kate to open the file created by VLC, the file name line always uses %20 for spaces, but the comment line does not. That one reads as you'd expect, with the space character.
I usually do a edit -> replace all in kate to change the %20s to the space character.
If I recall correctly, kwrite does not do this. So yes, I agree that it's some setting or other in kate that I do not understand either.
Spaces in file names have been "ok" to use in both linux … for quite some time. If your using a terminal emulator … you either have to enclose the entire file name in quotes or you have to use the \ character to make it suppress the special meaning of the next character
Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots
Spaces will work in GUI programs and you can force them to work in the command line. But they are not actually acceptable in Unix file names (which, of course, includes internet addresses) and may cause havoc with scripts or other programs that have not been designed to cope with them. It's far better to stick to the rules for file names:
1. start with a letter or number
2. only use letters, numbers, under-scores, hyphens, or dots
It may be recommended that you don't use them, but spaces *are* allowed in *nix filenames.
Could I humbly point out that it's not the use of spaces in filenames that is
the problem.
As I mentioned at the end of my original thread, I have NO PROBLEM
double-clicking a filename in pcmanfm* file manager on my main Debian system on
the hard drive. Kate happily opens the file, and spaces aren't replaced with
%20. (*I think it's an older version than pcmanfm on the live knoppix 7.7.1 on
usb stick.)
It's when I double-click a file in pcmanfm (ver 1.2.4) ON THE STICK when spaces
are replaced by %20 in Kate.
I did the following tests (SOLELY on the stick):
1) Using pcmanfm:
a) (This is the SAME scenario I've already described in my original thread.)
Kate was already the default application that's launched when a text file is
double-clicked. I double-clicked the file "my notes" in pcmanfm, but Kate
opened a NEW file called "my%20notes", with nothing in it.
b) While Kate was still open at "a)", I did the following to see what filename
was passed to Kate:
Code:
$ ps ax | grep kate
4893 tty5 Sl 0:01 kate -b file:///home/knoppix/my%20notes
c) I changed the default launch application from Kate to KWrite. When I
double-clicked "my notes", KWrite opened a NEW file called "my%20notes".
d) I changed the default launch application to Leafpad. When I double-clicked
"my notes", Leafpad CORRECTLY opened "my notes".
2) Using nautilus file manager:
I set the default launch application to Kate. When I double-clicked "my notes",
Kate CORRECTLY opened "my notes" (ie no %20 used).
CONCLUSIONS so far:
It seems to be ONLY pcmanfm (not other file managers, such as nautilus) that
"causes" %20 to be used in Kate. Also it seems to be KDE launch applications
(Kate and KWrite) in which the %20 problem occurs - but only via pcmanfm. I
don't think pcmanfm itself is a KDE application.
I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.
@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?
I think the answer just given at Stack Exchange is probably on the right track: Pcmanfm is passing the name as a url. There might be something in the Pcmanfm configuration files you can alter, or else there are just four options: use one of the two opening methods that work, add .txt to the file name so that the file type is clear (I'm not sure that would work), or remove the space.
@hydrurga
Do you not know the difference between "allowed" and "acceptable"?
Have you nothing better to do than to make silly comments about other peoples' posts?
I'm betting this is correct. %20 is the url code for a space, so passing the directory as a URL not as a straight directory would definitely cause this behavior.
I'm using the LXDE desktop environment, and did the following to fix the
problem.
Select the KMenu icon at the left end of the Desktop Panel at the bottom of the
screen. Select Accessories/MainMenu. When the MainMenu application appears,
click on Accessories in the left box, then click on Kate in the middle box, then
click on Properties at the right.
In the "Command" box, replace "kate -b %U" with "kate -b".
When I now double-click a text file in pcmanfm, Kate correctly opens the file,
ie spaces aren't replaced with %20.
I don't have much knowlegde of the percent parameters (like %U), but I've a
feeling that %U might mean "Treat the argument supplied to Kate as a URL" (not
as a normal file).
Thanks very much for the help that you've all given.
Last edited by winger9; 06-08-2018 at 03:21 PM.
Reason: Removed unneeded paragraph.
You will notice that %U allows multiple files to be passed to the target application (e.g. you could highlight several files and then open them all in Kate). So, a better bet might be to replace the %U by %F.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.