Questions tagged [cd]

cd is the "change directory" command offered by most shells. For CD-ROMs, please use the [cd-rom] tag.

737 questions
28
votes
4 answers

get back to the previous location after 'cd' command?

I'm writing a shell script that needs to cd to some location. Is there any way to get back to the previous location, that is, the location before cd was executed?
One Two Three
  • 22,327
  • 24
  • 73
  • 114
22
votes
4 answers

Execute a bash function upon entering a directory

I'd like to execute a particular bash function when I enter a new directory. Somethink like: alias cd="cd $@ && myfunction" $@ doesn't work there, and adding a backslash doesn't help. I'm also a little worried about messing with cd, and it would be…
Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
22
votes
6 answers

How to set the default directory of the cd command in Windows cmd terminal?

The cmd command cd takes me to a directory I never spend any time in. I would like it to take me to C:\Users\Kacy\Documents\ by default. Unfortunately, set cd = C:\Users\Kacy\Documents\ does not work. Is there a simple way to change this setting…
Kacy
  • 3,330
  • 4
  • 29
  • 57
21
votes
1 answer

Tweaking Bash 'cd' and TAB completion to recognize spelling mistakes

I was looking for a tweak to the cd command so that it recognizes spelling mistakes of directories and auto complete similar directory names. Right now, I have settings that recognize the spelling mistakes of directory but does not auto complete…
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
20
votes
2 answers

What is the reason for the CD /D switch in Windows cmd?

First I would like to note 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 otherwise. As we know from the help: Use the /D switch to change current drive in…
kefir500
  • 4,184
  • 6
  • 42
  • 48
20
votes
2 answers

Is there a hook in Bash to find out when the cwd changes?

I am usually using zsh, which provides the chpwd() hook. That is: If the cwd is changed by the cd builtin, zsh automatically calls the method chpwd() if it exists. This allows to set up variables and aliases which depend on the cwd. Now I want to…
Stefan Majewsky
  • 5,427
  • 2
  • 28
  • 51
19
votes
3 answers

How to push a commit to Github from a CircleCI build using a personal access token

When executing a build for git repository giantswarm/docs-content in CircleCI, I'd like to push a commit to another repository giantswarm/docs. I have this in the deployment section of circle.yml: git config credential.helper cache git config…
Marian
  • 14,759
  • 6
  • 32
  • 44
16
votes
3 answers

How to `cd` into directory with the name `-`?

Here is an example. I'm creating a directory named - and I can't cd into it. The command cd - returnes me to the previous directory. And I'm a bit supprised that cd "-" works the same way. I can enter that directory using the full path ~/-, but is…
bessarabov
  • 11,151
  • 10
  • 34
  • 59
15
votes
3 answers

Bash script awkwardness with pwd

I've got a strange issue while working with a bash script. Here it is: PWD=${pwd} # several commands cd /etc/nginx/sites-enabled/ # more commands cd $PWD # I expect that I returning to my directory, # but $PWD contains current dir -…
Vasiliy Stavenko
  • 1,174
  • 1
  • 12
  • 29
13
votes
10 answers

Make a CD run once

We're doing an "Amazing Race" kind of event, and thought it would be cool to have CDs that could only play once... like a "this message will self destruct in 5 seconds..." Any thoughts on how to do this? I was thinking it could be a compiled HTML…
Nathan DeWitt
  • 6,511
  • 8
  • 46
  • 66
13
votes
5 answers

Linux: Run a binary in a script

i want to run a program via script. normally i type ./program in the shell and the program starts. my script looks like this: #!/bin/sh cd /home/user/path_to_the_program/ sh program it fails, i think the last line went wrong... i know this is…
co-worker
  • 213
  • 2
  • 3
  • 5
13
votes
1 answer

How to run npm install without changing working directory

How to install dependencies for project without changing working directory to project root? Curently you need to execute: cd /my/project/root && npm install && cd - I'm looking for an option like -C for Makefile so that I can: npm install -C…
Aalex Gabi
  • 1,525
  • 1
  • 18
  • 32
13
votes
3 answers

implementing cd system call using C- if condition

Here is code that implements the cd system call using C. The problem with this code is that it's not entering the if condition if(strcmp(buffer,"cd") == 0) and I can't understand why. #include #include #include…
Urvah Shabbir
  • 945
  • 2
  • 15
  • 46
12
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…
Programmer
  • 750
  • 2
  • 9
  • 17
12
votes
1 answer

Run two commands with a crontab

I have a quick question. I need to add a cron to my debain crontab using an automated shell script and I need the cron to do two things: cd into /etc/application run the command "scrapy crawl" crontab -l | { /bin/cat; /bin/echo "* 3 * * * cd…
J.Zil
  • 2,397
  • 7
  • 44
  • 78
1
2
3
49 50