Reputation: 31
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
Upvotes: 0
Views: 1842
Reputation: 45243
#!/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
Upvotes: 0