New and simpler Solution to closed topic: Prevent writing in directory when Rclone mount is offline in Linux

What is the problem you are having with rclone?

This is NOT a problem with rclone per se, only a technique for using it. This problem is "solved". But it was previously posted (as I've pasted) in 2021 - and automatically closed - essentially unsolved. I found a MUCH simpler solution that I want to share. Maybe you can post this solution there to avoid duplicate posts.

Original post:
Is there a way to disable writes to a directory until the RCLONE is properly mounted under Linux?
My program does not know or care if RCLONE is mounted and will just write into the directory which in this case is the local disc.

Now Rclone service is started errors because there is stuff in the said directory. The option allow non empty is a problem because of conflicting files i assume?
End Original Post

NOTE AND UPDATE! - I had this problem and the previous thread was closed with only a complex and not useful solution - thus unsolved - for somebody of my skill level. But I found a simpler (much simpler) solution that I want to share for other novices like me:


  1. Put a file of a unique name that nobody nor program will ever use in Google Drive. In my case it was in the Google Drive root folder named "Do_NOT_Delete_Me_Or_You_Break_rclone.txt"
  2. Have your program check for the existence of that file before you write to your rclone mounted folder.

Example program in bash file:

if test -f ~/gdrive/Do_NOT_Delete_Me_Or_You_Break_rclone.txt
echo "File exists."

echo "Did NOT transfer files to gdrive because it appears to be not mounted"

Run the command 'rclone version' and share the full output of the command.

rclone v1.64.0

  • os/version: ubuntu 22.04 (64 bit)
  • os/kernel: 6.2.0-34-generic (x86_64)
  • os/type: linux
  • os/arch: amd64
  • go/version: go1.21.1
  • go/linking: static
  • go/tags: none

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

I simply want to write to my gdrive folder - but ONLY when the rclone mount is successful.
ex from a bash file:
cp /home/$USER/DepthSensor/LLL_DepthHistory.txt ~/gdrive/'Directed'

Please run 'rclone config redacted' and share the full output. If you get command not found, please make sure to update rclone.

type = drive
scope = drive
token = XXX
team_drive = 
### Double check the config for sensitive info before posting publicly

A log from the command that you were trying to run with the -vv flag

No log.  Thank You

You could also do this


$ df -h /mnt/tmp/
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/vgxubuntu-root  915G  638G  278G  70% /


$ df -h /mnt/tmp/
Filesystem      Size  Used Avail Use% Mounted on
s3:rclone       1.0P     0  1.0P   0% /mnt/tmp

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.