Install the app
How to install the app on iOS

Follow along with the video below to see how to install our site as a web app on your home screen.

Note: This feature may not be available in some browsers.

What is a good CLI program to install on my Synology to move files to the DSM 7 recycling bin?

As an Amazon Associate, we may earn commissions from qualifying purchases. Learn more...

44
7
NAS
DS1520+
Operating system
  1. macOS
Mobile operating system
  1. iOS
Occasionally I use the comamnd line on my Synology via ssh, beacuise sometimes I want to "trash" files or folders (the command line is great for this with globbing!). So I want to move the files to DSM's recycling bin.

So, is there a command line program which does this and which I can install through a package on my Synology? (I know on macOS of this trash program and on Linux of this one.)

Thanks for pointers!
 
Last edited:
You don't need CLI or Package for that because DSM has that function build in IF you have enabled that function per Shared Folder.
 
Upvote 0
You don't need CLI or Package for that because DSM has that function build in IF you have enabled that function per Shared Folder.
Do I understand you correctly: There is a CLI command already? What is that command?

(I need it to be a CLI command, so that I can do things like

Code:
trash *_hdr.tiff

to move all files in the current directory which end with _hdr.tiff to the trash.)
 
Upvote 0
Last edited:
NO, you don't understand or I was not clear with: " build in IF you have enabled that function per Shared Folder."
See Create a Shared Folder | DSM - Synology Knowledge Center (Enable Recycle Bin)
Anyway, the question is now more detailed and I understand you will and must use CLI and not the GUI function Recycle Bin so, you need a script.....
But, why can't you do that in GUI ? Because only "trash *_hdr.tiff" is only possible when you are in the right folder......
 
Upvote 0
Yes, sorry, my initial post was maybe not detailed enough.

I really want a CLI tool, because then I can combine it with find and other tools over multiple directories...

Anyway, just hoping that something like trash-cli for linux exists for Synology OS as well...
 
Upvote 0
If I understand correctly, this is what you want. Created with some help from ChatGPT. Use at your own risk.

Bash:
#!/bin/bash

# Script to find all files with a certain extension and move them to the recycle bin

# Check if the user provided the correct arguments
if [ "$#" -lt 2 ]; then
  echo "Usage: $0 <directory> <extension>"
  echo "Example: $0 /path/to/search .txt"
  exit 1
fi

# Get the directory and extension from the arguments
directory=$1
extension=$2

# Validate the directory
if [ ! -d "$directory" ]; then
  echo "Error: Directory '$directory' does not exist."
  exit 1
fi

# Find the root of the shared directory using df and awk
share_root=$(df -h "$directory" | awk 'NR==2 {print $NF}')

# Ensure the share_root was determined
if [ -z "$share_root" ]; then
  echo "Error: Unable to determine the shared folder root."
  exit 1
fi

# Define the recycle bin path
recycle_bin="$share_root/#recycle"

# Check if the recycle bin directory exists
if [ ! -d "$recycle_bin" ]; then
  echo "Error: Recycle bin directory ('$recycle_bin') does not exist. Enable the recycle bin for this shared folder."
  exit 1
fi

# Use the find command to search for files
echo "Searching for files with the extension '$extension' in '$directory'..."
files=$(find "$directory" -type f -name "*$extension")

# Check if any files were found
if [ -z "$files" ]; then
  echo "No files with the extension '$extension' were found."
  exit 0
fi

# Display the files to the user
echo "The following files were found:"
echo "$files"

# Ask the user if they want to move the files to the recycle bin
read -p "Do you want to move these files to the recycle bin? (y/n): " confirm

# If the user confirms, move the files
if [[ "$confirm" == "y" || "$confirm" == "Y" ]]; then
  echo "Moving files to the recycle bin..."
  while IFS= read -r file; do
    mv -v "$file" "$recycle_bin/"
  done <<< "$files"
  echo "Files have been moved to the recycle bin."
else
  echo "No files were moved."
fi
 
Upvote 0

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

Popular tags from this forum

dsm

Thread Tags

Welcome to SynoForum.com!

SynoForum.com is an unofficial Synology forum for NAS owners and enthusiasts.

Registration is free, easy and fast!

Trending content in this forum

Back
Top