Answer the question
In order to leave comments, you need to log in
How to copy files with forbidden characters?
Good afternoon.
I have an Ubuntu computer with over 20 gigabytes of files. The problem is that they need to be copied to a computer running Windows, but there are forbidden characters in the file names - > < |? * / \: "
Does anyone have a ready-made script that will go through all the files and bring them to a form suitable for Windows?
Answer the question
In order to leave comments, you need to log in
for f in $files; do newname=$(echo "$f" | tr '\\><|?*/:"' ' ');mv "$f" "$newname";done;
sledopit , let's go in order. As for the first character in the file name from the “forbidden” category, I agree, I didn’t think about it. Treated with a simple sed script
[email protected]:~/h$ echo '<<<<s><|?*/\:"e' | tr '\\><|?*/:"' ' ' | sed "s/^ *//"
well, or, as suggested by danfe, replace "forbidden" with "_".$() after newname= must be enclosed in double quotesWhat for?
Well, it was also worth writing about the $files variable. Otherwise, the cycle will not start.Obviously it won't start. How the author of the question will choose files for renaming, I do not know. As an option, use the script provided by danfe and work with subdirectories of the current directory, or not, everything is at the discretion of the author.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question