Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File name too long to mv

1,114 views
Skip to first unread message

jond...@gmail.com

unread,
Jul 25, 2008, 3:19:40 PM7/25/08
to
When I try to rename a file with a really long file name, I get the
following error:

$ mv <really-long-file-name> <shorter-file-name>

mv: cannot stat `<really-long-file-name>': File name too long

What does this mean and how does one get around this problem?

steven_nospam at Yahoo! Canada

unread,
Jul 25, 2008, 3:43:01 PM7/25/08
to

There are two things I would suggest trying:

1) Use a wildcard for the long name. Example:
mv really-long-name* short-name

2) Change the name using the i-node value rather than the name.
Example:
ls -i # shows the filenames and i-node numbers
find . -inum {inode-number} -exec /bin/mv {} short-name \;

Not sure if the first method would work, but pretty sure that method
two should do the trick.

HTH,

Steve

Wayne

unread,
Jul 25, 2008, 10:10:43 PM7/25/08
to

I don't think either method will help. In the end they both
invoke the mv command with the too-long name as an argument.

Perhaps a different command won't have the same limit. Consider
using tar on the whole directory, then rm -rf the directory,
then edit the tar archive with vi and change the name inside to
a shorter one. Then restore from the tar archive.

If tar has the same problem, try other commands such as pax or
cpio. Or edit the file with vi and use ":w short-name", move
all the short named files elsewhere, and delete the directory.

If all else fails you can download the source to Gnu mv, increase
the buffer size and compile your own version that will work.
I suppose that given the inode number of the directory, you
can use a hex editor on your /dev/disk to change the name
in the appropriate disk block.

How did you manage to create such a file in the first place?

-Wayne

jond...@gmail.com

unread,
Jul 25, 2008, 10:26:01 PM7/25/08
to

They are music files. The current name is the default name from when I
copied the cds to my computer. Is there any simple, direct way to edit
the file name directly (preferably that can easily be incorporated
into a script)? I'm not very savvy about file system hacking.

mop2

unread,
Jul 25, 2008, 11:34:35 PM7/25/08
to

Try:
cp ... && rm ...

jond...@gmail.com

unread,
Jul 26, 2008, 12:32:44 AM7/26/08
to
On Jul 25, 11:34 pm, mop2 <inva...@mail.address> wrote:

> On Fri, 25 Jul 2008 16:19:40 -0300, <jonde...@gmail.com> wrote:
> > When I try to rename a file with a really long file name, I get the
> > following error:
>
> > $ mv <really-long-file-name> <shorter-file-name>
>
> > mv: cannot stat `<really-long-file-name>': File name too long
>
> > What does this mean and how does one get around this problem?
>
> Try:
> cp ... && rm ...

same error

Paul Colquhoun

unread,
Jul 26, 2008, 1:39:05 AM7/26/08
to


Is "really-long-file-name" really just the file name, or is it actually
"/really/long/full/path/to/file-name"?

If it is actually a path, try doing:

cd really/long/full/path/to
mv file-name shorter-name


It might help things if you gave us the actual name, or even the real
length of the name.

Run this and tell us the output:

echo really-long-file-name | wc


--
Reverend Paul Colquhoun, ULC. http://andor.dropbear.id.au/~paulcol
Asking for technical help in newsgroups? Read this first:
http://catb.org/~esr/faqs/smart-questions.html#intro

mik3...@gmail.com

unread,
Jul 26, 2008, 2:10:31 AM7/26/08
to

you might want to try mv in combination with xargs.

Dan Stromberg

unread,
Jul 26, 2008, 2:43:44 PM7/26/08
to

Please run:

strace -f mv long-name short-name 2>&1 | egrep E

..and send the result to this list. Or if you're on a System V system
rather than Linux, just substitute strace with truss.

The responses so far have focused on application-level messages. There's
a slim chance that this is a limit in the kernel/syscall being used.
strace/truss should help identify that. Granted, it'd have to be a
matter of one syscall producing a file that another syscall couldn't
handle, but I wouldn't rule it out entirely.

The suggestion to cd to the directory containing the file before trying
to do anything with it was a particularly good one - that should reduce
the length of the files that need to be passed in argv and syscalls.

jond...@gmail.com

unread,
Jul 26, 2008, 4:27:15 PM7/26/08
to

Here's the output, with some anonymization (FYI, I'm using cygwin):

946 1781 [main] mv 6168 environ_init: GetEnvironmentStrings
returned 0x245D58 - "=::=::\"
89 2049 [main] mv 6168 environ_init: 0x780260: ALLUSERSPROFILE=C:
\Documents and Settings\All Users
71 2199 [main] mv 6168 environ_init: 0x7802E8: APR_ICONV_PATH=C:
\Program Files\Subversion\iconv
85 2374 [main] mv 6168 environ_init: 0x780368:
CLIENTNAME=Console
73 2447 [main] mv 6168 environ_init: 0x780380:
COMMONPROGRAMFILES=C:\Program Files\Common Files
72 2519 [main] mv 6168 environ_init: 0x7803B8:
COMPUTERNAME=compname
70 2589 [main] mv 6168 environ_init: 0x7803D8: COMSPEC=C:\WINDOWS
\system32\cmd.exe
76 2998 [main] mv 6168 environ_init: 0x780450:
FP_NO_HOST_CHECK=NO
78 3076 [main] mv 6168 getwinenv: can't set native for HOME=
since no environ yet
52 3493 [main] mv 6168 win_env::add_cache: native HOME=C:
\SyncDir
49 3542 [main] mv 6168 posify: env var converted to HOME=/
cygdrive/c/SyncDir
87 3629 [main] mv 6168 environ_init: 0x780480: HOME=/cygdrive/c/
SyncDir
89 3718 [main] mv 6168 environ_init: 0x780468: HOMEDRIVE=C:
84 3802 [main] mv 6168 environ_init: 0x7805C0: HOMEPATH=
\Documents and Settings\xxx xxx
84 3886 [main] mv 6168 environ_init: 0x780600: HOSTNAME=compname
91 4478 [main] mv 6168 environ_init: 0x780658: LOGONSERVER=\
\compname
84 4562 [main] mv 6168 environ_init: 0x780678: MAKE_MODE=unix
96 4759 [main] mv 6168 environ_init: 0x7806D8:
NUMBER_OF_PROCESSORS=2
160 11204 [main] mv 6168 environ_init: 0x780790:
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
87 11380 [main] mv 6168 environ_init: 0x780800: PRINTER=HP
Deskjet D1400 series
96 11476 [main] mv 6168 environ_init: 0x780828:
PROCESSOR_ARCHITECTURE=x86
90 11566 [main] mv 6168 environ_init: 0x780848:
PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 3, GenuineIntel
90 11656 [main] mv 6168 environ_init: 0x780890:
PROCESSOR_LEVEL=15
88 11744 [main] mv 6168 environ_init: 0x7808A8:
PROCESSOR_REVISION=0403
88 11832 [main] mv 6168 environ_init: 0x7808C8: PROGRAMFILES=C:
\Program Files
99 12220 [main] mv 6168 environ_init: 0x781710: QMAKESPEC=/usr/
lib/qt3/mkspecs/cygwin-g++
94 12517 [main] mv 6168 environ_init: 0x781798:
SESSIONNAME=Console
85 12694 [main] mv 6168 environ_init: 0x7817C0: SONICCENTRAL=C:
\Program Files\Common Files\Sonic Shared\Sonic Central\
91 12785 [main] mv 6168 environ_init: 0x781810: SYSTEMDRIVE=C:
81 12866 [main] mv 6168 environ_init: 0x781828: SYSTEMROOT=C:
\WINDOWS
85 12951 [main] mv 6168 getwinenv: can't set native for TEMP=
since no environ yet
96 13047 [main] mv 6168 mount_info::conv_to_posix_path:
conv_to_posix_path (C:\DOCUME~1\xxx~1\LOCALS~1\Temp, no-keep-rel, no-
add-slash)
152 13199 [main] mv 6168 normalize_win32_path: C:
\DOCUME~1\xxx~1\LOCALS~1\Temp = normalize_win32_path (C:
\DOCUME~1\xxx~1\LOCALS~1\Temp)
53 13252 [main] mv 6168 mount_info::conv_to_posix_path: /cygdrive/
c/DOCUME~1/xxx~1/LOCALS~1/Temp = conv_to_posix_path (C:
\DOCUME~1\xxx~1\LOCALS~1\Temp)
126 13378 [main] mv 6168 win_env::add_cache: posix /cygdrive/c/
DOCUME~1/xxx~1/LOCALS~1/Temp
47 13425 [main] mv 6168 win_env::add_cache: native TEMP=C:
\DOCUME~1\xxx~1\LOCALS~1\Temp
49 13474 [main] mv 6168 posify: env var converted to TEMP=/
cygdrive/c/DOCUME~1/xxx~1/LOCALS~1/Temp
92 13566 [main] mv 6168 environ_init: 0x781878: TEMP=/cygdrive/c/
DOCUME~1/xxx~1/LOCALS~1/Temp
80 13646 [main] mv 6168 environ_init: 0x781848: TERM=cygwin
72 13718 [main] mv 6168 environ_init: 0x781858:
TEXDOCVIEW_DVI=cygstart %s
71 13789 [main] mv 6168 environ_init: 0x7819E8:
TEXDOCVIEW_HTML=cygstart %s
71 13860 [main] mv 6168 environ_init: 0x781A08:
TEXDOCVIEW_PDF=cygstart %s
72 13932 [main] mv 6168 environ_init: 0x781A28:
TEXDOCVIEW_PS=cygstart %s
93 14025 [main] mv 6168 environ_init: 0x781A48:
TEXDOCVIEW_TXT=cygstart %s
70 14167 [main] mv 6168 mount_info::conv_to_posix_path:
conv_to_posix_path (C:\DOCUME~1\xxx~1\LOCALS~1\Temp, no-keep-rel, no-
add-slash)
40 14207 [main] mv 6168 normalize_win32_path: C:
\DOCUME~1\xxx~1\LOCALS~1\Temp = normalize_win32_path (C:
\DOCUME~1\xxx~1\LOCALS~1\Temp)
40 14247 [main] mv 6168 mount_info::conv_to_posix_path: /cygdrive/
c/DOCUME~1/xxx~1/LOCALS~1/Temp = conv_to_posix_path (C:
\DOCUME~1\xxx~1\LOCALS~1\Temp)
105 14352 [main] mv 6168 win_env::add_cache: posix /cygdrive/c/
DOCUME~1/xxx~1/LOCALS~1/Temp
38 14390 [main] mv 6168 win_env::add_cache: native TMP=C:
\DOCUME~1\xxx~1\LOCALS~1\Temp
39 14429 [main] mv 6168 posify: env var converted to TMP=/
cygdrive/c/DOCUME~1/xxx~1/LOCALS~1/Temp
71 14500 [main] mv 6168 environ_init: 0x781A98: TMP=/cygdrive/c/
DOCUME~1/xxx~1/LOCALS~1/Temp
71 14571 [main] mv 6168 environ_init: 0x781A68: USER=xxxxxxxx
74 14645 [main] mv 6168 environ_init: 0x781C08:
USERDOMAIN=compname
71 14716 [main] mv 6168 environ_init: 0x781A80: USERNAME=xxxxxxxx
71 14787 [main] mv 6168 environ_init: 0x781C28: USERPROFILE=C:
\Documents and Settings\xxx xxx
40 18937 [main] mv 6168 symlink_info::check: 0 = symlink.check (C:
\cygwin\etc\group, 0x22C5E0) (0xA)
50 20098 [main] mv 6168 cygheap_user::ontherange: HOME is already
in the environment /cygdrive/c/SyncDir
156 20582 [main] mv 6168 tty_list::allocate: console 9A07E0
already associated with tty0
57 20639 [main] mv 6168 tty_list::allocate: console 0x9A07E0
associated with tty0
61 21944 [main] mv 6168 normalize_posix_path: ENAMETOOLONG =
normalize_posix_path (p3)
44 23881 [main] mv 6168 fhandler_base::set_flags: O_TEXT/O_BINARY
set in flags 0x10000
150 24109 [main] mv 6168 handle_to_fn: nt name '\Device\NamedPipe
\cygwin-0xA54-0xE'
55 24914 [main] mv 6168 handle_to_fn: derived path '\Device
\NamedPipe\cygwin-0xA54-0xE', posix '/Device/NamedPipe/
cygwin-0xA54-0xEa54.00000002'
50 25073 [main] mv 6168 fhandler_base::set_flags: O_TEXT/O_BINARY
set in flags 0x10000
193 25397 [main] mv 6168 handle_to_fn: nt name '\Device\NamedPipe
\cygwin-0xA54-0xE'
63 26515 [main] mv 6168 handle_to_fn: derived path '\Device
\NamedPipe\cygwin-0xA54-0xE', posix '/Device/NamedPipe/
cygwin-0xA54-0xEa54.00000002'
62 26577 [main] mv 6168 build_fh_pc: fh 0x61169E20
72 26701 [main] mv 6168 fhandler_base::set_flags: O_TEXT/O_BINARY
set in flags 0x10000
55 28072 [main] mv 6168 normalize_posix_path: ENAMETOOLONG =
normalize_posix_path (p3)
62 31021 [main] mv 6168 normalize_posix_path: ENAMETOOLONG =
normalize_posix_path (p3)
57 31403 [main] mv 6168 normalize_posix_path: ENAMETOOLONG =
normalize_posix_path (p3)
47 40786 [main] mv 6168 fhandler_base::close: closing '/Device/
NamedPipe/cygwin-0xA54-0xEa54.00000002' handle 0x638
70 41390 [main] mv 6168 fhandler_base::close: closing '/Device/
NamedPipe/cygwin-0xA54-0xEa54.00000002' handle 0x610
5 42112 [sig] mv 6168 wait_sig: saw __SIGEXIT
52 42805 [main] mv 6168 __to_clock_t: total 00000000 0000003E
1707 44609 [main] mv 6168 pinfo::exit: Calling ExitProcess n 0x100,
exitcode 0x1

jond...@gmail.com

unread,
Jul 26, 2008, 5:18:15 PM7/26/08
to
On Jul 26, 1:39 am, Paul Colquhoun <postmas...@andor.dropbear.id.au>
wrote:

most of the files are still too long even inside the same directory.
they contain around 130 characters or more.

Wayne

unread,
Jul 26, 2008, 6:59:14 PM7/26/08
to

If this is true it looks like a cygwin bug. POSIX minimums are 255 characters.
Then again, maybe that's bytes; I know some OSes use UTF-16 so 130 characters
would be 260 bytes.

If I were you I'd report the exact filename (and its length) and the bug
to the cygwin mailing list.

-Wayne

jond...@gmail.com

unread,
Jul 26, 2008, 11:38:46 PM7/26/08
to
So I tried all of the ideas mentioned above except directly editing
the file name on the disk, which I don't know how to do. For some
reason, editing it with vi or emacs creates a new file. Using tar, cp,
etc. each causes the same long file name problem.

Any other ideas? I really don't want to manually go through all the
file names in Windows to change them, both because that's a pain, and
because it seems like a crude and clumsy solution.

jond...@gmail.com

unread,
Jul 27, 2008, 12:05:36 AM7/27/08
to

so is there a way to edit a file name directly (sort of as per one of
Wayne's suggestions above)? my naive understanding is that this would
require editing the directory file, though I'm a little hazy on where
exactly the file name is stored.

Mark Hobley

unread,
Jul 27, 2008, 6:42:47 AM7/27/08
to
jond...@gmail.com wrote:

> Any other ideas? I really don't want to manually go through all the
> file names in Windows to change them, both because that's a pain, and
> because it seems like a crude and clumsy solution.

There is a 260 pathname length limit for filenames within Microsoft
Windows. The problem that you are encountering is probably because the
absolute pathname for your files exceeds this limit.

Make a single letter folder in the root directory of your
Microsoft Windows folder, and move all of your music files to that
folder (Using Microsoft Windows Explorer.)

Now hopefully, you can open the files in cygwin. (Watch out also for
files with apostrophes and things in the filenames. You might need to
rename these, but hopefully you will spot such names in the Explorer
Window.)

There might be a free mass renaming tool for Microsoft Windows which can
help you reduce the lengths of your filenames. It has been a while since
I last looked at such tools, so I have no specific recommendations at
this time.

Regards,

Mark.

--
Mark Hobley,
393 Quinton Road West,
Quinton, BIRMINGHAM.
B32 1QE.

Allodoxaphobia

unread,
Jul 27, 2008, 11:46:10 AM7/27/08
to

Could you boot a Live CD and `mv` it from there?

Jonesy
--
Marvin L Jones | jonz | W3DHJ | linux
38.24N 104.55W | @ config.com | Jonesy | OS/2
*** Killfiling google posts: <http://jonz.net/ng.htm>

Harry331

unread,
Jul 27, 2008, 1:04:56 PM7/27/08
to
jond...@gmail.com wrote...

Assume your music files are here.

C:\Documents and Settings\Mason\My Documents\My Music\blablabla.mp3

The goal is to shorten the path
"C:\Documents and Settings\Mason\My Documents\My Music\"

Net share mymysic="C:\Documents and Settings\Mason\My Documents\My Music"

Net use M:=\\IP_of_PC\mymusic

If everything go well, you now have
M:\blablabla.mp3

Now, rename your music file
copy M:\blablabla.mp3 c:\shortname.mp3

Hope this helps.

jonderry

unread,
Jul 27, 2008, 7:12:34 PM7/27/08
to
On Jul 27, 1:04 pm, harryooopot...@hotmail.co_ (Harry331) wrote:
> jonde...@gmail.com wrote...

BTW, if you have windows and cygwin, you can recreate the problem I'm
having by creating a new text file in windows, typing "aaaaabbbbb
cccccddddd" into the file's name, and then copy-pasting it so there
are 7 copies (if you run wc on the file name, it should take up 148
bytes for a 147 character file name). If you find a way to fix the
file name from inside cygwin (hopefully a scriptable way), I'd love to
hear it. I've scoured the web for solutions to no avail.

jonderry

unread,
Jul 27, 2008, 7:20:08 PM7/27/08
to

If you put it in a root directory you may have to copy-paste a couple
more times to make the file name too long again. If I max out the file
name length to 256 bytes it doesn't work anywhere. Actually my
original problem is solved by moving the files, but only because I was
"lucky" enough that they were all under 250 bytes. Still interested if
anyone knows how to solve the 256 byte file name case, though less
urgently.

Harry331

unread,
Jul 27, 2008, 9:01:04 PM7/27/08
to
jonderry wrote...


>If you put it in a root directory you may have to copy-paste a couple
>more times to make the file name too long again. If I max out the file
>name length to 256 bytes it doesn't work anywhere. Actually my
>original problem is solved by moving the files, but only because I was
>"lucky" enough that they were all under 250 bytes. Still interested if
>anyone knows how to solve the 256 byte file name case, though less
>urgently.

Google "Windows max filename length" points to here.

http://en.wikipedia.org/wiki/Filename

<quite>
Microsoft Windows: Windows kernel forbids the use of characters
in range 1-31 (i.e., 0x01-0x1F) and characters " * : < > ? \ |.
Although NTFS allows each path component (directory or filename)
to be 255 characters long and paths up to about 32767 characters
long, the Windows kernel only supports paths up to 259 characters
long.
</quote>

Why are you interested in solving an invalid filename length of
256 byte ? You are going nowhere. Forget about it.

0 new messages