Bash - find | xargs syntax

Hello.
Question 1
In folders I have filenames with spaces ( generally .desktop files ).
Folder names has no newline nor spaces.
I have tried two syntax, one works the second not.
I would like to know why.
This works :

find $PATH1 $PATH2 $PATH3 $PATH4 $PATH5 $PATH6 $PATH7 $PATH8 $PATH9 $PATH10 $PATH11 $PATH12 $PATH13 $PATH14 -type f | xargs -I{} kate {}

This does not works

find $PATH1 $PATH2 $PATH3 $PATH4 $PATH5 $PATH6 $PATH7 $PATH8 $PATH9 $PATH10 $PATH11 $PATH12 $PATH13 $PATH14 -type f | xargs -d ‘\n’ kate

Question 2
As said filenames may have spaces ( generally .desktop files ).
Folder names has no newline nor spaces.
If I use -print0 as actions that mean that the output is ‘\0’ terminated even if there are no special characters in the file names.
‘\n’ is just replace by ‘\0’.

Question 3
I use ‘| xargs -I{} someCMD {}’ .
Is it sufficient even if I use ‘print0’ in the find part side; or must I use the option -0 accordingly in the xargs side.

Thank you for helping.

What exactly “works” and “does not work” mean?

I miss question mark. If in other cases it is possible to at least attempt to guess your question, here I do not understand it.

Yes, you must.

Question 1
Script 1 works → all 25 files are open at ounce in kate
Script 2 does not works → files are open one by one in kate. You must close the first one to have the second opened in kate, then closer the second to get the third one , and so on.

Question 2
What I want to know is one use ‘print0’ because one want a ‘\0’ to separate the flow even it is not necessary (there is no linefeed in the filenames so technically there is no need to use ‘\0’ as separator ).

Thank you for helping

You want -print0 and xargs -0 because the shell you are using to execute these commands uses spaces to separate command line arguments. If you give it a file name with one space, it is seen as two files.

Not necessary? For a robust solution you need this. If it is too much typing or you too easily forget things, make a alias that combines find -print0 and xargs -0 in one handy shortcut.

On the difference between 1 and 2, can you first explain why you want to use 2 if 1 is working? If it only is to educate yourself, it is likely better to find out yourself, do so you learn more.

I have tried tens of syntax to load at ounce kate with a list of files to edit.
The penultimate test was with ’ | xargs -d ‘\n’ kate’ and failed to load the files at ounce. Kate was showing the files one by one. Closing the current made the bext to show up.

The last with ‘| xargs -I{} kate {}’ seems to do what I want (loading all the files at ounce).

Concerning the spaces in the .desktop filename, what about the following :

ID -u is : 1000

$0 is : /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_ALL_SCRIPT_step_1_002.sh
$@ is :

PWD is : /home/user_install

ID is : uid=1000(user_install) gid=100(users) groups=100(users),464(vboxusers)


find /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT -type f ! -name “*~”

/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script.sh.keep.1
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_ALL_SCRIPT_step_1_002.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_script_upgrade_user_script.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/RUN UPGRADE USER SCRIPT.desktop
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/EDIT UPGRADE_USER SCRIPT.desktop
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script_session.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_ALL_SCRIPT_step_1_001.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/main_mandatory_machine_script.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/main_script_machine.sh
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/EDIT EDIT MAIN SCRIPT.desktop
/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/RUN MAIN SCRIPT.desktop



find /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT -type f ! -name “*~” | xargs -I{} ls -al {}

-rw-r–r-- 1 user_install users 3424 21 déc. 20:15 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script.sh.keep.1
-rwxr-xr-x 1 user_install users 2169 22 déc. 12:02 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_ALL_SCRIPT_step_1_002.sh
-rwxr-xr-x 1 user_install users 1086 15 déc. 12:19 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_script_upgrade_user_script.sh
-rwxr-xr-x 1 user_install users 604 16 déc. 20:15 ‘/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/RUN UPGRADE USER SCRIPT.desktop’
-rwxr-xr-x 1 user_install users 595 16 déc. 20:14 ‘/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/EDIT UPGRADE_USER SCRIPT.desktop’
-rw-r–r-- 1 user_install users 582 20 déc. 15:32 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script_session.sh
-rwxr-xr-x 1 user_install users 3775 7 déc. 22:00 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_ALL_SCRIPT_step_1_001.sh
-rwxr-xr-x 1 user_install users 2447 8 déc. 18:23 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/main_mandatory_machine_script.sh
-rwxr-xr-x 1 user_install users 3428 21 déc. 20:17 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/edit_edit_main_script.sh
-rwxr-xr-x 1 user_install users 23795 19 déc. 00:21 /run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/main_script_machine.sh
-rwxr-xr-x 1 user_install users 594 16 déc. 20:20 ‘/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/EDIT EDIT MAIN SCRIPT.desktop’
-rwxr-xr-x 1 user_install users 582 16 déc. 20:19 ‘/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/RUN MAIN SCRIPT.desktop’


There is no problem with files that contain spaces in their name.

Thank you for helping.

Okay, problem solved?

Note, you did quote my question but you did not answer it.

Not sure where you are trying to find the .desktop files but I do not expect them to be found where you are searching.

I show you the result. There are at least four .desktop files with space in file name with the expected output.

The problem is not solved.
If you are interesting look at : [Xargs -0 does not load all files at ounce to kate - Chapter 2]

Thank you for helping.

No thanks, one note, please spend some time thinking about the people your are communicating with. So if somebody asks something try to answer that and if you have output to share, please summarize it so that people do not have to search for information. That also helps you in the sense you get better responses.

In this case I overlooked the spaces in your previous message, that could have been prevented using:

-rwxr-xr-x 1 user_install users 582 16 déc. 20:19 ‘/run/media/user_install/INS_STEP2_MINI/NEW_INSTALL_LINUX_2023/2023_12_14_17h00/MY_PROJECTS/MY_INSTALL_STEP_1/2023_12_01_19h31/001_SCRIPTS/003_MAIN_SCRIPT/RUN MAIN SCRIPT.desktop’

Notice the name “RUN MAIN SCRIPT.desktop”

So you want to open Kate for every found file, that means you normally you have so start Kate separate for each file. If so, have a look at “man find”, second option under “ACTIONS”. There is also an EXAMPLE.

With command like xargs -0 -I {} kate {} you open each file in new instance of kate. Just use xargs -0 kate. Obviousle, after pipe)