summaryrefslogtreecommitdiff
path: root/.scripts/order
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2023-07-01 20:58:49 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2023-07-01 20:58:49 +0530
commited779a4bc67e7506ba5521ac1d2308aaedeb89de (patch)
treea8f1a6f2a55cd95d52a94d25dde41c5af21281b3 /.scripts/order
parentab60bbbf1b19bae28f7302d2299ca14dd64a7bc5 (diff)
.scripts: Adding order and rsyncfon script
Diffstat (limited to '.scripts/order')
-rwxr-xr-x.scripts/order17
1 files changed, 17 insertions, 0 deletions
diff --git a/.scripts/order b/.scripts/order
new file mode 100755
index 0000000..ecd8f25
--- /dev/null
+++ b/.scripts/order
@@ -0,0 +1,17 @@
+#!/bin/sh
+## Simple shellscript to index all directories present in a main directory based on their creation time
+
+noofdirs=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)
+lenofnod=$(echo -n "$noofdirs" | wc -m) ## Flag n to prevent newline count
+
+# d flag for reverse indexing i.e most recent file-directory is indexed 1.
+if [[ "$1" = "-d" ]]; then
+ ls -d */ -vt | cut -d'/' -f1 | nl -w$lenofnod -s ". " -n rz | while read n f;
+ do mv -n "$f" "$n $f" ;
+ done
+#else by default index oldest file-directory as 1.
+else
+ ls -d */ -vtr | cut -d'/' -f1 | nl -w$lenofnod -s ". " -n rz | while read n f;
+ do mv -n "$f" "$n $f" ;
+ done
+fi