--- title: "Delete Files/Folders" slug: "delete-filesfolders" updated: 2024-10-10T09:38:01Z published: 2024-10-10T09:38:01Z canonical: "help.scalefusion.com/delete-filesfolders" --- > ## Documentation Index > Fetch the complete documentation index at: https://help.scalefusion.com/llms.txt > Use this file to discover all available pages before exploring further. # Delete Files/Folders Use this script to remotely delete files and/or folders on Linux machines. 1. Copy and save the contents below to a **UTF-8** editor like **notepad++** OR **Sublime Text** in Windows or **gedit** in Ubuntu. 1. If you are using **notepad++** then use the bottom right panel to change the type to **Unix (LF)**. ![](https://cdn.document360.io/175c0eac-012f-4410-bdc5-ac60794f82d8/Images/Documentation/image-NAW5LA30.png) 2. Or click [here](https://cdn.document360.io/175c0eac-012f-4410-bdc5-ac60794f82d8/Images/Documentation/Delete_Files_Folders.sh) to download the file. ```bash #!/bin/bash # Define the target hostname (convert to lowercase) target_hostname="ENTER_CURRENT_HOSTNAME_OF_DEVICE" # Get the current hostname (convert to lowercase) current_hostname=$(hostname | tr '[:upper:]' '[:lower:]') # Check if the current hostname matches the target hostname if [ "$current_hostname" != "$target_hostname" ]; then    echo "Error: Current hostname ($current_hostname) does not match the target hostname ($target_hostname). Exiting."    exit 1 fi # Function to delete a file and show a message delete_file() {    file_path=$1    if [ -e "$file_path" ]; then        rm "$file_path"        echo "File $file_path deleted."    else        echo "File $file_path not found."    fi } # Function to delete a folder and its contents and show a message delete_folder() {    folder_path=$1    if [ -e "$folder_path" ]; then        rm -r "$folder_path"        echo "Folder $folder_path and its contents deleted."    else        echo "Folder $folder_path not found."    fi } # DELETE_A_FILE delete_file "/path/to/file.txt" # DELETE_MULTIPLE_FILES delete_file "/path/to/file1.txt" delete_file "/path/to/file2.txt" # DELETE_A_FOLDER_AND_ITS_CONTENTS delete_folder "/path/to/folder" # DELETE_MULTIPLE_FOLDERS_AND_THEIR_CONTENTS delete_folder "/path/to/folder1" delete_folder "/path/to/folder2" # Use caution with wildcards to avoid unintended deletions # For example, this will delete all .txt files in the home directory and its subdirectories # rm -r ~/*.txt ``` 3. In the script, replace the following placeholder: 1. Provide the host name in the line: target_hostname="ENTER_CURRENT_HOSTNAME_OF_DEVICE" 2. Provide the path of the file or folder to be deleted in the lines: delete_file "/path/to/file.txt" delete_file "/path/to/file1.txt" 4. Please use caution with wildcards to avoid unintended deletions, for example, rm -r ~/*.txt will delete all .txt files in the home directory and its subdirectories. 5. Follow [our guide](/docs/deploy-linux-shell-scripts-using-scalefusion#step-1-upload-and-deploy-the-script) to upload & publish the script using Scalefusion Dashboard. > [!CAUTION] > Note: > > 1. Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT. > 2. Please validate the scripts on a test machine before deploying them on all your managed devices. > 3. Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.