Digital Communication


Digital Communication

pushd command: create and swap directories


With Linux pushd, you save directory paths, swap directories, and add them to your stack. These job steps can certainly be performed by other Linux commands, but in this context pushd has some advantages.

What is pushd command?

In Linux, pushd is one of the commands that many users do not use at all in their daily work. It’s all the more unfortunate as the command has a lot of potential and makes using the command line easier. The main function of Linux pushd is to save the path to the current directory and place it at the top of your stack. This allows you to easily return to a working directory.

The pushd command is not only part of standard Linux distributions, like Debian or Ubuntu, but it is also known from a few other operating systems.

How does Linux pushd work?

When you run the pushd command and create a specific directory as a parameter, it automatically becomes your current working directory. At the same time, the name and path of this selected directory are placed on the top of your stack. When you run pushd without further specifications, the directory at the top of your stack becomes your current working directory. The two directories at the top of the list therefore exchange positions. You can also use the cd command in Linux, but for large operations this often requires more executions. On the contrary, the pushd command leads directly to the intended objective.

What is the syntax of pushd command?

The syntax of pushd is always the same. The order is made up as follows:

$ pushd [Options] [Répertoire]


If you don’t create any directories, the directory at the top of your stack is automatically used.

What are the Linux pushd options?

Besides the standard “-h” and “-v” options, the pushd command has only one other option: with “-n” you can add a new directory to the stack without affecting your current directory. This means that the new directory slides to the second position on the stack and your current directory stays in the first position.

Examples of using the pushd command

So that you better understand how the pushd command works and see the advantages of this command, we present some examples.

With this command, the “Example” directory becomes your new working directory.

If you run this command, the Images directory is inserted into the second position of your stack. However, you continue to work in your current repertoire.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact