Untitled

 avatar
unknown
plain_text
17 days ago
1.1 kB
4
Indexable
#!/bin/bash

# Sprawdzenie argumentu
if [ $# -ne 1 ]; then
  echo "Uzycie: $0 <katalog>"
  exit 1
fi

DIR=$1

# Znalezienie plików i wypisanie posortowanej listy
echo "Zawartosc katalogu i podkatalogow:"
find "$DIR" -type f | \
  awk -F/ '{ print tolower($NF) }' | \
  sort -t. -k2,2 -k1,1r | \
  while read -r file; do
    FILEPATH=$(find "$DIR" -type f -iname "$(basename "$file")" 2>/dev/null | head -n1)
    if [ -f "$FILEPATH" ]; then
      ls -l --time-style=long-iso "$FILEPATH" | awk '{printf "%s %10d %s\n", $6, $5, tolower($NF)}'
    fi
  done

# Zapytanie o usunięcie .txt
echo -n "Czy chcesz usunac pliki .txt? (t/n): "
read -r decyzja
if [ "$decyzja" = "t" ] || [ "$decyzja" = "T" ]; then
  find "$DIR" -type f -name "*.txt" -exec rm -f {} \;
  echo "Usunieto pliki .txt"
else
  echo "Pliki .txt nie zostaly usuniete"
fi

# Czyszczenie ekranu
clear

# Zapis listy .txt po operacjach
echo "Lista plikow .txt po operacjach:" > results.txt
find "$DIR" -type f -name "*.txt" -printf "%f\n" >> results.txt

# Wyswietlenie wynikow
cat results.txt
Editor is loading...
Leave a Comment