Bash - s50600822/Notes GitHub Wiki

Find all file types under dir

find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

SED find and replace

find . -name *.java -type f |xargs grep "import org.jetbrains.annotations.NotNull" -l|xargs sed -i -e 's/@NotNull/@Nonnull/g' 

 

find . -name *.java -type f |xargs grep -v "import javax.annotation.Nonnull" -l |xargs sed -i -e 's/import org.jetbrains.annotations.NotNull/import javax.annotation.Nonnull/g'

 

find . -name *.java|xargs grep "import javax.annotation.Nonnull;" -l | uniq -d

remove prefix before "-"

#!/bin/bash

# Loop through all files in the current directory
for file in *; do
    # Check if the file name contains a "-"
    if [ $file == *-* ](/s50600822/Notes/wiki/-$file-==-*-*-); then
        # Get the part of the file name after the "-"
        new_name="${file#*-}"

        # Trim leading and trailing spaces from the new name
        new_name=$(echo "$new_name" | xargs)

        # Rename the file
        mv -v "$file" "$new_name"
        echo "Renamed \"$file\" to \"$new_name\""
    fi
done