pushd and popd – File Navigation Gems

pushd and popd are two commands that are absolutely worth their learning time if you are in the business of using the command line on a regular basis on linux. One of the biggest hindrances of using a command line for file manipulation and such would be navigation between folders. Sometimes its might be a pain to navigate between two folders, even using TABs for auto completion. This is where pushd and popd comes in to the picture.

What this does, in short, is, create a stack containing the paths that you have traversed using pushd. You can revisit these paths using popd. Remember that this is a stack in all aspects.

A short intro on how a stack works, if you haven’t come across it already. Skip this paragraph if you know what a stack is. Stack is a data structure that is like a stack of books or a stack of biscuits or best, pringles. You can stack one item on top of each other, but you can only take the item on top. Logical  right?. You stack an item using push. As in, pushing a potato chip into a pringles case. And you take one out using pop. Of course, you can only take the one on the top, a position called the ‘top of stack’.


Suppose you are in your home folder (~). You move to another directory by typing,

Command: pushd ~/Documents/work-docs

This will give you an output with two directory listings. The first one is the directory that you have navigated ‘to’. The second one is the directory that you just navigated ‘from’.

Output: ~/Documents/work-docs ~

You can navigate to another folder with something like say,

Command: pushd ~/Downloads

Now you will have the following output

Output: ~/Downloads ~/Documents/work-docs ~

What this shows is a history of your past navigations, or a ‘stack’ of your previous directories. The top of stack being the left most. Now to go back one step to ~/Documents/work-docs/, all you have to do is type,

Command: popd

and it will give you the following output

Output: ~/Documents/work-docs ~

That would be a quick intro of pushd and popd. Have a good time navigating through your directories.


Sync files to Google Drive from Linux – Command Line Utility


The Need
I wanted to sync some of my files to google drive easily. I wanted it to create folder structures on its own as well. I guess you have a gui utility for ubuntu but could not find an rpm file for fedora or a source. Also i wanted a Commang line utility, something like git.

The Solution
So i came across this lovely tool called grive2. Bingo. Perfect.

You can install it using the package manager. As simple as

dnf install grive2

(it should be listed as grive2.x86_64 : Google Drive client in your package manager)

Working it
Now that you have installed it how do you sync it. There are two steps to this process, the authentication step and the syncing step. Although it seems like a single step process when you first do it because when you do the authentication it automatically syncs it.

All you have to do is cd to the folder that you want to sync and then type in

grive -a

when you do that you will be prompted with a link along with an open prompt to paste an authentication code. Copy and paste that link in a browser and you will be asked to authenticate grive to access your google drive. Accept it and you will get the authentication code that you need. Copy this and paste it in your terminal where your prompt is waiting for you to come back. Then you are done.

grive is now looking at the current folder you are on and also your google drive to see if the content/folders in the current folder are already there. Since this is your first time there is no chance that it is already there so it uploads all that is in the current folder to google drive. Once that is done it starts downloading what is in google drive to the current folder since you don’t already have those here. Syncing is a two way road, both uploads and downloads happen.

The next time you sync you just need to go to the same folder and say


and it does the same without any authentication

Type in grive --help for more options


Tricky Bit – Being Specific
Now is the tricky bit. I did not need these downloads to happen. My want was very specific. I just wanted to sync what is in a particular folder of mine in my pc up to google drive and then in the future when ever i made changes to “this particular folder” in my local drive or google drive i wanted it to sync that. Many of you might want the same too. You would have loads of stuff on your google drive. Why sync everything!

So the way around this is the mighty ‘-s’ parameter that lets you specify a specific folder that you wanted to sync. So what did i do.

Example say that my folder, lets call it MyFolder is in home/me/Documents. This MyFolder of mine contains all the files that i want to sync to grive. Then what i would do is cd to Documents and do

grive -a -s MyFolder/

Now this would authenticate this folder(Documents) but only sync the MyFolder folder. Again, when i want to sync this folder again i would go to Documents and say

grive -s MyFolder/

it would now sync what ever changes i made whether in my local or in my server, deleting and uploading as necessary. “Deleting and Uploading as necessary” is one of my favorite aspects. Although thats what syncing is. Ironic. 🙂


Using the vi editor (Short Version)

The vi editor has two modes
1) The Command mode
2) The Insert mode

with the Command mode you can move around the file with the arrow keys and you can use the del key or keys like x to delete letters.

with the Insert mode you can insert characters using the keyboard.

Note: You cannot enter any letters when you are in the command mode. You must enter the Insert mode before typing in anything.

Common Task:

Say you want to delete a particular letter or a word and then insert some other word in its place. This is what you would do

By default the vi editor starts up with the Command mode.
Move your cursor to the letter you want to delete and press ‘x’ or ‘del’ key.
This will delete the letter.
Press ‘i’ to enter into the Insert mode.
Now your keyboard can enter alphabets and numbers.
Insert the content you want.
Press ‘Esc’ key to go back to the Command mode.
Remember that to delete a letter you should go to the command mode.

Note: To Undo a particular typo or a delete, press ‘u’ in the command mode to undo. Works like any other word editor.