USEFUL COMMANDS (MISCELLANEOUS)
Finding directories
We are going to create a script that recursively finds all directories that contain a .pom.xml file inside them and, if they do, executes a mvn clean.
This way we can keep our filesystem clean.
#!/bin/bash
EXECUTION_DIR=$PWD
array=($(find . -type d))
for value in "${array[@]}"
do
FILE=$value/pom.xml
if [ -f "$FILE" ]; then
cd $value
mvn clean
echo "Cleaned successfully project at $value"
cd $EXECUTION_DIR
fi
done
Printing path and file name in a shell script
This is done using the dirname and basename commands:
#!/bin/bash
read -p "Please insert File Full Path: " OPENAPI_MAIN_FILE
directory=$(dirname "$OPENAPI_MAIN_FILE")
filename=$(basename "$OPENAPI_MAIN_FILE")
echo $directory
echo $filename