I was told I can rename and shorten file names that have more than 255 characters (including file pathway entries) using Ubuntu. How can I do this?
Most of this will be done using a terminal window, and typed commands, often referred to as CLI, for command line interface.
The first way that you might try to shorten your fully defined path and filename, is to move the files in question to a shorter path.
Using a terminal window, this is done with the
mv command as outlined below.
1st, open a terminal window (press ctrl+alt+t)
Let's assume that the full pathname to a file is
where the first part log the long pathname is not of interest. You must first create a destination directory to store the files of interest. First let's make sure that you are in your home directory
Now lets create a directory to store the renamed files:
Now we could move just the one file to the new
mv /This/Is/The/First/Part/Of/A/Long/Path/And/Here/Is/My/file.name ./Shortpath/
Now the file
file.name is in the
Shortpath directory in your home directory. The full pathname to the file is
<username> is your user name.
That's fine for a single file, and a little modification makes it move entire subdirectories:
mv /This/Is/The/First/Part/Of/A/Long/Path/And/Here ./Shortpath/
moves the directory named
Here from the long path, to the
Shortpath directory, so the full name for the file would now be
So, by using
man mv) you can move files, or directory structures, from the end of long paths to shorter paths.
This is all well and fine if you want to permanently move the files from a long and unwieldy path, to a short path permanently. Sometimes you just want to do it for a little while, and for that I'm going to use
man mount) to create a short path to the files, that will go away the next time you reboot.
Again lets assume that the long path is
and the part you are interested in begins at the
mount with the
--bind option, we can add a new directory structure to your linux system, so that the path tot he file is much shorter.
First, make sure that a directory we will use as a mountpoint exists:
ls -ld /mnt
should return something like
drwxr-xr-x 2 root root 4096 Apr 16 11:59 /mnt
if it does not, the command
sudo mkdir /mnt will create the directory. You need to use
sudo for this, as regular users can't create directories at the root level.
Now we can connect the directory structure of the long path, starting at
Here to your file system with the command
You might try using
sudo mount --bind /This/Is/The/First/Part/Of/A/Long/Path/And/Here /mnt
Now a path to your file is
Please note that the file has not been moved - there a are now two fully valid paths to the file:
/This/Is/The/First/Part/Of/A/Long/Path/And/Here/Is/My/file.name point to exactly the same place on the disk.
When you are done manipulating files, and you don't need the path mounted anymore, you can execute the command
sudo umount /mnt
which will disconnect the path, or you can reboot. Either way, the mount will be gone.
Some useful information:
In a terminal window, information about commands can be found in the Manuals which are installed in Linux:
man mv show the manual pages for
Other commands used here were
sudo. All of these also have pages in the manuals.