Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Questions tagged [cd-command]

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

0
votes
2answers
39 views

Unable to go inside directory on Debian 9

I am logged in as sudo user on Debian 9. When I do ls then it shows me there is a directory called vars If I do cd /vars then I get error bash: cd: /vars: No such file or directory If I do sudo ...
0
votes
1answer
30 views

Shell Script To CD and Run a Python Script

OK, I know that there is a lot like this question but I literally get nothing. The thing i need is a script that cd's to /home/project then runs python3 pyscript.py I created an alias to cd alias name=...
1
vote
1answer
19 views

How can I suppress printing the full path to subdirectories when using CDPATH=“.:/some/path”?

I want to use bash's CDPATH to point to a directory of symlinks to directories that I access frequently. However, doing: export CDPATH="~/symlinks" causes cd SUBDIR to stop working if ./SUBDIR and ~...
1
vote
2answers
58 views

How do I create a symbol to represent a path to easily cd into a directory?

In the same way that cd ~ directs you to your home directory, is it possible to create another symbol, @ for example, such that cd @ would take me to /my/working/directory?
6
votes
3answers
1k views

-bash: /bin/cd: No such file or directory - automatically execute ls after cd

I accidentially destroyed my cd command. I tried to automatically execute ls after cd is called. I found a post saying that I have to execute alias cd='/bin/cd && /bin/ls', but now I get -...
3
votes
1answer
46 views

Why does `cd` have no effect if output is piped?

I accidentally typed cd /tmp | tail which is of course not what I meant. But to my surprise, I then did not change directory. Why is this? For comparison cd /tmp > /tmp/foo does result in a ...
7
votes
5answers
1k views

$ find -exec cd => gives error: => find: ‘cd’: No such file or directory

When I run this command it works: $ find . -inum 888696 -exec ls '{}' \; Conversation.pst Outlook Data File Outlook Data File.sbd Trash Unsent Messages Inbox.pst Outlook Data File.msf ...
5
votes
3answers
75 views

Is there any case in which the `cd .` (single dot) command could be useful?

This should theoretically just be redundant since it changes into the current working directory. Anyway, is there any scenario in practice, where this command could be useful?
1
vote
1answer
67 views

Getting random “cd: Too many arguments.” error messages when using different commands

I am getting random "cd: Too many arguments." when using different commands, for example newgrp or when logging in. Here is a console log showing the issue along with the Linux version and shell type. ...
1
vote
1answer
39 views

cd to a path containing spaces using a path variable [duplicate]

I have a file containing a list of commands which I run from my .bash_profile as source my_cmds For eg: $cat my_cmds scripts=~/scripts assuming my $HOME is /Users/knayak, when I run cd $scripts ...
0
votes
3answers
50 views

Solution to change directory passing a directory pattern as the parameter

I'd like to get any script or Linux solution to implement changing directory passing not exactly a directory but a pattern as the parameter. Something like this: # Ex: I'd like to execute a "cd" to a ...
1
vote
1answer
68 views

Why does cd need execution permission of a directory? [duplicate]

From https://unix.stackexchange.com/a/350629/674 For directories, the execute permission is a little different; it means you can do things to files within that directory (e. g. read or execute them)...
1
vote
2answers
38 views

cd's '-e' option

According to the Bash manual page the -e option of cd leads to an unsuccessful return status after a successful directory change. If the -e option is supplied with -P and the current working ...
1
vote
1answer
67 views

Inconsistent behavior of Bash's `cd` with symbolic links [duplicate]

I am currently trying to wrap my head around the behavior of Bash's cd when it comes to symbolic links. By default, cd should follow the logical directory structure and should not resolve symbolic ...
0
votes
3answers
94 views

Change directory working directory for previous directory in Shell Script

Is there any way to achieve below.. I am stuck to perform my task. I have written shell script which gives me correct output only when the script is getting executed on same month below is the ...
0
votes
1answer
20 views

Alias CD to a directory that's name is included in current directory

I've been using cmake and creating a build folder for my cmake code and I want to easily cd to the build directory. I've been naming my build directory in this format: /parent/codeandsuch /parent/...
0
votes
5answers
275 views

Change directory using ls | tail -1

I want to go in the directory on the basis of highest directory number. Path: /home/cg/root/2018/01. Inside this path I have multiple directories as below 15 16 17 So on.. In this case highest ...
-1
votes
4answers
102 views

Need to change directory in bash script

I am trying to change a directory in a bash script in order to delete a file after it has been transferred. Here is my script and what I would like to do: Please see line 5: 1 #!/bin/bash 2 name=...
1
vote
2answers
827 views

curl -O : Why it's not possible to download file specific directory? [closed]

The man curl entry for curl -O says: If you want the file saved in a different directory, make sure you change cur‐ rent working directory before you invoke curl with the -O, --...
0
votes
1answer
26 views

cd fails when trying to enter maldetect version-agnostic directory

I'm installing Maldet on Debian 9.3: cd /usr/local/src wget http://www.rfxn.com/downloads/maldetect-current.tar.gz tar -xzvf maldetect-current.tar.gz cd maldetect-* bash ./install.sh While doing cd ...
1
vote
1answer
41 views

is there a way to `ls` midway through the path of a `cp` or `mv` command (i.e. without cd-ing to the directory in order to perform an `ls`)?

I'm looking for a more efficient way to check what directories and files exist midway through typing the path for a cp or mv command without having to cd to the folder and running ls, then returning ...
1
vote
2answers
59 views

Navigate to a directory from a favorites list [duplicate]

Like everyone, I use the cd builtin command to navigate my directory-structure. Tab-completion comes in handy. Sometimes I use pushd and popd to jump between directories. Some of those directories I ...
-1
votes
2answers
206 views

Can't access a folder with sudo

I have been using Linux for two years, but today I encountered a very strange thing. I have nginx deployed on one server, and this is its log folder: ♪ log l -d nginx drwx------ 2 nginx nginx 4.0K ...
1
vote
2answers
66 views

What happens when I try to change to a parent directory after it has been renamed?

I'm several child directories deep and I enter cd .. and receive this error: cd: ..: No such file or directory I am confused- of course there is a parent directory, I'm in it! A little digging ...
-3
votes
1answer
44 views

unable to do cd got file not found in PATH

Error: process caused \"exec: \\\"cd\\\": executable file not found in $PATH\"\n"} PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin From where cd will execute?
0
votes
3answers
75 views

What's the easiest way to cd to the deepest directory on an absolute path to a file?

For example, I may have the following on my clipboard: /Users/matt/widgets/file.txt And I want to change directory to: /Users/matt/widgets cd doesn't work: $ cd /Users/matt/widgets/file.txt bash: ...
0
votes
2answers
312 views

chroot with working directory specified

Say I want to write wrapper for chroot command with the possibility to set working directory otherwise preserving chroot semantics. Thus semantics should be: chroot.sh <chroot-dir> <working-...
23
votes
4answers
3k views

Why do I need to use cd “$@” instead of cd “$1” when writing a wrapper for cd?

Elsewhere I have seen a cd function as below: cd() { builtin cd "$@" } why is it recommended to use $@ instead of $1? I created a test directory "r st" and called the script containing this ...
2
votes
1answer
87 views

change of directory is very slow

from time to time changing to a directory (through terminal) launches git process which takes 100% of CPU time and up to 5-6 seconds during which my console is absolutely unresponsive. This doesn't ...
0
votes
1answer
138 views

Writing start script with different working directory

I installed octoprint to my raspberry pi earlier this year in order to control my 3d printers. I've been able to make the pi control 2 printers at once using octoprint. Also I've added a second ...
4
votes
2answers
106 views

Search for a specific file and change to its directory

What's the best way to go to a directory that contains a specific file? (Assuming we are starting at the root of where we wish to search). I'm using Cygwin. SOLUTION: My final solution was to put ...
-1
votes
1answer
32 views

Cannot Access Folder

I downloaded this folder using wget https://github.com/duxingkei33/orangepi_PC_gpio_pyH3 when I ls I can see the folder orangepi_PC_gpio_pyH3 however when I cd orangepi_PC_gpio_pyH3 I get error: ...
0
votes
1answer
103 views

How to put whereis result into cd? [duplicate]

My format is whereis directory | cd but I get no output (not even a warning). Where as you have other posts that require variables, my question asks how to do it without them.
0
votes
0answers
30 views

How to check if a subfolder exists and if so add it to the path automatically on cd? [duplicate]

On my Ubuntu machine, I have a lot of javascript / typescript projects. Each of npm's binary might have a global installation, like tsc at ~/.nvm/versions/node/v7.10.0/bin/tsc $ tsc -v Version 2.4.2 ...
0
votes
3answers
211 views

cd 3 times to great-grandparent dir

I have this: cd $(dirname $(dirname $(dirname "$0"))) && which will cd to project root. Is there shorthand for this somehow, where I can just be like: cd 3 && # not quite, but you ...
0
votes
1answer
594 views

sudo as user permission denied on command

Hi i'm having a real problem trying to run a script as root, the script is to use sudo to run wp-cli as the user required. The command I am using is sudo -u hstestsite1 -s "cd /home/hstestsite1/...
2
votes
2answers
86 views

Prevent or detect change directory action in a shell script

I have a library that accepts plugins. The plugins are shell scripts. I want to prevent the plugins from changing the current working directory for any command in the script. One thing I could do is ...
0
votes
2answers
74 views

difference between ~ and cd

I am wondering what is the difference between $ ~ and $ cd Both seems to go to the same directory.
15
votes
1answer
870 views

Different behaviour of cd with multiple arguments in bash releases

Posting it here something that is puzzling me; upgrading an application server from Jessie to Stretch broke a bash script. Upon investigation, we narrowed it to a change of behaviour of the cd ...
4
votes
3answers
423 views

How to omit the character $ when entering a path stored in a variable?

I have a frequently used directory. Suppose it is: /etc/insserv.conf.d/testname I set a variable in my /root/.bashrc: mydir=/etc/insserv.conf.d/testname Now, I can open this directory by this ...
1
vote
3answers
521 views

Create alias for desktop directory

If I type in cd Desktop, no matter what folder the terminal is currently open in, I want it to navigate to /home/bob-ubuntu/Desktop In my .bashrc file I have the following lines at the bottom: alias ...
4
votes
5answers
970 views

Immediately enter the last dir you renamed

I have a directory located inside /var/www/html. I renamed this directory with mv from example1 to to example2. How could I enter the newly named dir the moment the namechange was made? How would ...
1
vote
2answers
123 views

Remove directory part from current directory in zsh

Let's say I cd to /usr/local/bin but I want to change my pwd to /usr/bin, how can I do that with zsh? I know I can do things like cd /a/b/ and then cd b c in order to change my pwd to /a/b, but I can'...
0
votes
1answer
323 views

changing current directory from child process [duplicate]

How would you arrange for a shell script to be executed in a child process, while still being able to change the current directory of the invoking shell?
0
votes
3answers
1k views

Run shell script when navigating to directory with cd [duplicate]

Is it available to set script to run in a particular directory, when you cd into it? For example if /foo is a directory with git project, is it possible, when cd /foo automatically run git status or ...
3
votes
1answer
109 views

Automate cd into an archive directory under ~/.avfs

I use avfs to conveniently look inside archives from a shell prompt. This creates a view of the whole directory tree under ~/.avfs (so if a file /path/to/foo exists then it's also visible as ~/.avfs/...
2
votes
2answers
113 views

I have a command that outputs a directory and I want to cd into that directory

I was hoping I could just do cd | [my command] but it seems cd doesn't work from a pipe. I want to simply cd into the output of [my command] without writing a bash script of sorts I'm hoping there is ...
0
votes
1answer
337 views

Unable to move to an existing directory

Put simply, I have a file on my desktop that I'm attempting to access using cd /file name and I'm returned with: No such file or directory. I resorted to copying and pasting the directory (being ...
0
votes
1answer
229 views

how to cd to directory OR directory file is in? [duplicate]

If I do cd "user/Dropbox/foo.txt", I get -bash: cd: user/Dropbox/foo.txt: Not a directory. But my intention in this case is always the same: I want to cd to the directory the file is in. I tried this:...
0
votes
0answers
22 views

Directory name autocompletion with wildcards doesn't work in bash [duplicate]

If there are only 2 folders abc and def in the current directory, executing the command: $ ls a* and pressing TAB would autocomplete the name of the folder abc but executing $ cd a* and pressing ...