-1

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?

5
  • 1
    Are you currently running Ubuntu? May 9 '19 at 19:04
  • 1
    No offense but I would not be on this forum if i was not using Ubuntu. Yes I use Ubuntu 18.04.2 May 9 '19 at 23:19
  • 1
    The wording in your question lent itself to "I have a problem with Windows..." May 10 '19 at 0:38
  • 1
    i said absolutely nothing about windows May 10 '19 at 0:55
  • 1
    I didn't intend to offend - there are a lot of questions on this site related to Windows - people starting to use Ubuntu, or having problems with dual-boot, or using WSL. May 10 '19 at 0:58
2

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

/This/Is/The/First/Part/Of/A/Long/Path/And/Here/Is/My/file.name

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

cd ~

Now lets create a directory to store the renamed files:

mkdir ./Shortpath

Now we could move just the one file to the new Shortpath directory:

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 /home/<username>/Shortpath/file.name where <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 /home/<username>/Shortpath/Here/Is/My/file.name

So, by using mv (see 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 mount (see 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

/This/Is/The/First/Part/Of/A/Long/Path/And/Here/Is/My/file.name

and the part you are interested in begins at the Here

Using 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 /mnt/Is/My/file.name

Please note that the file has not been moved - there a are now two fully valid paths to the file:

/mnt/Is/My/file.name and /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 mv

Other commands used here were ls, mkdir, mount, umount, sudo. All of these also have pages in the manuals.

4
  • I have no idea what you are trying to say, I am relatively new to this. could you explain how step by step in greater detail? @Charles Green May 10 '19 at 1:01
  • @MikePeterson Sure - but I think I should ask are you just trying to find the files, access the files, or move them to a shorter directory path? May 10 '19 at 1:05
  • I want to move them to a shorter directory path. May 10 '19 at 12:22
  • @MikePeterson OK, I'll expand the answer, and provide details for two methods. May 10 '19 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.