Freebsd how to escape the directory: "-- Video"

Status
Not open for further replies.

esamett

Patron
Joined
May 28, 2011
Messages
345
I have read several tutorials for Linux and FreeBSD for dealing with spaces in Windows file/directory names, such as:
http://www.cyberciti.biz/faq/rsync-transfer-filename-that-contains-whitespace/

I got stumped trying to use CLI shell to access:
/mnt/tank1/video-server/-- Video
As exampled below FreeBSD either thinks I am trying to issue a "--" <flag>, or adds the single or double quote to the directory path:

Code:
hell
ls: illegal option -- -
usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format] [file ...]
[root@freenas /mnt/tank1/video-server]# ls \-\-\ Video
ls: illegal option -- -
usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format] [file ...]
[root@freenas /mnt/tank1/video-server]# ls '\-\-\ Video'
ls: \-\-\ Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls '\\ Video'
ls: \\ Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls '-- Video'
ls: illegal option -- -
usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format] [file ...]
[root@freenas /mnt/tank1/video-server]# ls '"--" Video'
ls: "--" Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls "'--' Video"
ls: '--' Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls '\-\-\ Video'
ls: \-\-\ Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls '\-- Video'
ls: \-- Video: No such file or directory
[root@freenas /mnt/tank1/video-server]# ls '-- 'Video
ls: illegal option -- -
usage: ls [-ABCFGHILPRSTUWZabcdfghiklmnopqrstuwxy1,] [-D format] [file ...]
[root@freenas /mnt/tank1/video-server]#


The reason I need to do this is that I copied a subdirectory with Windows Explorer, and now I cannot delete it:
An unexpected error is keeping you from deleting the file. If you continue to receive this error, you can use the error code to search for help with this problem.

error 0xF1020004: No error description available

I thought of using the FreeNAS command line to fix my problem.

Advice appreciated,
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
I have an idea.

Use the back quote thing. If you wanted to delete the file "-- crap", couldn't you just do this, with the back quote:

rm `echo -- crap`

since echo won't get confused on the hyphens?

Just an idea.
 

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Actually I was thinking more like:

# rm `-- Video`

Note that this is NOT the single quote symbol.
 

esamett

Patron
Joined
May 28, 2011
Messages
345
will let you know!

so `echo --crap` sends "--crap" to "rm"?
what is "`" used for?

thanks,

e
 

esamett

Patron
Joined
May 28, 2011
Messages
345
Sorry, neither worked for me:

Code:
[root@freenas /mnt/tank1/video-server]# cd `-- Video`
bash: --: command not found
[root@freenas ~]# cd `echo --Video`
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
[root@freenas ~]#
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
Got it.

Code:
cd "`echo --` `echo Video`"


Note the use of double quote, and single reverse quote.
 

esamett

Patron
Joined
May 28, 2011
Messages
345
I googled my Windows error and got something related to SMB and Windows 2000:
http://support.microsoft.com/kb/311563

I did a copy/paste of your suggestion directly into FreeNAS shell:
Code:
[root@freenas /mnt/tank1/video-server]# cd "`echo --` `echo Video`"
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
[root@freenas /mnt/tank1/video-server]#
 

DrKK

FreeNAS Generalissimo
Joined
Oct 15, 2013
Messages
3,630
I googled my Windows error and got something related to SMB and Windows 2000:
http://support.microsoft.com/kb/311563

I did a copy/paste of your suggestion directly into FreeNAS shell:
Code:
[root@freenas /mnt/tank1/video-server]# cd "`echo --` `echo Video`"
bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
[root@freenas /mnt/tank1/video-server]#
Here's your problem.

You can't do this in bash.

Type "csh" and switch to cshell.
 

willnx

Dabbler
Joined
Aug 11, 2013
Messages
49
You could delete the file via inode when the name is problematic.

To get the inode, run this while in the directory where the file lives:
# ls -li​

The inode will be the 1st column.
Once you have the inode, you can do this: (make sure you're in the directory which has the file)
# find . -inum INODE -exec rm -i {} \;​
 
Last edited:

cyberjock

Inactive Account
Joined
Mar 25, 2012
Messages
19,526
Now that is truly awesome. From someone with only 17 posts too! Good work willnx!
 

esamett

Patron
Joined
May 28, 2011
Messages
345
NOOB: I got into the directory I need. Still stuck. Can't use rm properly and the find command doesn't like directories:

Code:
rm: ./-=- Adventure: is a directory
[root@freenas] /mnt/tank1/video-server/-- Video/-- New and High Quality Video/-
Anime-Manga/-=- copy# ls
-=- Adventure/ -=- Hentai/ ./ -=- Ecchi-harem/ -=- RomCom/ ../
[root@freenas] /mnt/tank1/video-server/-- Video/-- New and High Quality Video/-
Anime-Manga/-=- copy# ls -li
total 214
233941 dr-xr-xr-x+ 7 guest guest 7 Sep 14 16:36 -=- Adventure/
242026 dr-xr-xr-x+ 15 guest guest 15 Sep 14 17:52 -=- Ecchi-harem/
298772 dr-xr-xr-x+ 2 guest guest 2 Jul 13 22:30 -=- Hentai/
228316 dr-xr-xr-x+ 4 guest guest 4 Sep 14 16:13 -=- RomCom/
228313 dr-xr-xr-x+ 6 guest guest 6 Sep 14 17:56 ./
483710 dr-xr-xr-x+ 79 guest guest 80 Sep 14 16:05 ../
[root@freenas] /mnt/tank1/video-server/-- Video/-- New and High Quality Video/-
Anime-Manga/-=- copy# find . -inum 233941 -exec rm -i {} \;
rm: ./-=- Adventure: is a directory
[root@freenas] /mnt/tank1/video-server/-- Video/-- New and High Quality Video/-
Anime-Manga/-=- copy# rm "`echo --` `echo Video`"
rm: illegal option -- -
usage: rm [-f | -i] [-dIPRrvW] file ...
unlink file
[root@freenas] /mnt/tank1/video-server/-- Video/-- New and High Quality Video/-
Anime-Manga/-=- copy#

 

willnx

Dabbler
Joined
Aug 11, 2013
Messages
49
Aww crap, that's what I get for only 1/2 reading the thread...

So I did a test run, and while I saw an error, it looks like the directory is gone.
I'm not 100% how FreeNAS addresses leaking blocks (or more specifically, if it does or if it's more cleaver than that) so I can't guarantee that the space consumed will be reclaimed right away.

My results:
via my windows box, I made a test directory, and a folder with the same name as yours
# pwd
/mnt/vol/Redmond/test

# ls -li
total 50
401 drwxrwxr-x+ 3 burnin wheel 3 Sep 15 19:56 -- Video/
394 drwxrwxr-x+ 3 burnin wheel 3 Sep 15 19:55 ./
9 drwxrwxr-x+ 6 wkstn8 wheel 6 Sep 15 19:50 ../


# find . inum 401 -exec rm -rf {} \; <-- Note the -rf instead of -I ; -rf is how you remove a directory *use with caution*
rm: "." and ".." may not be removed
find: ./-- Video: No such file or directory
find: inum: No such file or directory
find: 401: No such file or directory


# ls -li
total 33
394 drwxrwxr-x+ 2 burnin wheel 2 Sep 15 19:56 ./
9 drwxrwxr-x+ 6 wkstn8 wheel 6 Sep 15 19:50 ../


Let us know if you can still see the directory afterwards
 

ewhac

Contributor
Joined
Aug 20, 2013
Messages
177
This is an elaborate joke, right?

*sigh*

There's several issues tripping you up.

First: Switch to 'bash' or some other Bourne-shell derivative. 'csh' will cause you serious injury. ( http://www-uxsup.csx.cam.ac.uk/misc/csh.html )

Second: One of the problems you're experiencing is due to the shell trying to break up arguments on spaces. If the filenames themselves have spaces, then the shell will break them up. So instead of passing a single filename argument called "Local Documents" to the program, the shell will instead break it up into two arguments, "Local" and "Documents".

So we have to make the shell leave the spaces alone. In Bash, that can be done a couple ways. One is to surround the argument in quotes:

ls "Local Documents"

...or...

ls 'Local Documents'

(Do not use backquotes; they mean something entirely different.)

Another is to escape the space(s) using the backslash character. This tells the shell, "Don't do what you would normally do with the following character; just pass it along literally."

ls Local\ Documents

So, in your case, you could say:

cd "-- Video"

But, surprise! this doesn't work:

-bash: cd: --: invalid option

This is because you're now tripping over the argument parsing inside 'cd' itself. It (and nearly every other console command on the planet) assumes that any argument that begins with a '-' is a command option (like the 'a' in: ls -a). It doesn't recognize '--', so it dies.

Solution: Make the first character in the argument not a '-', like so:

cd './-- Video'

Your other other problem is that, by tradition, 'rm' treats directories specially, and will not normally delete them. Rather, you must use 'rmdir' to delete directories. But guess what: 'rmdir' will refuse to delete a directory if it's not empty. You must first delete all the files inside before you can delete the directory. And if there's a non-empty directory inside, then you have to first delete all the files inside that, etc., etc., turtles all the way down.

So what people generally do is use the '-r' (recursive) option to 'rm', which deletes files and directories recursively:

rm -r './-- Video'

This deletes the directory "-- Video" and everything inside it (so be careful).

Summary: By creating a bunch of filenames with spaces and leading dashes, you'll be stress-testing a lot of argument parsers out there.
 

esamett

Patron
Joined
May 28, 2011
Messages
345
rebooted everything. working now...Thank you all!!
 
Status
Not open for further replies.
Top