<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Marco Antonio Bet</title>
    <description>The latest articles on DEV Community by Marco Antonio Bet (@itsbetma).</description>
    <link>https://dev.to/itsbetma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F684395%2F43415b44-b15b-4851-8d9e-f796b1571fce.jpeg</url>
      <title>DEV Community: Marco Antonio Bet</title>
      <link>https://dev.to/itsbetma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/itsbetma"/>
    <language>en</language>
    <item>
      <title>Productivity with Git aliases</title>
      <dc:creator>Marco Antonio Bet</dc:creator>
      <pubDate>Thu, 25 Aug 2022 00:22:00 +0000</pubDate>
      <link>https://dev.to/itsbetma/productivity-with-git-aliases-g5i</link>
      <guid>https://dev.to/itsbetma/productivity-with-git-aliases-g5i</guid>
      <description>&lt;p&gt;It has been a year from the day I started working on my actual job, and it was the first work that I need to use git, and from this day on I never stopped using it, it is just so amazing.&lt;/p&gt;

&lt;p&gt;But one thing that made me very frustrated is that for some cases git commands can be very long or not intuitive. Also, some commands would show a lot of information that I did not want to see.&lt;/p&gt;

&lt;p&gt;For example, the git status and git log commands would show consecutively something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git status
On branch main
Changes to be committed:
  (use "git restore --staged &amp;lt;file&amp;gt;..." to unstage)
 new file:   added_file
 new file:   delete_file
 new file:   renamed_file
Changes not staged for commit:
  (use "git add/rm &amp;lt;file&amp;gt;..." to update what will be committed)
  (use "git restore &amp;lt;file&amp;gt;..." to discard changes in working directory)
 deleted:    delete_file
 deleted:    renamed_file
Untracked files:
  (use "git add &amp;lt;file&amp;gt;..." to include in what will be committed)
 fourth_file
 new_file
  now_renamed_file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;








&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git log
commit 895e76a4e71ecc4cc65de27e4429ffce165cccff (HEAD -&amp;gt; main)
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:36 2022 -0300
third file
commit 86deb1bb03edabb56e4cb5d84289fe7ab3025607
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:10 2022 -0300
second commit
commit d8fb730fe75482bdcc4cfd923ffdbdec95953a5a
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:02 2022 -0300
first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So I wonder if there is a better way of showing these pieces of information.&lt;/p&gt;

&lt;p&gt;Let’s start with the simpler one which is git status, but first, we need to understand how to set git alias.&lt;/p&gt;

&lt;h3&gt;
  
  
  Ways of setting git alias
&lt;/h3&gt;

&lt;p&gt;There are two ways of setting git alias, one of them is by commands in the terminal and another is by editing the &lt;strong&gt;&lt;code&gt;~/.gitconfig&lt;/code&gt;&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;For example, setting git status improvements with terminal commands would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git config --global alias.ss status -sb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you want to set the git alias with a text editor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git config --global --edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will open the default editor for git.&lt;/p&gt;

&lt;p&gt;You can also open the &lt;strong&gt;&lt;code&gt;~/.gitconfig&lt;/code&gt;&lt;/strong&gt; file with &lt;code&gt;vim ~/.gitconfig&lt;/code&gt;, code &lt;code&gt;~/.gitconfig&lt;/code&gt;, or any other text editor.&lt;/p&gt;




&lt;p&gt;Now allow me to go back to where I was.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git config --global alias.ss status -sb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So with this new alias set, how can we use it?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git ss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which will show a reduced &lt;strong&gt;&lt;code&gt;git status&lt;/code&gt;&lt;/strong&gt; output.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜  git_alias git:(main) ✗ git ss    
## main
A  added_file
AD delete_file
AD renamed_file
?? fourth_file
?? new_file
?? now_renamed_file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may be asking yourself what is the &lt;strong&gt;&lt;code&gt;-sb&lt;/code&gt;&lt;/strong&gt; flag in the git status command is.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;s&lt;/strong&gt;: Give the output in the short format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;b&lt;/strong&gt;: Show the current branch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore with just a little bit of change in the git status command, you can have a better output.&lt;/p&gt;

&lt;p&gt;With the &lt;strong&gt;git log&lt;/strong&gt; improvement, we will go a little bit forward and I will show you two types of an alias that I currently have.&lt;/p&gt;

&lt;h3&gt;
  
  
  First type of git log alias
&lt;/h3&gt;

&lt;p&gt;Alias:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git config --global alias.ll !git log --pretty=format:'%C(blue)%h %C(cyan)%ae %C(green)%cr%C(red)%d %C(white)%s’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output would be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git ll
895e76a example@example.com 38 minutes ago (HEAD -&amp;gt; main) third file
86deb1b example@example.com 39 minutes ago second commit
d8fb730 example@example.com 39 minutes ago first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is my favorite of the two because it shows the HASH, Email, Date, and commit message.&lt;/p&gt;

&lt;p&gt;You would be asking yourself what is the &lt;strong&gt;--pretty=format&lt;/strong&gt;: flag in the git log command. Basically, this command demands an option that can be a placeholder, which is currently our option.&lt;/p&gt;

&lt;p&gt;Every placeholder starts with a &lt;strong&gt;%&lt;/strong&gt; sign. And the &lt;strong&gt;%C&lt;/strong&gt; placeholder stands for color, as you can see inside the parenthesis there is always a color name.&lt;/p&gt;

&lt;p&gt;List of placeholders used in this command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;%C()&lt;/strong&gt;: Change the color of the text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%h&lt;/strong&gt;: Show the hash of the commit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%ae&lt;/strong&gt;: Show the author’s email.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%cr&lt;/strong&gt;: Show the committer date.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%d&lt;/strong&gt;: Show to you which commit is the head of the local and origin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;%s&lt;/strong&gt;: Show the subject of the commit message.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Second type of git log alias
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git config --global alias.lg log --all --graph --decorate --oneline --abbrev-commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output would be something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git lg
* 895e76a (HEAD -&amp;gt; main) third file
* 86deb1b second commit
* d8fb730 first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is not my favorite &lt;strong&gt;git log&lt;/strong&gt; alias, but it is a very good example of an alias because before I would need to write the full command and now I just need to write &lt;strong&gt;git lg&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Explaining some of the git aliases that I have
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Shell script in a git alias
&lt;/h4&gt;

&lt;p&gt;When a git alias starts with a &lt;strong&gt;!&lt;/strong&gt; this means that the command next is Bash or Shell. With this, you can create functions and use operators like &lt;strong&gt;&amp;amp;&amp;amp;&lt;/strong&gt; and &lt;strong&gt;||&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;staging = !git fetch &amp;amp;&amp;amp; git checkout origin/staging
main = !git fetch &amp;amp;&amp;amp; git checkout origin/main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where I work we use the staging and main as central branches, so every time I need to start working on something new I need to check out from one or another and this command helps me do this quickly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;amend = !git add -A &amp;amp;&amp;amp; git commit -a --amend --no-edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command deserves attention because it is one of the most used commands for me. Most of the time I commit some changes and think that everything is in place, but suddenly I discover that I forgot a console.log, commentaries, and so on.&lt;/p&gt;

&lt;p&gt;Basically what he does is to add all changes to the last commit without changing the commit message.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rename = !git add -A &amp;amp;&amp;amp; git commit -a --amend
save = !git add -A &amp;amp;&amp;amp; git commit -m 'SAVEPOINT'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rename and save work together for me, the thing is that when you have changes they are not really saved and when you commit these changes they are now in a safer place. When working I use save to store information when I am going to leave for some time or stop working, but I always return and rename the last commit because you should never push a commit message ‘&lt;strong&gt;SAVEPOINT&lt;/strong&gt;’.&lt;/p&gt;

&lt;p&gt;If I have multiple saves I just do a &lt;strong&gt;&lt;code&gt;git rebase -i HEAD~N&lt;/code&gt;&lt;/strong&gt; and squash the ‘SAVE POINTS’ commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;restore = reset HEAD~1 --mixed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restore will simply uncommit the changes, but won’t throw away the changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;wipe = !git add -A &amp;amp;&amp;amp; git commit -qm 'WIPE SAVEPOINT' &amp;amp;&amp;amp; git reset HEAD~1 --hard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wipe I do not use a lot, but it is very useful. Wipe will add everything to a commit with a message of ‘&lt;strong&gt;WIPE SAVEPOINT&lt;/strong&gt;’ and then reset to the commit before the wipe.&lt;/p&gt;

&lt;p&gt;If you run &lt;strong&gt;git ll&lt;/strong&gt;, you will not see the commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;895e76a example@example.com 38 minutes ago (HEAD -&amp;gt; main) third file
86deb1b example@example.com 39 minutes ago second commit
d8fb730 example@example.com 39 minutes ago first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, if is not here, where can I find it? You can find typing &lt;strong&gt;git log — reflog&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git log --reflog
commit 06dae1107b534d48d0002e40ccd0a1cf8ac45c6f
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Wed Jan 12 15:58:57 2022 -0300
    WIPE SAVEPOINT
commit 895e76a4e71ecc4cc65de27e4429ffce165cccff (HEAD -&amp;gt; main)
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:36 2022 -0300
    third file
commit 86deb1bb03edabb56e4cb5d84289fe7ab3025607
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:10 2022 -0300
    second commit
commit d8fb730fe75482bdcc4cfd923ffdbdec95953a5a
Author: Marco Antonio Bet &amp;lt;example@example.com&amp;gt;
Date:   Fri Jan 7 15:52:02 2022 -0300
    first commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to see the commit content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git checkout 06dae1107b534d48d0002e40ccd0a1cf8ac45c6f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And to add the commit content to your working branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;➜ git cherry-pick 06dae1107b534d48d0002e40ccd0a1cf8ac45c6f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;As you can see git alias is very useful to short and to create new commands, the commands above are aliases that I personally use, but this should not prevent you from improving or creating your own git aliases.&lt;/p&gt;

&lt;p&gt;I hope I could make you more productive with git alias and understand better what is, how to use it, and edit it.&lt;/p&gt;

&lt;p&gt;Thank you so much and I am looking forward to see you soon. 😉&lt;/p&gt;

&lt;p&gt;If you like this article you can give a ❤️, and 🔖 for later in the save button.&lt;/p&gt;

&lt;p&gt;And if you like content about Git, Linux, Productivity tips, Typescript, and Python please follow me &lt;a href="https://dev.to/itsbetma"&gt;Marco Antonio Bet&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;All commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
[alias]
ss = !git status -sb
ll = !git log --pretty=format:'%C(blue)%h %C(cyan)%ae %C(green)%cr%C(red)%d %C(white)%s'
lg = log --all --graph --decorate --oneline --abbrev-commit
ac = !git add -A &amp;amp;&amp;amp; git commit -m
ck = checkout
ckb = checkout -b
staging = !git fetch &amp;amp;&amp;amp; git checkout origin/staging
main = !git fetch &amp;amp;&amp;amp; git checkout origin/main
amend = !git add -A &amp;amp;&amp;amp; git commit -a --amend --no-edit
rename = !git add -A &amp;amp;&amp;amp; git commit -a --amend
save = !git add -A &amp;amp;&amp;amp; git commit -m 'SAVEPOINT'
restore = reset HEAD~1 --mixed
wipe = !git add -A &amp;amp;&amp;amp; git commit -qm 'WIPE SAVEPOINT' &amp;amp;&amp;amp; git reset HEAD~1 --hard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Github with the full .gitconfig: &lt;a href="https://gist.github.com/itsbetma/a350dca5eb20e07e4b90d7372b64da45"&gt;https://gist.github.com/itsbetma/a350dca5eb20e07e4b90d7372b64da45&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To learn more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases"&gt;https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git-status"&gt;https://git-scm.com/docs/git-status&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/pretty-formats"&gt;https://git-scm.com/docs/pretty-formats&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://git-scm.com/docs/git-log"&gt;https://git-scm.com/docs/git-log&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>git</category>
      <category>productivity</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Automated Backups with cron and RClone</title>
      <dc:creator>Marco Antonio Bet</dc:creator>
      <pubDate>Sun, 14 Aug 2022 22:06:53 +0000</pubDate>
      <link>https://dev.to/itsbetma/automated-backups-with-cron-and-rclone-3do4</link>
      <guid>https://dev.to/itsbetma/automated-backups-with-cron-and-rclone-3do4</guid>
      <description>&lt;p&gt;This article will show you how to use RClone and cron to automated file backups in a Linux Operating System.&lt;/p&gt;




&lt;p&gt;It is Friday past 6 PM, and I needed to back up some work and school files to Google Drive. Yes, I use git for coding projects, but this kind of work is better kept in Google Drive. So I wonder if there was a quicker, simple, and automated way of doing backups to Google Drive, and interesting, I found RClone.&lt;/p&gt;

&lt;p&gt;In this article you will learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whats is RClone.&lt;/li&gt;
&lt;li&gt;What is cron.&lt;/li&gt;
&lt;li&gt;Basic usage of RClone and cron.&lt;/li&gt;
&lt;li&gt;How to automatically back up files every Friday at 6:30 PM.&lt;/li&gt;
&lt;li&gt;Cron logging.&lt;/li&gt;
&lt;li&gt;How to uninstall RClone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Whats is RClone?
&lt;/h3&gt;

&lt;p&gt;Basically, RClone is a command-line computer program that can manage, transfer and sync files from your computer to cloud storage, or even between two cloud storages.&lt;/p&gt;

&lt;h3&gt;
  
  
  Whats is cron?
&lt;/h3&gt;

&lt;p&gt;Cron is a command-line utility software with the main purpose of scheduling jobs. Jobs are cron command with two parts basically, the first one is the schedule expression ,  the last is the script to be executed. Usually, all Linux OS comes with cron installed, if not:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CentOS/RHEL 7/8/5&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

yum install cronie


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Ubuntu&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

apt-get install cron


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;With cron, you can schedule a command or a shell script to run at a specific time, and that is what we going to do. Schedule an RClone command to run every Friday at 6:30PM.&lt;/p&gt;
&lt;h3&gt;
  
  
  Setting up RClone
&lt;/h3&gt;

&lt;p&gt;To start, install RClone.&lt;/p&gt;

&lt;p&gt;For &lt;strong&gt;Linux&lt;/strong&gt;, macOS, and BSD, just run:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl https://rclone.org/install.sh | sudo bash


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After installing RClone, let’s run the RClone configuration command.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone config


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Here you will follow these steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Choose n for a New remote.&lt;/li&gt;
&lt;li&gt;Type the name of the new RClone config, for example, mygdrive.&lt;/li&gt;
&lt;li&gt;Type 15 to use Google Drive as remote storage.&lt;/li&gt;
&lt;li&gt;For the next two steps, just type enter to continue.&lt;/li&gt;
&lt;li&gt;Now choose 1 for full access.&lt;/li&gt;
&lt;li&gt;For the next two choices, just type enter to continue.&lt;/li&gt;
&lt;li&gt;Sign-in into your google account in the RClone popup.
Now you are ready to go.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Building a shell script to backup files to Google Drive
&lt;/h3&gt;

&lt;p&gt;We are going to build a shell script that contains RClone command lines to sync folders from my computer to the Google Drive storage.&lt;/p&gt;

&lt;p&gt;Open your terminal and type:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mkdir sh ; cd sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;You don’t need to create a sh folder in your $HOME directory, you can create in another place or even do not create, but it is a good idea to organize your scripts in one place. If you create in another place, just remind yourself to change the path in the next steps.&lt;/p&gt;

&lt;p&gt;Now if you want to use vim then:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

vim backup.sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;But if you want to use another text editor, just create a file named &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; in the &lt;strong&gt;&lt;code&gt;$HOME/sh&lt;/code&gt;&lt;/strong&gt; folder or any other place, but &lt;strong&gt;&lt;code&gt;$HOME/sh&lt;/code&gt;&lt;/strong&gt; will be my location for this article.&lt;/p&gt;

&lt;p&gt;With the &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; file opened, let's write a line of code that syncs a folder from my computer to the Google Drive storage.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone sync -v --create-empty-src-dirs /$HOME/Desktop/Work mygdrive:/Work


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Now let’s dive into the explanations of the command.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone sync


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Sync will copy the files from the source and send them to the destination, but will not modify the source, only the destination.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

--create-empty-src-dirs


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;By default empty folders in the source are not synced, so to work around, this flag creates empty folders in the destination.&lt;/p&gt;

&lt;p&gt;In the last part of the command, you have two paths separated by a space, the first one is the source path and the second one is the destination path. By now you should probably notice that the second path has a &lt;strong&gt;&lt;code&gt;mygdrive:&lt;/code&gt;&lt;/strong&gt; which is the same name as the &lt;strong&gt;&lt;code&gt;rclone config&lt;/code&gt;&lt;/strong&gt; name. So basically I am syncing data from my computer to Google Drive, using &lt;strong&gt;&lt;code&gt;mygdrive&lt;/code&gt;&lt;/strong&gt; configuration.&lt;/p&gt;

&lt;p&gt;You can have multiple RClone configurations and this allows you to sync or copy files, not just from your computer to the cloud, but from one cloud to another. Just like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone sync -v --create-empty-src-dirs mygdrive:/Work anothergdrive:/Work


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;To see if the backup.sh file works, just run the command below and check if the destination has changed.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

source backup.sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; working properly, let's understand how we can schedule the &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; to run every day.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final script:&lt;/strong&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone sync -v --create-empty-src-dirs /$HOME/Desktop/Work mygdrive:/Work
rclone sync -v --create-empty-src-dirs /$HOME/Desktop/School mygdrive:/School


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  Setting up cron to run Shell file
&lt;/h3&gt;

&lt;p&gt;To schedule any job in cron we need to edit the crontab file, and to edit this file, open your terminal and type:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

crontab -e


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you never used crontab, then you will have to choose a default text editor, in my case it is vim.&lt;/p&gt;

&lt;p&gt;It will open the crontab file with your default text editor. When the file is open you will see only comments.&lt;/p&gt;

&lt;p&gt;To schedule in cron you will need a specific type of expression. Below you will see the structure of the expression:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.---------------- minute (0 - 59)
 |  .------------- hour (0 - 23)
 |  |  .---------- day of month (1 - 31)
 |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
 |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed
 |  |  |  |  |
 *  *  *  *  *  command to be executed


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Examples — Expression to schedule a job (&lt;strong&gt;my_shell.sh&lt;/strong&gt;) to run every Monday at 8:49 AM is:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

49 8 * * 1 my_shell.sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;If you want to run a job (my_shell.sh) from Monday to Friday at 11:26 AM you can write:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

26 11 * * 1-5 my_shell.sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;More examples of expressions:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

0 * * * *     =&amp;gt; Every hour
*/2 * * * *   =&amp;gt; Every two minutes
0 9-17 * * *  =&amp;gt; At minute 0 past every hour from 9 through 17


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;For more examples or to test if your expression will return the same logic as you expect, go to &lt;a href="https://crontab.guru/" rel="noopener noreferrer"&gt;crontab&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;With the crontab file open, type the line below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

30 18 * * 5 /$HOME/sh/backup.sh


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;What this command does is, every Friday at 6:30 PM &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; will be called, and it will back up my files to Google Drive.&lt;/p&gt;
&lt;h3&gt;
  
  
  Tips — Where is the cron log file?
&lt;/h3&gt;

&lt;p&gt;By default the cron log file is located at:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/var/log/syslog


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And to see the cron log in this file, run the code below:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

grep CRON /var/log/syslog


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;or to continuously watch the file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

tail -f /var/log/syslog | grep CRON


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;This command will return something like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Dec 15 07:35:01 rainbowone CRON[242416]: (root) CMD (command -v debian-sa1 &amp;gt; /dev/null &amp;amp;&amp;amp; debian-sa1 1 1)
Dec 15 07:45:01 rainbowone CRON[245607]: (root) CMD (command -v debian-sa1 &amp;gt; /dev/null &amp;amp;&amp;amp; debian-sa1 1 1)
Dec 15 07:55:01 rainbowone CRON[248793]: (root) CMD (command -v debian-sa1 &amp;gt; /dev/null &amp;amp;&amp;amp; debian-sa1 1 1)
Dec 15 08:00:01 rainbowone CRON[249386]: (rainbow) CMD (/$HOME/Desktop/sh/daily.sh)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;These messages only show which command cron ran, if you want to see the &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; log you will need to personalize the &lt;strong&gt;&lt;code&gt;backup.sh&lt;/code&gt;&lt;/strong&gt; to create its own log file, and write the content of it.&lt;/p&gt;

&lt;p&gt;But assuming you want to log the cron message to a specific file, luck of yours I will show you how.&lt;/p&gt;

&lt;p&gt;First of all, open this file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

/etc/rsyslog.d/50-default.conf


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Uncomment the line that starts with #cron.* and then restart &lt;strong&gt;syslog&lt;/strong&gt; with:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo service rsyslog restart



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;After that you will see cron logs in &lt;strong&gt;&lt;code&gt;/var/log/cron.log&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;/var/log/syslog&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to uninstall RClone?
&lt;/h3&gt;

&lt;p&gt;It is very simple to uninstall RClone from a Linux operating system, first of all, let’s find where the rclone configuration file is, to find the file run the command below.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

rclone config file


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;It will list one or more RClone configuration paths.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Configuration file is stored at:
/home/$USER/.config/rclone/rclone.conf


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;To remove the configuration file:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo rm -rf /home/$USER/.config/rclone/rclone.conf


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;And to finally remove RClone form the system:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo rm /usr/bin/rclone
sudo rm /usr/local/share/man/man1/rclone.1


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;At this point, you are probably able to automate file backups with cron and RClone in a Linux operating system.&lt;/p&gt;

&lt;p&gt;If you like this article you can give a ❤️, and 🔖 for later in the save button.&lt;/p&gt;

&lt;p&gt;And if you like content about Git, Linux, Productivity tips, Typescript, and Python please follow me &lt;a href="https://dev.to/itsbetma"&gt;Marco Antonio Bet&lt;/a&gt;&lt;/p&gt;




&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/itsbetma" rel="noopener noreferrer"&gt;
        itsbetma
      &lt;/a&gt; / &lt;a href="https://github.com/itsbetma/CronAndRCloneTutorial" rel="noopener noreferrer"&gt;
        CronAndRCloneTutorial
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Repository for the How to use RClone and cron to automate backup in Linux.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;CronAndRCloneTutorial&lt;/h1&gt;

&lt;/div&gt;

&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/itsbetma/CronAndRCloneTutorial" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>productivity</category>
      <category>linux</category>
      <category>bash</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
