What is the appropriate command to move all the files in a directory into a new folder with the current date and time as the folders name and move this folder to a new directory?
Example:
```
$ /media/wm/Birch/Church/Obsidian/CPB/§ Inbox
```
has the following files inside of it:
```
10+ (12 ideally).md
AI Graveyard.md
Building a House of Cards.md
Ground Turkey.md
§ Inbox.md
status and photo blogs.md
```
The objective is to move those 6 markdown files into a folder named `2026-03-24_2046` and then moved to this directory:
```
$ /media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox/
```
---
# 🤖
Good evening!
To accomplish this safely—especially since your file paths contain spaces and the section symbol (`§`)—the best approach is to combine the directory creation and the move command into a single, clean line using a variable.
Here is the exact command you need:
```bash
DEST="/media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox/$(date +"%Y-%m-%d_%H%M")" && mkdir -p "$DEST" && mv "/media/wm/Birch/Church/Obsidian/CPB/§ Inbox/"* "$DEST/"
```
### **How this works:**
* **`DEST="..."`**: This creates a temporary variable holding your long target path.
* **`$(date +"%Y-%m-%d_%H%M")`**: This dynamically generates the current date and time in your requested format (e.g., `2026-03-24_2046`) and appends it to the destination path.
* **`mkdir -p "$DEST"`**: This creates the new timestamped folder inside the `Antiquity/§ Inbox/` directory. The `-p` flag ensures it doesn't throw an error if parent directories already exist.
* **`&&`**: This is a safety check. It ensures the `mv` command *only* runs if the `mkdir` command successfully created the folder first.
* **`mv "/.../§ Inbox/"* "$DEST/"`**: This moves all files from your CPB inbox to the newly created folder. Notice that the asterisk (`*`) is *outside* the quotation marks—this allows the shell to properly select all the individual markdown files inside the directory while still protecting the spaces in the path itself.
> **Note on hidden files:** The `*` wildcard moves all standard, visible files (like your `.md` files). If you happen to have hidden files (like a `.obsidian` configuration file) in that specific inbox folder that also need moving, let me know, as that requires a slight tweak to the command.
Since this looks like a routine vault maintenance task for Obsidian, would you like me to show you how to set this up as a permanent bash alias or script so you only have to type a shortcut like `archive-inbox` in the future?
---
# 👨💻
> [!CITE] PROMPT
You're starting to understand my line of thinking. This is very much something I would rather frequently if can be executed such as you describe. And if i may become greedy in my desires, the flexibility to execute that from any folder inside my vault and push it to the inbox inside Antiquity that would be swell indeed!
---
# 🤖
That isn't greedy at all; that is exactly the kind of smart automation that makes a knowledge management system a joy to use rather than a chore.
To give you the flexibility to execute this from *any* folder you happen to be working in, we will step up from a basic alias to a small **Bash function**. This will take all the files in whatever directory you are currently sitting in and push them straight to a new timestamped folder inside your Antiquity inbox.
Here is how to set it up.
### **Step 1: Add the Function to Your Bash Configuration**
You will need to add this function to your `.bashrc` file so it loads automatically every time you open your terminal.
1. Open your terminal.
2. Open your `.bashrc` file in your preferred text editor (like `nano`):
Bash
```
nano ~/.bashrc
```
3. Scroll all the way to the bottom of the file and paste the following block of code:
Bash
```
archive-vault() {
# Define your fixed Antiquity inbox destination
local BASE_DEST="/media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox"
# Generate the timestamp
local TIMESTAMP=$(date +"%Y-%m-%d_%H%M")
local DEST="$BASE_DEST/$TIMESTAMP"
# Create the timestamped folder
mkdir -p "$DEST"
# Move all visible files from your CURRENT folder to the new destination
if mv ./* "$DEST/" 2>/dev/null; then
echo "Vault files safely archived to: $DEST"
else
echo "No files found to move, or an error occurred."
# Clean up the empty folder if the move failed
rmdir "$DEST" 2>/dev/null
fi
}
```
4. Save and exit (in `nano`, press `Ctrl+O`, `Enter` to save, then `Ctrl+X` to exit).
### **Step 2: Reload Your Configuration**
To make the new command available immediately without restarting your terminal, run:
Bash
```
source ~/.bashrc
```
### **Step 3: How to Use It**
Now, the workflow is incredibly simple. Whenever you are inside a directory in your terminal and want to empty its contents into your Antiquity archive, just type:
Bash
```
archive-vault
```
The script will automatically detect the current time, build the folder in `/media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox/`, grab the files from the folder you are currently standing in, and move them over.
Would you like to add a safety prompt to this script (e.g., "Are you sure you want to move 6 files? (y/n)") to prevent accidental archiving, or do you prefer the instant execution?
---
# 👨💻
> [!CITE] PROMPT
> Safety prompt, yes.
>
> I have my own alias file as to prevent from an accidental "whoopsie" located at `~/.bash_aliases` would that be alright to use, or can I create a new one for things such as this?
---
# 🤖
Using `~/.bash_aliases` is an excellent habit for preventing a system-breaking "whoopsie." On Linux Mint, the default system `.bashrc` is actually pre-configured to look for and load a `.bash_aliases` file automatically if it exists.
You can absolutely place functions in there alongside your standard aliases; the shell treats them the same way when loading.
Here is the updated function, complete with a file counter and a safety prompt.
### **The Updated `archive-vault` Function**
Open your `~/.bash_aliases` file and paste this block at the bottom:
Bash
```
archive-vault() {
# Create an array of all visible items in the current directory
local files=(*)
local count=${#files[@]}
# Check if the folder is empty before doing anything
if [ "$count" -eq 0 ]; then
echo "Directory is empty. Nothing to archive."
return 0
fi
# The safety prompt
read -p "Are you sure you want to move $count item(s) to Antiquity? (y/n) " response
# Execute only if the user types 'y' or 'Y'
if [[ "$response" =~ ^[Yy]$ ]]; then
local BASE_DEST="/media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox"
local TIMESTAMP=$(date +"%Y-%m-%d_%H%M")
local DEST="$BASE_DEST/$TIMESTAMP"
# Create the destination folder
mkdir -p "$DEST"
# Move the files and report success
if mv "${files[@]}" "$DEST/" 2>/dev/null; then
echo "Success! Archived $count item(s) to: $DEST"
else
echo "An error occurred during the move."
# Clean up the empty folder if the move failed
rmdir "$DEST" 2>/dev/null
fi
else
echo "Archive aborted."
fi
}
```
### **How to Apply It**
Once you have saved the file, reload your aliases by running:
Bash
```
source ~/.bash_aliases
```
Now, when you type `archive-vault`, it will tally up the files in your current directory, ask for confirmation, and only proceed if you give it the green light.
Would you like me to add a small modification to this script that automatically drops a quick `Archive Log.md` file inside the new timestamped folder listing the names of the files that were just moved?
---
# 👨💻
> [!CITE] PROMPT
> Wow yes, a Archive Log file would be great.
---
# 🤖
This is going to make your workflow incredibly smooth. Since you are moving these into Obsidian, we can even format the `Archive Log.md` file using markdown so it looks perfectly formatted the second you open it in your vault.
I have updated the script to automatically generate the log file, note the original directory the files came from, and list each moved file as a bullet point.
I also added a tiny, silent safeguard: standard Bash will sometimes count an empty folder as having "1" item (a literal asterisk) if you try to count it. I swapped the empty-folder check to verify the file actually exists, which prevents any weird phantom moves.
### **The Final `archive-vault` Function**
Open up your `~/.bash_aliases` file, delete the previous version we just made, and paste this one in its place:
Bash
```
archive-vault() {
# Create an array of all visible items in the current directory
local files=(*)
local count=${#files[@]}
# Check if the folder is actually empty (prevents the literal '*' bug)
if [ ! -e "${files}" ]; then
echo "Directory is empty. Nothing to archive."
return 0
fi
# The safety prompt
read -p "Are you sure you want to move $count item(s) to Antiquity? (y/n) " response
# Execute only if the user types 'y' or 'Y'
if [[ "$response" =~ ^[Yy]$ ]]; then
local BASE_DEST="/media/wm/Birch/Church/Obsidian/Antiquity/§ Inbox"
local TIMESTAMP=$(date +"%Y-%m-%d_%H%M")
local DEST="$BASE_DEST/$TIMESTAMP"
# Create the destination folder
mkdir -p "$DEST"
# Move the files
if mv "${files[@]}" "$DEST/" 2>/dev/null; then
# --- NEW: Create the Archive Log ---
local LOG_FILE="$DEST/Archive Log.md"
echo "# Archive Log: $TIMESTAMP" > "$LOG_FILE"
echo "" >> "$LOG_FILE"
echo "**Original Location:** \`$PWD\`" >> "$LOG_FILE"
echo "" >> "$LOG_FILE"
echo "### Files Archived:" >> "$LOG_FILE"
# Loop through the files and add them as bullet points
for f in "${files[@]}"; do
echo "- $f" >> "$LOG_FILE"
done
# -----------------------------------
echo "Success! Archived $count item(s) and created a log in: $DEST"
else
echo "An error occurred during the move."
# Clean up the empty folder if the move failed
rmdir "$DEST" 2>/dev/null
fi
else
echo "Archive aborted."
fi
}
```
### **How to Apply It**
Just like before, save the file and reload your aliases:
Bash
```
source ~/.bash_aliases
```
Now, when you run `archive-vault`, your new folder in Antiquity will contain all your moved files, plus a clean `Archive Log.md` that looks something like this when you open it in Obsidian:
# Archive Log: 2026-03-24_2109
**Original Location:** `/media/wm/Birch/Church/Obsidian/CPB/§ Inbox`
### Files Archived
* 10+ (12 ideally).md
* AI Graveyard.md
* Building a House of Cards.md
* Ground Turkey.md
* status and photo blogs.md
* § Inbox.md
---
Would you like me to wrap those log file bullet points in Obsidian wikilinks (e.g., `[[Ground Turkey.md]]`) so you can click them directly from the log, or do you prefer them as plain text list items?
---
# 👨💻
> [!CITE] PROMPT
> You have outdone yourself. This should square me away for now. I'll pin the conversation if I run into any hiccups, but I thank you. o7
---
# 🤖
You are very welcome! o7
I am glad we could get that sorted out and streamline your vault maintenance. Pinning the conversation is a great idea—just drop back in whenever you need to tweak the script or troubleshoot any hiccups.
When you are ready for your next project, would you like me to show you how to bind this new command to a custom keyboard shortcut in Linux Mint so you can archive files without even opening the terminal?
---
#LinuxMint #CLI #Obsidian