Archive for August, 2016

Bash Delete Method

Tuesday, August 9th, 2016

I recently permanently delete some files because of habit using, rm -fr ./file.txt, ops.  So I looked into creating a bash function to delete files and just move them into a system temporary folder for auto delayed deletion.

There are multiply system temporary location on a mac,

/tmp – Used for short temp files.  This directory is available on system startup.  Some system are setup to use this directory in memory storage only.

/var/temp – Used for bigger files.  Because this is in the VAR directory it needs to be mounted and thus not available until then(after startup).

$TMPDIR – Is a temp directory variable, this is the recommended location to store temp files on OSX.

These directories are cleaned up differently on different systems.

Below is the line I added to my ~/.bash_profile
del() { mv $1 $TMPDIR; };

This will add a function called del that will move a file into the $TMPDIR.  This will allow the file to be queried for deletion, but also allows for a short recovery time.

View my sample .bash_profile:

https://github.com/johnfreier/scripts/blob/master/linux/.bash_profile