I have a command that I desire to run it automatically only once at the starting up. The solution I found is to put it on the startup file of login shell session, ~/.profile. The problem is that this command is rather time consuming, which delays a lot the initialization.

How to solve it? I want to rclone data from a Google Drive.

  • Why would you put it in profile, instead of running it as a startup unit? Or is the intent that it prepares your shell? Could you actually tell us what the script does? Commented Dec 29, 2022 at 23:42
  • "instead of running it as a startup unit?", my friend, I have no idea what you mean. Commented Dec 30, 2022 at 0:21
  • @MarcusMüller "is the intent that it prepares your shell?" Answer: No; "Could you actually tell us what the script does?" Answer: Sure, it is a rclone command that synchronizes my local files with Google Drive stuffs. Commented Dec 30, 2022 at 0:24

1 Answer 1


What you describe doesn't require or suggest doing this in your shell initialization, but simply as unit required for your user session to work.

If you want that to be done before you reach your graphical target or your multi-user boot target get reached, you just make sure your startup system has a startup script it calls.

Now, you don't say which startup system you're using, or even which operating system – but reading "bash", I suppose it's Linux with systemd.

This makes this pretty easy. Just write a so called systemd unit file that you then make a boot requirement. That's pretty elegant, as it could run as soon as your network is brought up, and while the other things in your system are initialized in parallel; since syncing files will mostly be bound by waiting for network data, this will basically put no extra load on your system, and the syncing is done as soon as you can log in.

A systemd unit file that'd do would look roughly like this:

Description=Syncing stuff to and fro Google Drive

ExecStart=/usr/bin/rclone --options-to-rclone --whatevers
# The following only if not right to run rclone as root

# use WantedBy=graphical.target instead if you need that to be done
# only when the system's ready to log in graphically

put that as .service file in a systemd system service file directory, e.g., /etc/systemd/system/rsync-googledrive.server, and sudo systemctl enable rsync-googledrive will then make sure the service is started at boot.

You can also, instead, make it a user service, by putting it into ~/.config/systemd/user/; remove the User= and Group= lines in that case, and replace the WantedBy= line by WantedBy=default.target.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .