4

GNU Parallel is outputting hidden directories as follows using the --results parameter.

What command do I use on Ubuntu to change the all to directories so that they are no longer hidden. The directories are called:

'.\_ValidateAll.sh GL 170'/
'.\_ValidateAll.sh GL 190'/
'.\_ValidateAll.sh GL 220'/
'.\_ValidateAll.sh GL 355'/
'.\_ValidateAll.sh GL 357'/
'.\_ValidateAll.sh GL 359'/
'.\_ValidateAll.sh GL 361'/
'.\_ValidateAll.sh GL 363'/

enter image description here

Actually when I do a cat on the directory, I don't see the single quotes

vmdovs@ubuntu:/mnt/out/1$ cat 
GL170/                    .\_ValidateAll.sh GL 357/ .\_ValidateAll.sh GL 390/ .\_ValidateAll.sh GL 470/ .\_ValidateAll.sh GL 570/
rename.sh                 .\_ValidateAll.sh GL 359/ .\_ValidateAll.sh GL 400/ .\_ValidateAll.sh GL 480/ .\_ValidateAll.sh GL 572/
.\_ValidateAll.sh GL 190/ .\_ValidateAll.sh GL 361/ .\_ValidateAll.sh GL 410/ .\_ValidateAll.sh GL 500/ .\_ValidateAll.sh GL 574/
.\_ValidateAll.sh GL 220/ .\_ValidateAll.sh GL 363/ .\_ValidateAll.sh GL 420/ .\_ValidateAll.sh GL 530/ .\_ValidateAll.sh GL 590/
.\_ValidateAll.sh GL 355/ .\_ValidateAll.sh GL 368/ .\_ValidateAll.sh GL 440/ .\_ValidateAll.sh GL 540/ .\_ValidateAll.sh GL 710/

Also cd can access the directory as follows

cd .\\_ValidateAll.sh\ GL\ 190/
conteh
  • 325

3 Answers3

4

If the only issue is that the directories are hidden, you can just remove the . from the beginning of their name to make them unhidden. For example, using perl-rename (called rename on Ubuntu):

rename 's/^\.//' '.\_Validate'*

Or, with just shell tools:

for dir in '.\_Validate'*; do echo mv "$dir" "${dir//.}"; done

Bot of these leave you with horrible directory names though, with spaces and slashes and other unsavory things. Since you're renaming, you may as well rename to something sane:

rename 's/^\.\\//; s/\s+/_/g' '.\_Validate'*

That will result in:

$ ls -d _*
_ValidateAll.sh_GL_100  _ValidateAll.sh_GL_107  _ValidateAll.sh_GL_114
_ValidateAll.sh_GL_101  _ValidateAll.sh_GL_108  _ValidateAll.sh_GL_115
_ValidateAll.sh_GL_102  _ValidateAll.sh_GL_109  _ValidateAll.sh_GL_116
_ValidateAll.sh_GL_103  _ValidateAll.sh_GL_110  _ValidateAll.sh_GL_117
_ValidateAll.sh_GL_104  _ValidateAll.sh_GL_111  _ValidateAll.sh_GL_118
_ValidateAll.sh_GL_105  _ValidateAll.sh_GL_112  _ValidateAll.sh_GL_119
_ValidateAll.sh_GL_106  _ValidateAll.sh_GL_113  _ValidateAll.sh_GL_120

IMPORTANT: note that I am not checking for file name collision. If you rename one of these to something that already exists, then you will overwrite the existing file.

terdon
  • 242,166
4

You can use GNU Parallel:

parallel mv {} '{=s/^\.\\_//=}' ::: '.\_ValidateAll'*

This will remove .\_ from the names.

To also replace spaces with _ run:

parallel mv {} '{=s/^\.\\_//; s/\s/_/g=}' ::: '.\_ValidateAll'*
Ole Tange
  • 35,514
3

In principle (and as you probably know), files and directories are hidden if their name starts with a .. Thus, you can make them "visible" again by removing that .. It can be done in bash using, the builtin string manipulation functions:

user@host$ for dir in '.\_ValidateAll'*; do newname="${dir#.}"; mv "$dir" "$newname"; done

You would be well-advised, however, to verify it works correctly by trying it beforehand with

user@host$ for dir in '.\_ValidateAll'*; do newname="${dir#.}"; echo "rename $dir to $newname"; done

Update: you should definitely follow the advice in @terdon's answer to make use of the opportunity and get rid of all special characters in that process.

AdminBee
  • 22,803