That “sed” part changes every character to “" with the exception of the 4 characters ":.-” (quotes are not part of that string).
As Henk says, only “/” is illegal (and probably ‘\000’ (or NUL, binary zero)).
I don’t know where you are using this. However, you might want to remove that “:” (colon) from the allowed characters if you are using Windows file systems. That’s an illegal character for Windows file names.
Date_Time_Stamp=$( date +"$DTS_tmp2" | tr ' ' '_' | sed -e 's/^A-Za-z0-9:._-]//g')
Current_Vault_Folder="$Virus_Vault_Folder/${OStype}_"
Current_Vault_Folder+="$Date_Time_Stamp"
mkdir "${Current_Vault_Folder}"
A user might scan windows and copy the virus files into that folder. Then transfer them to a windows system. So, I should need to restrict to windows illegal characters as well. It will depend if a typical user will do that.
](https://stackoverflow.com/posts/31976060/timeline) Let's keep it simple and answer the question, first.
The forbidden printable ASCII characters
are:
Linux/Unix:
/ (forward slash)
Windows:
< (less than)
> (greater than)
: (colon - sometimes works, but is actually NTFS Alternate Data Streams)
" (double quote)
/ (forward slash)
\ (backslash)
| (vertical bar or pipe)
? (question mark)
(asterisk)
Non-printable characters
If your data comes from a source that would permit non-printable characters then there is more to check for.
The version of bash should be the most common. SED is included by default?
Reading the CFG file: scanvirus configuration
Date[space]Time or Time[space]Date
date +‘%Y-%m-%d %I:%M:%S%P’
DateTimeStamp= %Y-%m-%d %I:%M:%S%P
ExcludedScanFolders= dev etc kdeinit5__0 proc tmp srv sys .snapshots
The code clips.
#remove all past ';'
#printf "%s
" "$line"
DTS_tmp1=${line#DateTimeStamp= *}
#printf "%s
" "$DTS_tmp1"
DTS_tmp2=${DTS_tmp1%%;*}
#printf "%s
" "$DTS_tmp2"
#check for valid date and time
Date_Time_Stamp=$( date +"$DTS_tmp2" | tr ' ' '_' | tr sed -e 's/^A-Za-z0-9:._-]//g')
Current_Vault_Folder="$Virus_Vault_Folder/linux_"
Current_Vault_Folder+="$Date_Time_Stamp"
mkdir "${Current_Vault_Folder}"
After this, to make later output more readable. I convert '_ ’ to ‘[space]’
I need the folder name to be readable, but hold no illegal characters for both windows and linux. Give the user the most flexibility for the date time stamp.
I let through only some characters or mask out illegal characters.