Is there a way of handling invers bash v4 shell expansion, ie. treat all files NOT like a wildcard? I need to rm
all files that are not of the format 'Folder-???'
in this case and was wondering if there is a shorter (ie. built-in) way then doing a
for file in *
do
[[ $i =~ \Folder-...\ ]] && rm '$i'
done
loop. (the example doesn't work, btw...)
Just out of bash learning curiosity...
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
The “if –e” and “if –s” are such operators in Bash, used for testing the existence of a file. The difference between the two is that the former only tests the existence of a file, whereas the latter also checks if there are any contents in that file or not.
The Bash shell feature that is used for matching or expanding specific types of patterns is called globbing. Globbing is mainly used to match filenames or searching for content in a file. Globbing uses wildcard characters to create the pattern.
shopt -s extglob
rm -- !(Folder-???)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With