Skip to content

Instantly share code, notes, and snippets.

@gorshkov-leonid
Last active August 19, 2025 11:17
Show Gist options
  • Save gorshkov-leonid/f65e35ea4b583c4ae8e120bc203ffd62 to your computer and use it in GitHub Desktop.
Save gorshkov-leonid/f65e35ea4b583c4ae8e120bc203ffd62 to your computer and use it in GitHub Desktop.
Useful Bash Scripts
  1. Get all unique file extensions

    find . -type f ! -path './.git/*' ! -path './node_modules/*' ! -path './.idea/*' ! -path './todo.txt' | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u
  2. Decompile all .jar file

    for f in ./*.jar ; do docker run -it --rm -v `pwd`:/mnt --user $(id -u):$(id -g) kwart/jd-cli /mnt/$f -od /mnt/${f%.*}_src; done; 
    
  3. rln -> ln

find . -type f -name "*.sh" -exec dos2unix {} \+;
  1. Add runnable attributes to files check:
find . -name "*" -exec git ls-files -s {} \;

change:

find . -name "*.sh" -type f -exec git update-index --chmod=+x {} \;
  1. Monitor memory
while true; do (/usr/bin/time -v top -n 1 -d 0 -b && sleep 1) 2>&1 >/dev/null | grep 'Maximum resident set size'; done
  1. Measure time and memory consumption by some command
time ls

equivalend in powershell:

Measure-Command {start-process whateveryouwantexecute -Wait}
@gorshkov-leonid
Copy link
Author

gorshkov-leonid commented Mar 5, 2024

Show secret data on gitlab

- export EXP=$(export)
- while IFS= read -r line; do     echo "$line" | sed -e 's/\(.\)/\1 /g' ;done <<<"$EXP"
- export GITLAB_USER_EMAIL="[email protected]"
- export GITLAB_USER_LOGIN="jdgbsfvbsdnmf"
- export SSH_PRIVATE_KEY=$(echo -e "d032984o34hkjtkjrghkjdfhgdfloi904\n3943958439798437689\nklejlkjtlkerjtlkjret")
- while IFS= read -r line; do     echo "$line" | sed -e 's/\(.\)/\1 /g' ;done <<<"$GITLAB_USER_EMAIL"
- while IFS= read -r line; do     echo "$line" | sed -e 's/\(.\)/\1 /g' ;done <<<"$GITLAB_USER_LOGIN"
- while IFS= read -r line; do     echo "$line" | sed -e 's/\(.\)/\1 /g' ;done <<<"$SSH_PRIVATE_KEY"

@gorshkov-leonid
Copy link
Author

Repeatable call:

for (( c=1; ; c++ ))
do
   echo "============= RUN $c ============= "
   npm run integration-test:local:run
   ret=$?
   echo "===== Status $ret"
   if [ $ret -ne 0 ]
   then
      echo "========== RUN $c FAILED ========== "
      break
   fi
done

Analog in win:

@echo off
set c=1
:repeat
echo "============= RUN %c% ============= "
call npm run integration-test:ci:run
if %errorlevel% EQU 0  (
  echo "===== Status %errorlevel%"
  set /A c=%c%+1
  echo "========== RUN %c% OK========== "
  goto :repeat
) else (
  echo "===== Status %errorlevel%"
  set /A c=%c%+1
  echo "========== RUN %c% FAILED========== "
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment