I have on a Samba server lots of files in directories/subdirectories containing special chars. The problem is that, the files (containing a special chars) are not visible when I try to view files using Windows. So I wrote command (on the below) to change names of files with special characters, but putting back renamed files to dirs/subdirs doesn't work properly:
find . -type f -exec rename -v 's/[^a-zA-Z0-9 &](?=[^.]*\.)/_/g' '{}' \;
On the bottom I post current directory containing files to rename:
./dir 1/fil[special char]e3.jpg
./dir 1/another dir2/m[special char]r.file1.txt
./dir 1/another dir2/file[special char]2.doc
./dir 3/next dir4/dir 5/fi[special char]le5.xml
./file 4.zip
Expect - after using command described above (files in dirs/subdirs):
./dir 1/fil_e 3.jpg
./dir 1/another dir2/m_r_file1.txt
./dir 1/another dir2/file_2.doc
./dir 3/next dir4/dir 5/fi_le5.xml
./file 4.zip
reality - files in same folder where I run command:
__dir 1_fil_e 3.jpg
__dir 1_another dir 2_m_r_file1.txt
__dir 1_another dir 2_file_2.doc
__dir 3_next dir4_dir 5_fi_le5.xml
__file 4.zip
and I have 2 questions:
- how I can exclude pathname from filename?
- how to put files in to directories?
findhave a-execdir?