G
G
getnaked2012-08-31 10:18:20
linux
getnaked, 2012-08-31 10:18:20

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

2 answer(s)
J
jov, 2012-08-31
@jov

for f in $files; do newname=$(echo "$f" | tr '\\><|?*/:"' ' ');mv "$f" "$newname";done;

J
jov, 2012-08-31
@jov

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 quotes
What 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.
I just offered a simplified model.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question