I have approximately 600 pdf files with filenames that are too long to copy to my NAS. It is encrypted and only allows file names of 143 characters or less.
Is there a command or tool that will trim the long file names down to 143 characters or less?
Manually trimming 600 files would be a daunting task so I’m hoping there is a Linux command line approach to solve this.
Ok, I’ve got Krename running and the first issue is how to open the 600 files. They are scattered throughout my file system so I would need a way to put all of them in one directory so I could add them.
Is there a way to find all 600 files and then put them in a specific folder?
There is no program that would read your mind. To do what you want programmatically you need to define rules how to find files and rules how to rename them. If no common rules can be found, you can only do it manually one by one. If you can describe how to find these files, someone may suggest suitable find invocation.
And to add to avidjaar’s comment. you should really find out what the restrictions of that NAS are. You talk about number of characters in the file name, but I would suggest that you may mean bytes, not characters. Remind that nowadays (well since years and years) UTF-8 is used in Linux, also for file names and that thus a character can be more then one byte.
And think about what should happen when a shortened file name is the same as one that already exists (either all the time, or shortened just a few seconds ago) in the same directory.
Again, you know much, much more then we do. I assume that there are things that makes these file names different from all other. E.g. the names end in .pdf. But I do not know if that is enough to find them out (someone already said above, the system, nor we are mind readers).
So when the only criterium is that the names end in .pdf, then
find / -name '*.pdf' 2>/dev/null
would list them all. When you want to restrict to your home directory:
find /home/akorngold -name '*.pdf' 2>/dev/null
would be enough.
And then you can of course pipe the list through some more statements, either to move them to one directory (and hope there are no double names?) or rename them in situ.
And about the renaming itself, you also should design an algoritm. Only you can decide if you want characters to be cut from the begin of the name, or at the end of the name, but before the .pdf. And what to do when names clash with others.
It is you that should do the thinking and when you have made up your mind, we can help to put that in code.