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

NotTheDr01ds
  • 15,620
  • 5
  • 44
  • 70
  • possible duplicate of [bash/fish command to print absolute path to a file](http://stackoverflow.com/questions/3915040/bash-fish-command-to-print-absolute-path-to-a-file) – fedorqui Jan 08 '14 at 12:09

2 Answers2

3
#!/usr/bin/bash
delete_dir=$(readlink -f $1)
Luka Bradeško
  • 542
  • 7
  • 16
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
BMW
  • 42,880
  • 12
  • 99
  • 116