0

The script takes as input the path to the file to delete and move to trash not only files, but also the entire tree of folders.

Taking as input the absolute path of the file should not be a problem.

In case it is given as input the relative path of a file, how I get the absolute path to be moved to the trash?

Here's a dirty example of execution:

Write the file's path to be deleted ---> /home/user/mydata/song.mp3 (absolute path) In the trash will get: .Trash/home/user/mydata/song.mp3

Write the file's path to be deleted ---> mydata/song.mp3 (relative path) In the trash will get: .Trash/home/user/mydata/song.mp3

1

2 Answers 2

3
#!/usr/bin/bash
delete_dir=$(readlink -f $1)
Sign up to request clarification or add additional context in comments.

Comments

0
#!/usr/bin/bash

read path
if [[ "$path" =~ ^/home/user ]] ; then
  echo mv $path Trash$path
else
  echo mv /home/user/$path Trash/home/user/$path
fi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.