Questions tagged [cd-command]

cd is a shell built-in to change the working directory.

Change the working directory.

External reference

cd specification (The Open Group Base Specifications Issue 7, 2018 edition)

411 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
292
votes
7 answers

How to go to the previous working directory in terminal?

In terminal, how can I define a key to go to the previous directory which I was in when changing directory with the cd command? For example, I'm in /opt/soft/bin and I cd into /etc/squid3 and I want to get back to the first directory.
Hojat Taheri
  • 5,026
  • 6
  • 23
  • 22
245
votes
5 answers

What is the 'working directory' when cron executes a job?

I have a script that works when I run it from the command line, but when I schedule it with cron I get errors that it cannot find files or commands. My question is twofold: When I schedule a cron job using crontab -e, does it use my user ID as the…
ProfessionalAmateur
  • 3,115
  • 3
  • 18
  • 17
241
votes
4 answers

Combined `mkdir` and `cd`?

is there any way (what is the easiest way in bash) to combine the following: mkdir foo cd foo The manpage for mkdir does not describe anything like that, maybe there is a fancy version of mkdir? I know that cd has to be shell builtin, so the same…
Jasper
  • 3,538
  • 4
  • 16
  • 22
141
votes
11 answers

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
Sony Santos
  • 1,513
  • 2
  • 10
  • 7
140
votes
7 answers

Why is cd not a program?

I've always wondered why cd isn't a program, but never managed to find the answer. Anyone know why this is the case?
AkshaiShah
  • 3,599
  • 5
  • 18
  • 9
133
votes
36 answers

Quick directory navigation in the bash shell

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd /[full-path]/ all the time. Are there any shortcut commands to…
saiy2k
  • 1,593
  • 3
  • 11
  • 10
103
votes
10 answers

Does cd . have use?

One of the tutorials I've been following briefly stated that cd . has no use. When trying to replicate issue shown by OP in Symbolic link recursion - what makes it “reset”?, I also tried cd ., which showed the same effect OP described (growing $PWD…
Sergiy Kolodyazhnyy
  • 16,187
  • 11
  • 53
  • 104
98
votes
1 answer

Make cd follow symbolic links

I have my code mounted as an sshfs in my home directory, but the hierarchy is difficult to remember, so I created a symlink in my home directory leading to that directory. Is there a way so that when I cd to that symbolic link, instead of cding to…
rowantran
  • 1,805
  • 2
  • 13
  • 7
90
votes
11 answers

Execute a specific command in a given directory without cd'ing to it?

Is there a way to execute a command in a different directory without having to cd to it? I know that I could simply cd in and cd out, but I'm just interested in the possibilities of forgoing the extra steps :)
Naftuli Kay
  • 38,686
  • 85
  • 220
  • 311
87
votes
3 answers

What is the bash shortcut to change to the previous directory?

Sadly, I only learned about this last year by stumbling upon it randomly on the internet. I use it so infrequently that I always forget what it is by the time I need it again. How do you change to your previous directory?
hobodave
  • 1,173
  • 1
  • 7
  • 10
85
votes
3 answers

What is the point of the `cd` external command?

As referenced in this fine answer, POSIX systems have an external binary cd in addition to the shell builtin. On OS X 10.8 it's /usr/bin/cd. You can't use it like the builtin cd since it exits immediately after changing its own working directory.…
kojiro
  • 4,544
  • 4
  • 24
  • 32
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
66
votes
6 answers

Is there a way to cd back multiple times in bash?

I often use cd - to go back to where I was. How can I do this multiple times in bash? Or would zsh or some other tool support this?
timpone
  • 763
  • 1
  • 5
  • 8
66
votes
13 answers

Make cd automatically ls

I find that I often do the following: %> cd bla/bla %> ls I would like it that whenever I cd into a directory it automatically does an ls. I fiddled with my .bashrc for a while, but couldn't figure out how to make it happen.
RobKohr
  • 769
  • 1
  • 6
  • 4
1
2 3
27 28