Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [pushd]

The tag has no usage guidance.

2
votes
1answer
30 views

Can I rearrange the directories in `dirs` in the order of their most recent visits?

What is the order for the pathnames of the directories stored in the stack shown by dirs -l? Are they ordered by their last pushd commands? Is it possible to order them so that they are ordered by ...
-4
votes
2answers
50 views

Why does `pushd` always output the stack to stdout? [closed]

pushd push a directory into the directory stack, and change the working directory. I guess that is all we need. But besides, why does pushd always output the stack to stdout? I think that is ...
1
vote
1answer
161 views

Why can't I which pushd

I've been using pushd and popd for a long time while writing bash script. But today when I execute which pushd, I get nothing as output. I can't understand this at all. I was always thinking that ...
1
vote
1answer
115 views

`mktemp -d` followed by `pushd` works fine on command line, but not when in a script

If I paste these lines into a command prompt on Debian... DIR=$(mktemp -d -t bbbrtc.XXXXXX) || exit 1 echo "tmpdir = $DIR" cd "$DIR" They make a new temp directory, print the directory name, and ...
0
votes
2answers
341 views

Difference between pushd/popd and sub-shell+cd

I'm trying to understand if there are any benefits of using: pushd my_dir make all # ... or something else popd vs ( cd my_dir make all # ... or something else ) or is it merely a ...
0
votes
1answer
53 views

How shall we reproduce the stack in `dirs -v`?

I have a file whose content is the output of dirs -v, i.e. pathnames to directories: 0 ~/program_files/OS/dirs/recentVisitedDirs 1 ~/cs/security/computer security/OS security/user management/...
-1
votes
5answers
247 views

Are if-fi segments necessary when iterating on a pushd-popd directory list?

I use the following code which is part of this script that I use to update my WordPress websites: #!/bin/bash drt="/var/www/html" for dir in ${drt}/*/; do if pushd "$dir"; then wp plugin ...
0
votes
1answer
528 views

How does pushd work?

In Ubuntu 16.04 with Bash I had a problem when I didn't have a convenient way to upgrade all my WordPress components (core, translations, theme, plugin) and I used the following code to solve it: cat ...
-4
votes
2answers
44 views

How can I empty the `dirs` stack, without changing my current directory?

I have pushd several pathnames, so my dirs stack has multiple stack frames. Now I would like to empty the stack, without changing my current directory. I wonder how to do that? Thanks.
1
vote
1answer
220 views

dirs -v does not list the directory stack?

I have seen How do I use pushd and popd commands? , and I am aware that with pushd <dir> I would push <dir> to the directory stack, with popd I would pop the top directory from the ...
2
votes
2answers
459 views

How can I pushd a series of directories in one go?

I am in the directory foo which contains the subdirectories bar1 bar2 and bar3 and nothing else. I would like to act pushd on foo, bar1, bar2 and bar3 in one command, however I am encountering ...
4
votes
1answer
308 views

Making 'pushd' directory stack persistent

Ok this is a short question. I just happened to know that with pushd command, we can add more working directories into our list, which is handy. But is there a way to make this list permanent, so it ...
1
vote
0answers
928 views

Navigating the file system: Difference between CD and PUSHD [duplicate]

Being very novice in navigating the file system, I always use the CD command line to change directories. I just find out that there is another command called: PUSHD I am having hard time to ...
53
votes
3answers
32k views

Difference between “cd -” and “cd ~-”

The Bash command cd - prints the previously used directory and changes to it. On the other hand, the Bash command cd ~- directly changes to the previously used directory, without echoing ...
1
vote
0answers
37 views

How to get pushd programs to display directory abbreviations

I'm a big fan of using bash's pushd, popd, and dirs program set. However, I tend to use it so much, that the list of directories becomes too hard to read through. It would be nice if I could get the ...
2
votes
1answer
67 views

How to zip many n-th level subdirectories, without their top (parent) dir?

in such a filesystem structure: root/ | container1/ | | | subdir2/ | | | subdir3/ | | | ...
3
votes
3answers
279 views

Why doesn't shell expansion on popd remove a directory from stack?

When I use popd alone it removes a directory from the stack and takes me to that directory. However, if I do cd $(popd) then no directory is removed from the stack. Since the process is simply forked ...
1
vote
3answers
278 views

Is there a better way to unwind a deep pushd stack?

I sometimes encounter situations where something like this happens in a Bash script: pushd /tmp wget -q http://download.redis.io/redis-stable.tar.gz tar xzf redis-stable.tar.gz pushd redis-stable ...
1
vote
1answer
272 views

Oh-My-Zsh remove duplicated path in directory stack

Without Oh-My-Zsh, I can pushd two identical path: $ dirs ~ $ pushd Desktop Desktop ~ $ pushd ~ ~ Desktop ~ With Oh-My-Zsh: $ dirs ~ $ pushd Desktop Desktop ~ $ pushd ~ ~ Desktop How do I disable ...
3
votes
3answers
1k views

When using popd, how to push the current directory onto the stack?

When using popd, how to push the current directory onto the stack?
3
votes
1answer
338 views

removing duplicates from pushd/popd paths

Context linux bash pushd/popd/dirs Problem The problem scenario is very similar to the one stated in this question: removing or clearing stack of popd/pushd paths ... however the goal is not to ...
1
vote
1answer
283 views

How can I get a persistent dirstack with unique entries in zsh?

The Arch Wiki has this interesting bit of zsh configuration: DIRSTACKFILE="$HOME/.cache/zsh/dirs" if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then dirstack=( ${(f)"$(< $...
1
vote
2answers
189 views

Detect pushd depth in bash?

I would like to be able to programmaticly detect when my pushd stack is non-empty, within a bash shell. Is there any way to detect this? Something akin to $SHLVL would be nice. But so far, the only ...
11
votes
1answer
13k views

pushd, popd vs cd, cd- in bash and zsh

Is there a difference between the behavior of pushd/popd in bash vs zsh? It seems in zsh cd, cd- behaves exactly the same as pushd/popd (which adds/pops directory automatically when cd) while in bash ...
0
votes
1answer
499 views

Why is cd appending dirs like pushd?

I am using zsh in Babun (Cygwin with oh-my-zsh and some extras). I noticed some odd behavior, it looks like cd is behaving like pushd? { ~ } » mkdir foo { ~ } » pushd foo ~/foo ~ { foo } » popd ~ ...
2
votes
3answers
99 views

How can I view the stack used by `pushd` and `popd`?

I would like to use the recently accessed directories list for logging purposes. Is the directory stack as used by pushd and popd stored somewhere, perhaps as a list of folders in a text file? If so, ...
2
votes
2answers
230 views

How can I popd to a specific directory?

I have used pushd to move about to various directories and now if I run dirs -v I get: 0 ~/Desktop 1 /etc 2 /var/log 3 ~/Downloads 4 /tmp How can I popd to a specific directory in the ...
1
vote
1answer
2k views

-ksh: pushd: not found

I am trying to used pushd, popd and dirs in SUSE Linux but I am getting -ksh: pushd: not found while I try to check pushd which pushd which: no pushd in (/usr/bin:/bin:/usr/sbin:/sbin) I am ...
1
vote
2answers
994 views

Does pushd always push the current directory?

$ pwd /tmp/d1 $ dirs /tmp/d1 $ pushd ../d2 /tmp/d2 /tmp/d1 $ popd /tmp/d1 $ pwd /tmp/d1 It seems that pushd always pushes the current directory e.g. /tmp/d1 into the stack, although I run it as pushd ...
40
votes
13answers
10k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
3
votes
1answer
502 views

Persistent directory stacks across sessions in zsh

I would like to share my directory stack (the one accessed with dirs) across sessions and tmux panes/windows. In the zshbuiltins man page I have found autopushd to add every directory I switch into ...
0
votes
1answer
265 views

Using pushd and popd [duplicate]

Say I do the following: cd ~ pushd . cd /bin/ pushd . dirs "/bin/ ~/ cd ~/Downloads/ pushd . dirs ~/Downloads /bin/ ~" How would I popd back to something a while ago, say from downloads to the home ...
2
votes
1answer
158 views

bash - inherit directory stack in children

If, in my newly created bash, I do: pushd foo pushd bar dirs -l -v I will get something like 0 bar 1 foo 2 old_dir If I then do bash dirs -l -v I get only 0 bar The same thing happens if I ...
6
votes
2answers
3k views

Refer to an item in `dirs`

I use pushd to work with multiple directories in bash and zsh. I've aliased dirs to dirs -v so that I get an ordered list when I want to see what's on the directory stack: chb$ dirs 0 /Volumes/...
296
votes
9answers
312k views

How do I use pushd and popd commands?

What are the practical uses of both pushd and popd when there is an advantage of using these two commands over cd and cd -? EDIT: I'm looking for some practical examples of uses for both of these ...
5
votes
3answers
2k views

Conflict between `pushd .` and `cd -`

I am a happy user of the cd - command to go to the previous directory. At the same time I like pushd . and popd. However, when I want to remember the current working directory by means of pushd ., I ...
33
votes
2answers
8k views

removing or clearing stack of popd/pushd paths

After pushding too many times, I want to clear the whole stack of paths. How would I popd all the items in the stack? I'd like to popd without needing to know how many are in the stack? The bash ...