Understanding the Error
File name too long
Invalid argument
Linux limits filename length to 255 bytes.
Find Too-Long Filenames
# Find files with names > 200 chars
find /path -type f -name "????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????" -ls
# Or with perl
find /path -type f -exec perl -e '$l=length($_); if($l>200){print"$l: $_\n"}' {} \;
Fix 1: Rename Long Files
# Using inode number
ls -li
find . -inum INODE -exec mv {} newname \;
Fix 2: Bulk Rename
# Truncate to 100 chars
for f in *; do
new=$(echo "$f" | cut -c1-100)
mv "$f" "$new"
done
Fix 3: Avoid Creating Long Filenames
- Set filename limits in applications
- Use timestamps hashed to 64 chars
- Store metadata in database, use IDs as filenames
Filesystem-Specific Limits
- ext4: 255 bytes
- XFS: 255 bytes
- ZFS: 255 ASCII, 511 Unicode
- NTFS (mounted): 255 UTF-16
Check your filesystem:
df -T /path