Browse Source

Merge branch 'master' of git.galthub.com:gmj/home.public.bin

George Jones 3 months ago
parent
commit
22f240b469
3 changed files with 38 additions and 2 deletions
  1. 17 0
      bin/count-files-in-directories.sh
  2. 18 0
      bin/datestamp-files.sh
  3. 3 2
      bin/orglinks.sh

+ 17 - 0
bin/count-files-in-directories.sh

@@ -0,0 +1,17 @@
+#!/bin/bash
+# Count the files each directory in a heirarchy
+#
+# USAGE: count-files-in-directory.sh [DIR [FILETYPE]]
+
+STARTDIR=${1:-.}
+FILETYPE=${2:-""}
+
+# Use find to get all directories in the directory structure
+find $STARTDIR -type d -name \*${FILETYPE} | while read -r dir
+do
+ # Use wc to count the number of files in each directory
+ num_files=$(find "$dir" -type f | wc -l)
+
+ # Print the directory and the number of files
+ echo "$num_files $dir"
+done | sort -n -r

+ 18 - 0
bin/datestamp-files.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+# for all files in one directory, rename the file adding it's mtime to the  filename
+# so foo.txt becomes 2023-12-04-foo.txt
+
+DIR=${1:-.}
+
+# Use find to get all files in the directory
+find $DIR -maxdepth 1 -type f | while read -r file
+do
+ # Use stat to get the modification time of the file
+ mtime=$(stat -c %y "$file")
+
+ # Format the modification time to YYYY-MM-DD
+ formatted_mtime=$(date -d "$mtime" "+%Y-%m-%d-%H-%M-%S")
+
+ # Rename the file by adding the modification time to the front of the filename
+ mv "$file" "$DIR/${formatted_mtime}-$(basename "$file")"
+done

+ 3 - 2
bin/orglinks.sh

@@ -24,8 +24,9 @@ mkdir -p "$destination_dir"
 
 # Find all .org files under $HOME and loop through them
 find "$source_dir" -type f -name "*.org" | grep -v "$destination_dir" | head -$MAXFILES | while read -r original_file; do
+
     # Get the relative path by removing the source directory part
-    relative_path="${original_file#$source_dir/}"
+    relative_path=${original_file#"$source_dir"/}
 
     # Replace "/" in paths with "__"
     modified_relative_path1="${relative_path//\//__}"
@@ -48,7 +49,7 @@ find "$source_dir" -type f -name "*.org" | grep -v "$destination_dir" | head -$M
 
     # if the target file exists, continue
 
-    if [ -f $local_link_to_original ] ; then
+    if [ -f "$local_link_to_original" ] ; then
         continue
     fi