summaryrefslogtreecommitdiff
path: root/.scripts
diff options
context:
space:
mode:
authorSaumit Dinesan <justsaumit@protonmail.com>2022-07-06 11:50:11 +0530
committerSaumit Dinesan <justsaumit@protonmail.com>2022-07-06 11:50:11 +0530
commit04ad460a97319f475505f9107179b0374470e588 (patch)
treee6e1e8e7d997c4532583983ba6186c1d70b258f5 /.scripts
parent2be1b55c588b3afeeb6f6d8dc337b76ed3357631 (diff)
only to rename directories and addition of -d flag
Diffstat (limited to '.scripts')
-rw-r--r--.scripts/order13
1 files changed, 12 insertions, 1 deletions
diff --git a/.scripts/order b/.scripts/order
index bfd6947..aba3e71 100644
--- a/.scripts/order
+++ b/.scripts/order
@@ -1,6 +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
-ls -vtr | nl -w$lenofnod -s ". " -n rz | while read n f; do mv -n "$f" "$n $f" ; done
+# 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