Trying to delete a directory or a file using a pattern-selective deletion (using �*� and �?� )
By respect for people who read you, could you please take the time to post something that make sens ?
Thanks in advance for your time
As ctsgnb says, could you please rephrase this question and post a practical example, what you have to deal with? Thanks.
You can create directories, subdirectories and subsubdirectories in one swoop with the mkdir -p command (brace expansions) using the bash shell (3.0 or higher!).
mkdir -p newdir{1..2}/subdir{1..3}/subsubdir{1..2}
You can delete them again with rm -r:
rm -r new*
Does that help?
1 Like
I want to write a script that deletes files inside the dir. However, the script
should also allow the user to confirm by pressing (d) key.
#!/bin/bash
for file in $1/*
do
size='ls -l $file | cut -f 5 -d " "'
name='ls -l $file | cut -f 9 -d " "'
let "rem=$size%2"
if [ $rem -eq 0 ]; then
echo "file $name is to be deleted"
read -p "press <d> to confirm" answer
if [ "$answer" == "d" ]; then
rm $name
fi
fi
done