1

I'm running Linux Lubuntu.

I've been looking for a way to replace/remove forward slashes / from filenames and foldernames (created with MAC computers) with a shell script only for my backup files.

I've searched and apparently, neither did Areca Backup neither anyone else tried to remove these slashes while doing a backup before. Couldn't find any piece of info of to how to check filenames and foldernames and rename those with slashes but I do have a feeling after what I read that it is probably with sed.

Maybe anyone has at least a little piece of info of how this "Preprocessing scripts" from Areca Backup works, would be really great.

Examples (as I mentioned, I wouldlike this to be effective in the backup only if possible)

Filename Before: foo/bar.jpg

Filename After: foobar.jpg

  • A filename can't contain /? Are you talking about a path to a filename? Please edit the question and give us an example of what you have before hand and what you'd like to see afterwards. – Andy Dalton Apr 11 '18 at 15:21
  • Added an example. Hope it's more clear to you now. – Hansel F. Apr 11 '18 at 15:49
  • How are you viewing the file names? With what command? Are they embedded in some backup file or as individual files? – ilkkachu Apr 11 '18 at 18:41
1
echo 'foo/bar.jpg' | sed 's|/||g' 
| improve this answer | |
  • Not really what I'm looking for. The file itself is named with a forward slash as I showed in the example above. The file is stored on an afp network share so I guess it was accepted the way it was named. – Hansel F. Apr 11 '18 at 15:52
  • echo 'foo/bar.jpg' | sed 's|/||g' – Dipankar Nalui Apr 11 '18 at 17:07
  • Please check my updated answer as per your modified question – Dipankar Nalui Apr 11 '18 at 17:28
  • Now this is what I was looking for. Thanks – Hansel F. Apr 12 '18 at 5:34
0

You can use sed to eliminate / from paths:

someFile="/path/to/some/file"
sed -e 's./..g' <<< "${someFile}
pathtosomefile
| improve this answer | |
  • As mentioned in the example above, the file name itself contains a forward slashes, no the path. – Hansel F. Apr 12 '18 at 5:36
  • @HanselF. As mentioned in a comment above, a file name cannot contain forward slashes. Also note that the answer you accepted is the same as the answer that I provided here. – Andy Dalton Apr 12 '18 at 17:58

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.