cd is the "change directory" command offered by most shells. For CD-ROMs, please use the [cd-rom] tag.
Questions tagged [cd]
673 questions
10
votes
6 answers
How to make an html page open automatically on a CD/DVD
I need to include an html page (table of contents) on a CD/DVD. I'd like the html page to open automatically when the user puts the CD/DVD in their machine. Is there a way to do this (the MSDN cds do this) either by purchasing software or…
Sam
10
votes
1 answer
How POSIX compliant is "/path/file/.."?
I wanted to change current directory into shell script into directory, containing specific regular file. I found that following trick works in mksh and busybox sh:
path=/path/to/regular/file
cd $path/..
but not in GNU Bash:
bash: cd:…
![](../../users/profiles/10998312.webp)
KAction
- 525
- 2
- 9
10
votes
1 answer
cd into a directory without knowing its name in bash
If I know there will be a single folder inside a directory, but I do not know it's name, is there a simple way in bash to go into it? If I wanted to do a check to make sure a folder exists within the current directory, can that be done?
![](../../users/profiles/3475234.webp)
user3475234
- 1,353
- 3
- 19
- 34
10
votes
6 answers
In CMD / .bat I can change dir from C to D but not other way around?
Ok so here is a copy-paste of my CMD window
C:\Documents and Settings\Developer>cd /d "D:\"
D:\>cd /c "C:\"
The filename, directory name, or volume label syntax is incorrect.
D:\>
when I run cd /d "D:\" in C drive it works fine,
but when I run cd…
![](../../users/profiles/2186340.webp)
Andre
- 631
- 6
- 14
- 29
10
votes
5 answers
Bash script to change parent shell directory
What I'm trying to do
I've created a shell script that I've added to my $PATH that will download and get everything setup for a new Laravel project. I would like the script to end by changing my terminal directory into the new project folder.
From…
![](../../users/profiles/107870.webp)
michaelespinosa
- 475
- 2
- 5
- 14
10
votes
2 answers
Difference between cd and function chdir
What is the difference between the cd shell command and the Perl function chdir? Please can you explain with an example?
![](../../users/profiles/1030542.webp)
iDev
- 1,717
- 5
- 31
- 52
9
votes
6 answers
Stay in directory changed after ending of bash script
My bash script:
#!/bin/bash
cd /tmp
Before running my script:
pwd: /
After running my script:
pwd: /
After runnig my script trough sourcing it:
pwd: /tmp
How I can stay at the path from the script without sourcing it ?
![](../../users/profiles/130024.webp)
astropanic
- 10,140
- 17
- 64
- 128
9
votes
2 answers
What is the reason for the CD /D switch in Windows cmd?
At first I'd like to say that I do understand the purpose of the /D switch for the Windows Command Prompt cd command. I'm just curious why it works this way, and not other. As we all know, it does the following:
Use the /D switch to change current…
![](../../users/profiles/2004438.webp)
kefir500
- 3,551
- 6
- 34
- 41
9
votes
3 answers
system("cd ") in a C program
I'm trying to use the system() function in a C program.
For example, I tried to create a directory on my desktop, using the system() function.My code:
#include
#include
int main(void)
{
system("cd…
![](../../users/profiles/3096157.webp)
Programmer
- 700
- 1
- 9
- 15
8
votes
7 answers
A bash one-liner to change into the directory where some file is located
I often want to change to the directory where a particular executable is located. So I'd like something like
cd `which python`
to change into the directory where the python command is installed. However, this is obviously illegal, since cd takes…
![](../../users/profiles/74493.webp)
bsdfish
- 2,416
- 1
- 21
- 20
8
votes
2 answers
git init, add, commit from a different directory
I am writing a Lua script that creates a directory, creates some files inside of it and initializes git, adding those files to it and finally committing everything. However there's no way to use cd from inside Lua (you can, but it won't have…
![](../../users/profiles/6245072.webp)
user6245072
- 1,841
- 15
- 30
8
votes
3 answers
Change cd default directory (bash)
I'm looking for a way to change the default directory of cd, and I'm wondering if this is possible. I tried adding
alias "cd=cd ~/Documents/Github"
to .bashrc, but this obviously doesn't work because it breaks the cd command so that you cannot use…
![](../../users/profiles/3082194.webp)
Jay
- 889
- 1
- 10
- 20
7
votes
1 answer
Find location of current script (mlx-file) in MATLAB
I'm working on my MATLAB code in a number of different locations, and it would be really helpful if I could make the code aware of its location on the computer. Till now I worked with .m-files. For .m-files I found the following solutions:
%example…
![](../../users/profiles/6272965.webp)
KLJ
- 131
- 1
- 10
7
votes
2 answers
bash expand cd with shortcuts like zsh
Is it possible in bash to expand something like
cd /u/lo/b
to
cd /usr/local/bin
?
![](../../users/profiles/3575698.webp)
hasan
- 524
- 3
- 12
7
votes
4 answers
'cd' option to change to the previous directory
I remember there was a way to execute the cd command, automatically returning to the previous directory (without an explicit cd ...).
Is it possible?
![](../../users/profiles/169754.webp)
Roberto Aloi
- 28,818
- 19
- 65
- 109