Edi Junior
Edi Junior

Reputation: 53

How to check if a file is in a dir and then delete it and another file?

I'm now using Ubuntu, and increasingly using terminal. I would like to delete files from Trash via command line. So, I've gotta delete files from ~/.local/share/Trash/files dir.

All right, here's the question:

When I move some file to trash, it also creates a file_name.trashinfo file in ~/.local/share/Trash/info. How could I automatically delete the corresponding .trashinfo file when I delete something in ../files?

Upvotes: 0

Views: 2406

Answers (1)

avermaet
avermaet

Reputation: 1593

You can use the following script to delete both files simultaneously. Save it in some file in the ~/.local/share/Trash directory, and call then bash <script.sh> <path-to-file-to-be-deleted-in-files-dir>.

A sample call to delete the file test if you named the script del.sh: bash del.sh files/test

#!/bin/bash                                                                 

file=$1
if [ -e "$file" ] # check if file exists
then
  rm -rf "$file" # remove file
  base=$(basename "$file")
  rm -rf "info/$base.trashinfo" # remove second file in info/<file>.trashinfo

  echo 'files deleted!'
fi

Upvotes: 1

Related Questions