cd is the "change directory" command offered by most shells. For CD-ROMs, please use the [cd-rom] tag.
Questions tagged [cd]
737 questions
4
votes
1 answer
cd doesn't work when redirecting output?
Here's a puzzler: can anyone explain why cd fails when the output is redirected to a pipe?
E.g.:
james@machine:~$ cd /tmp # fine, no problem
james@machine:~$ cd /tmp | grep 'foo' # doesn't work
james@machine:~$…

James Brady
- 27,032
- 8
- 51
- 59
4
votes
1 answer
Shell Script thinks directory does not exist when running cd
I have a shell script (which I source into .bashrc) that allows me to jump to my projects directory from anywhere.
cdp(){
proj="~/dev/projects/$@/"
builtin cd $proj
}
_my_cdp()
{
local cur opts
cur="${COMP_WORDS[COMP_CWORD]}"
…

amflare
- 4,020
- 3
- 25
- 44
4
votes
3 answers
batch-file variable %CD% adding a backslash when run from drive root
I have a problem with the variable %CD% in a batch-file. It adds a backslash if the script is run from the root of a drive.
as an example: updatedir=%CD%\Update & echo %updatedir% will return something like
From a folder E:\New Folder\Update…

Mantis
- 41
- 2
4
votes
3 answers
bash script to create and cd to directory with spaces in name
I'm working on a project to remotely create a repository in my GitLab CE instance (that part is working!) and then to create a directory using the name of the project (working!) and cd into that directory (here's where I have the issue...) and then…

Thomas Ramage
- 73
- 1
- 9
4
votes
1 answer
Choose where to spawn a command in Yeoman
I'm building a generator and I need at the end to npm install in a certain directory in my app, I tried things like:
this.spawnCommandSync('cd', [this.destinationRoot() + '/my/folder'])
this.spawnCommandSync('npm', ['install'])
but it doesn't…

Calvein
- 2,111
- 13
- 28
4
votes
1 answer
eval commands with STDERR/STDOUT redirection causing problems
I'm trying to write a bash script where every command is passed through a function that evaluates the command using this line:
eval $1 2>&1 >>~/max.log | tee --append ~/max.log
An example of a case where it does not work is when trying to evaluate…

ProfessorManhattan
- 703
- 9
- 27
4
votes
2 answers
change directory in unix shell (special characters)
I have directory name starting with --. How to enter it with cd? Basic escape charaters is not working
# cd --smol--/
-bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]]] [dir]
# cd \-\-smol\-\-
-bash: cd: --: invalid option
…

petersmol
- 61
- 5
4
votes
4 answers
What is the difference between ~directory_name and /directory_name in linux
I am using a Mac OS 10.10.3 and I am new to using linux commands.
This is the doubt I have-
The present working directory:
/dir_name
when I run this command:
cd ~
The directory path changes to:
~dir_name
What does the ~ or / change in the directory…

Alex Jose
- 278
- 3
- 17
4
votes
2 answers
Error with cd Command with "-=" in the Target Directory's Name
I came across an interesting phenomenon when trying to use the 'cd' command with some of my directories.
I have named a number of my directories "-= [name]" so that they will be sorted to the top when I sort by name on a Windows machine at work. At…

yth
- 103
- 1
- 7
4
votes
2 answers
How can I wrap the current directory in strings in CMD?
I need to write a command which will change the current directory and print the NEW directory wrapped in some tags. I thought cd SOMEPATH & echo wkd%cd%wkd would do it but there is a problem.
Here is some example input and output
C:\Users> cd .. &…
user3018710
4
votes
1 answer
Set-Location scope
Given this file
Set-Location C:\
If I run it
.\foo.ps1
It will change the directory in the script. However once the script is finished the parent console directory has also been changed. Can Set-Location be called in such a way as to affect only…

Zombo
- 1
- 62
- 391
- 407
4
votes
4 answers
Change directory to a path specified in a file with tilde
I have a file, say: ~/cwd. The content of this file is a single line:
~/tmp
I want fo cd to this (~/tmp) dir. I'm trying:
> cd `cat ~/cwd`
And got:
-bash: cd: ~/tmp: No such file or directory
Why the RELATIVE paths failed? When the content of the…

egor7
- 4,678
- 7
- 31
- 55
4
votes
3 answers
Open CD/DVD door with a Windows API call?
How do I open the CD/DVD door with a Windows API call?

gemisigo
- 205
- 4
- 12
4
votes
1 answer
Access to CD-ROM using Java
I would like to ask if there is any possibility to access the cdrom device via sound libraries in Java.
What I want to do is to mute CD Analog. I've searched using google for a long time, but there is no information about such an operation. I assume…

rainbow
- 1,161
- 3
- 14
- 29
4
votes
5 answers
Bash function that changes directory
I have a common use case that I'd like to write a function for: I often want to cd to some directory relative to some file.
My current workflow looks like this:
$ gem which rspec/core | xargs echo -n | pbcopy
$ cd *paste and delete end until…

Joshua Cheek
- 30,436
- 16
- 74
- 83