Questions tagged [pushd]

44 questions
468
votes
11 answers

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 commands or reasons for keeping stack with…
syntagma
  • 12,091
  • 21
  • 57
  • 74
85
votes
3 answers

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 anything. Is that the only difference? What is the use…
dr_
  • 28,763
  • 21
  • 89
  • 133
59
votes
15 answers

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?
Tim
  • 98,580
  • 191
  • 570
  • 977
58
votes
2 answers

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 manual doesn't seem to cover this. Why do I need to…
chrisjlee
  • 8,283
  • 16
  • 49
  • 54
51
votes
1 answer

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 cd doesn't affect the dir stack. If someone can…
dragonxlwang
  • 683
  • 1
  • 5
  • 8
7
votes
3 answers

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, where?
B.Kocis
  • 227
  • 1
  • 6
6
votes
2 answers

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/banister/grosste_daever_gh/2013-03-27/reader 1 …
chb
  • 584
  • 7
  • 17
6
votes
1 answer

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 can survive reboots or logoffs?
Sollosa
  • 1,887
  • 4
  • 19
  • 32
5
votes
1 answer

How is the pushd directory stack stored?

In a related question somebody states that the directory stack of the pushd command is emptied when your shell terminates. But how is the stack actually stored? I use fish instead of bash and the commands work the same way. I would assume pushd (and…
jallersma
  • 55
  • 1
  • 3
5
votes
3 answers

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 lose the possibility to go to the previous…
Bernhard
  • 11,992
  • 4
  • 59
  • 69
5
votes
1 answer

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 clear the stack, but rather to prune it.…
dreftymac
  • 717
  • 2
  • 7
  • 10
3
votes
1 answer

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 their most recent visit times (a natural extension…
Tim
  • 98,580
  • 191
  • 570
  • 977
3
votes
3 answers

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 and the result is put in place of the shell…
Adam Thompson
  • 885
  • 1
  • 9
  • 18
3
votes
3 answers

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

When using popd, how to push the current directory onto the stack?
user176549
  • 31
  • 1
  • 2
3
votes
2 answers

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 middle of the stack?, e.g option 2: /var/log man bash…
the_velour_fog
  • 11,840
  • 16
  • 64
  • 109
1
2 3