Help!! Filenames with blanks in them

Technical issues/questions of an intermediate or advanced nature.
User avatar
Ed_P
Contributor
Contributor
Posts: 3207
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Help!! Filenames with blanks in them

Post#1 by Ed_P » 06 Apr 2016, 21:12

When I boot I am getting "cp cannot stat" error msgs. The reason is deleted files with blanks/spaces in their names. I know how to remove normal .wh. files:

Code: Select all

find /mnt/live/memory/images/changes/home -name ".wh.*" | xargs rm
but I need a tweak to handle the names with blanks. Something that would replace the " " with a "?". Would grep work?

Some of the error msgs:

Code: Select all

rm: cannot remove ‘/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session’: No such file or directory
rm: cannot remove ‘Storage/.wh.000004.log’: No such file or directory
rm: cannot remove ‘/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session’: No such file or directory
rm: cannot remove ‘Storage/.wh.000003.log’: No such file or directory
Some of the files:

Code: Select all

/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000004.log
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000003.log

-edit-

No longer solved. New discussion added.
Last edited by Ed_P on 16 Apr 2016, 23:32, edited 2 times in total.
Ed

User avatar
Ed_P
Contributor
Contributor
Posts: 3207
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Help!! Names with blanks in them

Post#2 by Ed_P » 06 Apr 2016, 22:04

I tried using sed but the files still wouldn't delete. :(

Code: Select all

    find /mnt/live/memory/images/changes/home -name ".wh.*" | sed 's" "?"' |  xargs rm

Code: Select all

rm: cannot remove ‘/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session?Storage/.wh.000004.log’: No such file or directory
rm: cannot remove ‘/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session?Storage/.wh.000003.log’: No such file or directory
And yes, the files are still there.

Code: Select all

/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000004.log
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000003.log
When I manually remove them I use the "?" and it works.

Code: Select all

guest@porteus:~$ rm /mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session?Storage/.wh.000003.log
rm: remove write-protected regular empty file ‘/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000003.log’? y
guest@porteus:~$ su
Password: 
root@porteus:/home/guest# rm /mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session?Storage/.wh.000004.log
root@porteus:/home/guest# 

Code: Select all

find /mnt/live/memory/images/changes -name .wh.*
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000017.log
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000006.ldb
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000007.log
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Session Storage/.wh.000003.ldb
/mnt/live/memory/images/changes/usr/lib64/.wh.libapm.so.1
Strange.

:pardon:
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Help!! Names with blanks in them

Post#3 by Bogomips » 06 Apr 2016, 22:42

^ How about trying?

Code: Select all

find /mnt/live/memory/images/changes/home -name ".wh.*"  -delete
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Ed_P
Contributor
Contributor
Posts: 3207
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Help!! Names with blanks in them

Post#4 by Ed_P » 07 Apr 2016, 00:08

^ Wow!! :shock:

Showing promise so far.

Code: Select all

guest@porteus:~$ find /mnt/live/memory/images/changes/home -name ".wh.*"  
/mnt/live/memory/images/changes/home/guest/Backups/FireFox/.wh.bookmarks-2016-03-13.json
/mnt/live/memory/images/changes/home/guest/.cache/mozilla/firefox/c3pp43bg.default/safebrowsing/.wh..wh..opq
/mnt/live/memory/images/changes/home/guest/.config/google-chrome/Default/Extensions/bpphkkgodbfncbcpgopijlfakfgmclao/.wh.42.5.15_0
/mnt/live/memory/images/changes/home/guest/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys/.wh..wh..opq
/mnt/live/memory/images/changes/home/guest/.wh.rc.local_shutdown
/mnt/live/memory/images/changes/home/guest/.wh.google-chrome.desktop
/mnt/live/memory/images/changes/home/guest/.wh.browser.desktop
guest@porteus:~$ find /mnt/live/memory/images/changes/home -name ".wh.*"  -delete
guest@porteus:~$ find /mnt/live/memory/images/changes/home -name ".wh.*"
:Yahoo!:

Have to see later after Chrome has been used.
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Help!! Names with blanks in them

Post#5 by Bogomips » 10 Apr 2016, 11:12

@ Ed_P
If no longer outstanding, please mark thread as solved. :wink:
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them [Solved]

Post#6 by Rava » 16 Apr 2016, 06:57

Wow, that "-delete" option was new to me as well...

There are so many tutorial posts and articles about find, using the | xargs rm or such variant that I never looked for a simple find option. *facedesksjshsgduasdf*
Cheers!
Yours Rava

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Help!! Filenames with blanks in them [Solved]

Post#7 by Bogomips » 16 Apr 2016, 15:21

Corollary
If there is a filename with blank or other unusual character, and the file cannot really be deleted, then all that has to be done is to find it! ;)

Code: Select all

guest@porteus:~$ find Junk -regex '.* .*'
Junk/Oranges S01E01  Parte 1 (legendado em portugu??s).pt.srt
Junk/Apples S01E01  Parte 1 (legendado em portugu??s).mp4
Junk/Apples  Ep. 02 pt.1 (com legenda em portugu??s).pt.srt

guest@porteus:~$ find Junk -regex '.* .*Ep.*'
Junk/Apples  Ep. 02 pt.1 (com legenda em portugu??s).pt.srt
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them [Solved]

Post#8 by Rava » 16 Apr 2016, 17:36

Since I digressed at times, I tried again and boiled it down to the basics. So I deleted this post, it was too off topic.

Please see post viewtopic.php?f=140&t=5698#p44237 :D
Cheers!
Yours Rava

User avatar
brokenman
Site Admin
Site Admin
Posts: 5503
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v3.2rcX all desktops
Location: Brazil
Contact:

Re: Help!! Filenames with blanks in them [Solved]

Post#9 by brokenman » 16 Apr 2016, 22:12

Yeah, I would cut out you digression bit. It is long enough as it is.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them [Solved]

Post#10 by Rava » 16 Apr 2016, 22:37

brokenman wrote:Yeah, I would cut out you digression bit. It is long enough as it is.
Just did so. :D

Anyhow, by any chance, you know of any trick that might meld me with my * plus whitespace script issue?
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 3207
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

Re: Help!! Filenames with blanks in them [Solved]

Post#11 by Ed_P » 16 Apr 2016, 23:31

Rava does "?" instead of "*" work for you? While "*" supports any number of characters I believe "?" supports a single character.
Ed

Bogomips
Full of knowledge
Full of knowledge
Posts: 2560
Joined: 25 Jun 2014, 15:21
Distribution: 3.2.2 Cinnamon & KDE5
Location: London

Re: Help!! Filenames with blanks in them

Post#12 by Bogomips » 16 Apr 2016, 23:42

Between digression and ingression got completely lost. Couldn't see the wood for the trees. Still can't. :%)
Linux porteus 4.4.0-porteus #3 SMP PREEMPT Sat Jan 23 07:01:55 UTC 2016 i686 AMD Sempron(tm) 140 Processor AuthenticAMD GNU/Linux
NVIDIA Corporation C61 [GeForce 6150SE nForce 430] (rev a2) MemTotal: 901760 kB MemFree: 66752 kB

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them

Post#13 by Rava » 16 Apr 2016, 23:56

Bogomips wrote:Between digression and ingression got completely lost. Couldn't see the wood for the trees. Still can't. :%)
Sorry, it's complex, and seems I not realized what I could have been left out... I try again, hopefully this time I manage better. (I also removed quite some unneeded text in my above post)


You can boil it down to this:

I want to call mc (via a script) with 2 paths. So that mc opens these "target path" in its left and right working panel, one is the source directory for backup copy, the other the target. The target directory in /tmp varies since I give it a name including version and date so that I can have several versions next to each other.


Both have whitespace. One also has a wildcard. (The one in /tmp)

The path with only whitespace you can enclose in " ". (In my example, the one in /home/rava, but could be anywhere with a needed path with whitespace)

The other one, you cannot use " " to protect the whitespaces, or else the wildcard * won't expand.

Code: Select all

# file /tmp/999-local-settings-3.1.*/home/rava/.moonchild\ productions/pale\ moon
That's an how it works fine in bash itself, but not in a bash script. When you created a matching folder, e.g.

Code: Select all

# mkdir -p "/tmp/999-local-settings-3.1.0_2016-04-17/home/rava/.moonchild productions/pale moon"
the above would match, like I demonstrated with bash in my above post.


But when you try the same in a bash script, it fails. You get an "file or folder not found", or such error.

Like I said above, using " " won't work, since the * won't expand.
Using "\ " (minus the " ) also not works, the bash script complains about "path not found", even when the same works fine in bash itself....


That's boiled down to the basics. Well, at least I found a 2 part work around as quoted above, but I would prefer a solution in being able to give such wildcard and whitespace folder or filename and the script is able to expand the wildcard(s) while still respecting the whitespaces.
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them

Post#14 by Rava » 17 Apr 2016, 00:34

Simple questio. what happens with

Code: Select all

w="/home/rava/.moonchild productions/pale moon"
mkdir -p /tmp/999-local-settings-3.1.*$w
Me thinks it would create a folder containing the character "*" and thus creating problems for quite some scripts... But a filename or folder with a * in it is per se not invalid, just difficult.

Code: Select all

rava@porteus:/$ mkdir -p /tmp/999-local-settings-3.1.*
rava@porteus:/$ l /tmp/999-local-settings-3.1.\*/
total 0
drwxr-xr-x  2 rava  40 2016-04-17 02:31 .
drwxrwxrwt 18 root 540 2016-04-17 02:31 ..
rava@porteus:/$ file /tmp/999-local-settings-3.1.\*/
/tmp/999-local-settings-3.1.*/: directory 
See? Valid path.


But it's not about creating the folder, it's about finding it.


The existing base folder can vary, e.g.

/tmp/999-local-settings-3.1.0_2016-04-05
/tmp/999-local-settings-3.1.0_2016-04-10
/tmp/999-local-settings-3.2rc1_2016-04-25

etcetera.

And the rest of the folder would then always be the same, like so:

/tmp/999-local-settings-3.1.0_2016-04-05/home/rava/.moonchild productions/pale moon
/tmp/999-local-settings-3.1.0_2016-04-10/home/rava/.moonchild productions/pale moon
/tmp/999-local-settings-3.2rc1_2016-04-25/home/rava/.moonchild productions/pale moon


Only ONE of these base folders are meant to exist at a time, since usually you do only run one Porteus at a time. At least that's how it is planned to be intended to be used for now. And the "date" part of the name is meant to reflect the current date.


Now the issue is, how can I address such folder, needing a wildcard * at one part to match the variants, but also needs to address the whitespaces that follow?


Like I wrote in my initial post, the only work around the * AND whitespace in one folder name issue is by doing this trick:

Code: Select all

cd $path1    # no masking so that * is expanded, CAVE! This part of the path given *must* *not* have whitespaces (it can expand, via the * to include whitespaces, but not in front or after the *)
cd "./${path2}"        # masking for whitespace
. /usr/share/mc/bin/mc-wrapper.sh . "$path2"  # masking for whitespace
I use two instances of cd to change into the wanted target folder, and then just use "." to start one panel of mc in that very folder and "$path2" for the other panel.

$path2 is the path with only whitespace, but without the need or a wildcard *
Cheers!
Yours Rava

User avatar
Rava
Contributor
Contributor
Posts: 1319
Joined: 11 Jan 2011, 02:46
Distribution: Porteus 3.1.0 x86-64 XFCe
Location: Germany

Re: Help!! Filenames with blanks in them

Post#15 by Rava » 17 Apr 2016, 11:26

All kudos go to donald, he found the solution by making as script and not using a variable as I did but using the path directely in it, like so:

Code: Select all

    #!/bin/bash
    /usr/libexec/mc/mc-wrapper.sh /tmp/999-local-settings-3.1.*/home/rava/.moonchild\ productions/pale\ moon/  /home/rava/.moonchild\ productions/pale\ moon/ 
Works like a charm.

And now, when I ponder about it I do get it why using a variable was the issue, cause doing so gives you the need to protect the whitespaces. Using no variable: no such need. AT least not in the very same way, when including the need of expanding the wildcard.

And again the behaviour of bash and of a bash script is the same.


All is well.
Like Dutch from Black lagoon used to say "Hallelujah and Peanut Butter!"

Black Lagoon, the anime for folks who not care or even dislike anime.

Also an anime for folks who usually dislike brutal stuff, but many of these still enjoy Black Lagoon cause it is just that good of a show.</digress>

Hmmm why not open up a thread where we can chat about which media / series / manga / fanfiction we like, and why?
Anyone interested?
Cheers!
Yours Rava

Post Reply