You can use the perl rename utility (aka prename or file-rename) to rename the directories.
NOTE: This is not to be confused with rename from util-linux, or any other version.
rename -n 's/([[:cntrl:]])/ord($1)/eg' run_*/
This uses perl's ord() function to replace each control-character in the filename with the ordinal number for that character. e.g ^A ...
And I guess for the sake of curiosity, how in the heck did this happen in the first place?
folder = [sp.saveLocation, 'run_', sp.run_number, '/'];
where sp.run_number was an integer. I forgot to convert it to a string, but for some reason running mkdir(folder); (in matlab) still succeeded.
So, it would appear that mkdir([...]) in Matlab concatenates ...
The shell expands ~ before running sudo; you can see this in action with set -x:
$ set -x
$ sudo ls ~
+ sudo ls /home/skitt
which shows that the command actually run already has the home directory expanded, using the current user at the time of the expansion.
To see the target user’s home directory, you have to defer the tilde expansion:
sudo bash -c 'ls ...
The filetypes reported by ls depends on the capabilities of the underlying filesystem, the operating system, and on the specific implementation of ls.
The l type is the common symbolic link file type.
This is (ought to be) documented in your ls manual.
On OpenBSD (macOS and AIX has the same list, but in another order):
- regular file
b block ...
There are two issues here. The first is quoting. You should get into the habit of always quoting your variables. For more on this please see:
Why does my shell script choke on whitespace or other special characters?
Security implications of forgetting to quote a variable in bash/POSIX shells
However, that's not what's actually breaking your script here. ...
ls sorts the list of files based on their name which in your case doesn't contain newline characters. Even sort sorts on the contents of the lines which don't include the newline character, so here it's not about finding a character that sorts before newline, but one that sorts before nothing and you won't find one.
Now, GNU ls -v (for version-sort) does ...
Easiest would be to create the wrong filename and the correct filename in the same environment where the mishap happened, and then just move/rename the folders to the correct names.
To avoid collisions between existing names better use another destination folder.
./saveLocationA/wrongname1 -> ./saveLocationB/correctname1
./saveLocationA/wrongname2 -> ...
From the BSD ls man page:
LSCOLORS The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatena-
tion of pairs of the format fb, where f is the foreground color and b is the background color.
The color designators are as follows:
drwxr-xr-x. 14 root root 4096 Aug 25 04:02 .
drwxr-xr-x. 25 root root 4096 Sep 16 2018 ..
The two records above are:
one is . the current directory /var/log
The other .. is the parent directory. In this case .. will be the
parent directory of /var/log which is /var.
You can find that information in the info pages by doing info coreutils 'ls invocation'. On my system it includes the following excerpt:
The file type is one of the following characters:
block special file
character special file
high performance ("contiguous data") file
GNU ls doesn't know anything about the terminal's control sequences. It simply relates the $TERM environment variable to its table (whether from the $LS_COLORS environment variable, or its compiled-in defaults doesn't matter much). None of that tells it how many colors the terminal has.
If you read the source code (dircolors.c, ls.c), you might notice ...