cd is the "change directory" command offered by most shells. For CD-ROMs, please use the [cd-rom] tag.
Questions tagged [cd]
673 questions
792
votes
32 answers
Why can't I change directories using "cd" in a script?
I'm trying to write a small script to change the current directory to my project directory:
#!/bin/bash
cd /home/tree/projects/java
I saved this file as proj, added execute permission with chmod, and copied it to /usr/bin. When I call it by:
proj,…
![](../../users/profiles/33203.webp)
ashokgelal
- 74,448
- 25
- 67
- 83
763
votes
14 answers
Equivalent of shell 'cd' command to change the working directory?
cd is the shell command to change the working directory.
How do I change the current working directory in Python?
![](../../users/profiles/28835.webp)
too much php
- 81,874
- 33
- 123
- 133
261
votes
4 answers
Change directory command in Docker?
In docker I want to do this:
git clone XYZ
cd XYZ
make XYZ
However because there is no cd command, I have to pass in the full path everytime (make XYZ /fullpath). Any good solutions for this?
![](../../users/profiles/1460614.webp)
RParadox
- 4,827
- 4
- 19
- 28
125
votes
4 answers
Change working directory in my current shell context when running Node script
I am trying to change the working directory of my Node.js script when it is run from a bin script. I have something like the following:
#!/usr/bin/env node
process.chdir('/Users')
When I then run this file with ./bin/nodefile, it exits, but the…
![](../../users/profiles/2433617.webp)
Jonovono
- 2,517
- 6
- 26
- 49
88
votes
7 answers
bash - how to pipe result from the which command to cd
How could I pipe the result from a which command to cd?
This is what I am trying to do:
which oracle | cd
cd < which oracle
But none of them works.
Is there a way to achieve this (rather than copy/paste of course)?
Edit : on second thought, this…
![](../../users/profiles/175296.webp)
Michael Mao
- 8,868
- 21
- 71
- 91
75
votes
5 answers
How to run 'cd' in shell script and stay there after script finishes?
I used 'change directory' in my shell script (bash)
#!/bin/bash
alias mycd='cd some_place'
mycd
pwd
pwd prints some_place correctly, but after the script finished my current working directory doesn't change.
Is it possible to change my path by…
![](../../users/profiles/90909.webp)
qrtt1
- 7,276
- 8
- 37
- 56
70
votes
3 answers
docker-exec failed: "cd": executable file not found in $PATH
I used this command:
docker exec compassionate_mclean cd /root/python
The error returned is
docker-exec: failed to exec: exec: "cd": executable file not found in
$PATH
Kindly help me out
![](../../users/profiles/1101251.webp)
sabarish
- 859
- 1
- 8
- 14
70
votes
4 answers
How do I find the current directory of a batch file, and then use it for the path?
I have a batch file that I intend to distribute to our customers to run a software task.
We distribute them as a folder or .zip with the files inside. Inside, there is the batch files and another folder with the files needed to run the…
![](../../users/profiles/2327428.webp)
Ryan Barber
- 715
- 1
- 6
- 7
66
votes
14 answers
How to cd into a directory with space in the name?
I'm attempting to get into the directory /cygdrive/c/Users/my dir/Documents:
$ DOCS="/cygdrive/c/Users/my\ dir/Documents"
$ echo $DOCS
/cygdrive/c/Users/my\ dir/Documents
$ cd $DOCS
-bash: cd: /cygdrive/c/Users/my\: No such file or directory
$ cd…
![](../../users/profiles/2316667.webp)
user2316667
- 4,826
- 11
- 40
- 68
65
votes
14 answers
Run cmd commands through Java
I found several code snippets for running cmd commands through a Java class, but I wasn't able to understand it.
This is code for opening the cmd
public void excCommand(String new_dir){
Runtime rt = Runtime.getRuntime();
try {
…
![](../../users/profiles/1086247.webp)
Reham
- 1,776
- 6
- 19
- 44
55
votes
7 answers
How to use "cd" command using Java runtime?
I've created a standalone java application in which I'm trying to change the directory using the "cd" command in Ubuntu 10.04 terminal. I've used the following code.
String[] command = new String[]{"cd",path};
Process child =…
![](../../users/profiles/451951.webp)
Antrromet
- 14,318
- 9
- 56
- 73
44
votes
2 answers
What does double slash // in `cd //` mean in Linux?
I've entered a command cd // instead of cd / by mistake and instead of getting an error as I'd expect the shell (Bash) showed a prompt as if I'm in the // directory:-
@://$
@://$ pwd
//
Listing the content of…
![](../../users/profiles/471164.webp)
vitaut
- 37,224
- 19
- 144
- 248
43
votes
14 answers
Go up several directories in linux
When I want to go one directory up I use
cd ..
But when I want to go 7 directories up is there any way to do this other than just typing seven (7) times cd .. ?
![](../../users/profiles/1568385.webp)
user15683854875644328975643872
- 561
- 1
- 6
- 15
39
votes
9 answers
One command to create and change directory
I'm searching for just one command — nothing with && or | — that creates a directory and then immediately changes your current directory to the newly-created directory. (This is a question someone got for his exams of "linux-usage", he made a new…
![](../../users/profiles/1943213.webp)
Autom3
- 413
- 1
- 4
- 8
34
votes
11 answers
"cd" does not work in shell script
I am wondering why cd does not work in shell script. It is as follows,
#!/bin/sh
cd test
mkdir $(date +%d-%mm-%Y)
When I run this, I get can't cd to test
cd: 2: can't cd to /test
Why is it like this?
![](../../users/profiles/163373.webp)
Abhishek
- 6,554
- 20
- 58
- 76