Currently I have a recursive directory of files that looks like the following
foo_1/bar_1.txt
foo_1/foo_2/bar_2.txt
foo_1/foo_2/bar_2a.txt
foo_1/foo_2/foo_3/bar_3.txt
...
I need to use a bash script to convert them into single file names safe across all operations like the follows:
foo_1_bar_1.txt
foo_1_foo_2_bar_2.txt
foo_1_foo_2_bar_2a.txt
foo_1_foo_2_foo_3_bar_3.txt
...
However using the underscore as the replacement of "/" would undermine the backward process and one cannot convert them back to the original "Path" names.
I am currently considering using "=" as the replacement character and thing will look like
foo_1=bar_1.txt
foo_1=foo_2=bar_2.txt
foo_1=foo_2=bar_2a.txt
foo_1=foo_2=foo_3=bar_3.txt
I went through this question (Good style/practices for separators in file (or directory) names) where the answer suggests using multi-character options but I since my file names are already pretty long and need to be kept below a certain threshold after the "replacement process", if a single character option, that is human readable, is available things will work in my best interest.
I have tested touching a file with equal sign and it is working fine on at least MacOS, however I am afraid there are some other systems that will result in problems. Are there any caveats in doing this?
EDIT: The purpose of my process, is to convert a tree-like directory structure into a single directory, upload the files to a server (via ssh) that only accepts single directory structure, and then have another computer download (via HTTP) the files and convert them back to the directory structure.
touch a/b.txt
on my system would give no such file or directory error – cr001 Jan 13 '22 at 09:12a
exists first then.mkdir -p a && touch a/b.txt
. – Kusalananda Jan 13 '22 at 10:01tar
or something to put all the files into one archive file (optionally compressed withgzip
orxz
or whatever), upload it, and the other system can download and extract it? That's one of the things that archive formats are for. – cas Jan 13 '22 at 10:12