Questions tagged [cd-command]

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

Filter by
Sorted by
Tagged with
120
votes
36answers
60k views

Quick directory navigation in the bash shell

I would like to frequently switch between directories that are in totally unrelated paths, for example /Project/Warnest/docs/ and ~/Dropbox/Projects/ds/test/. But I don't want to type cd /[full-path]/...
46
votes
6answers
12k views

cd .. on root folder

Why cd .., typed at root folder, does not warn or fails with an error? I would expect: /$ cd .. -bash: cd: ..: No such file or directory Instead, I'm left at /. Of course, this is since .. does ...
223
votes
6answers
227k views

How to go to the previous working directory in terminal?

In terminal, how can I define a key to go to the previous directory which I was in when changing directory with the cd command? For example, I'm in /opt/soft/bin and I cd into /etc/squid3 and I want ...
0
votes
1answer
46 views

How to use external command cd in bash?

I'm trying to use external cd (/usr/bin/cd) to jump to parent directory /usr/bin/cd .. but it doesn't work (no error message, current directory remains as was). I know this is a builtin bash command ...
-1
votes
4answers
88 views

Where is cd ~ located on Ubuntu?

What is the absolute path of cd ~ on Ubuntu? Trying to find out where this dir is located? For example: /home
4
votes
4answers
61k views

How to change the working directory for a shell script

I have a Python script that looks files up in a relative directory. For example: the Python script is in /home/username/projectname/. I have a file that is being called within the Python script that ...
0
votes
1answer
42 views

Passing a Directory to cd

I have a function, which I would hope would get me a fuzzy search on the latest directories I have been looking at and save me time, a simple 1 liner: dirs | sed 'y/ /\n/' | fzf | xargs cd 2 hours ...
2
votes
1answer
102 views

What is making “at” in AIX add a “cd /some/path/here” prior to my explicit commands?

When I execute the following command: cd /some/path/here at -t 201409301100 ls -al <CTRL-D> at -lov I get the following output: ======================== myusername.1411755840.a Mon Sep 30 ...
141
votes
4answers
90k views

Combined `mkdir` and `cd`? [duplicate]

is there any way (what is the easiest way in bash) to combine the following: mkdir foo cd foo The manpage for mkdir does not describe anything like that, maybe there is a fancy version of mkdir? I ...
4
votes
4answers
1k views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '/' and then choose the first result? I want to create a function that would cd down to a common ...
55
votes
10answers
154k views

Script to change current directory (cd, pwd)

I want to run a script to simply change the current working directory: #!/bin/bash cd web/www/project But, after I run it, the current pwd remains unchanged! How can I do that?
0
votes
2answers
103 views

How to execute a bash script, with it's arguments, on multiple directories? [duplicate]

I have a shell script app1.sh and a tree of folders, but I don't know how to execute this shell inside each folder. Here is This script recieves an string, an integer and a file as arguments to work....
1
vote
0answers
27 views

Oh My Zsh - execute ls after auto cd [duplicate]

Oh My Zsh has this lovely feature where you can just type dir-name instead of cd dir-name to access the directory called dir-name. In my old .bashrc I had a function that overwrites the builtin cd ...
364
votes
10answers
364k views

How do I use pushd and popd commands?

What are the practical uses of both pushd and popd when there is an advantage of using these two commands over cd and cd -? EDIT: I'm looking for some practical examples of uses for both of these ...
0
votes
2answers
1k 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-...
0
votes
0answers
18 views

Does zsh support tab completion when changing directories using path replacement? [duplicate]

I just started using zsh after being a bash user for over two years and out of the many great enhancements it offers, I am ecstatic over the path replacement capability when changing directories. But ...
3
votes
1answer
50 views

Change directories verbosely?

I am logging every action performed in a bash script to a logfile. I would like to have cd verbosely change directories so I can record the output to the log. Kind of like this: iMac:~ leetbacoon$ ...
2
votes
2answers
91 views

How can I combine the ssh and cd commands?

I am trying to write a bash-script to update a remote git repo. The script looks something like: #!/bin/bash ssh user@remote.de 'cd /home/h/usr/praktikum | git pull | sbatch run.sh' However, the ...
2
votes
3answers
112 views

Faster way to cd into a directory after listing the directory in a previous command?

I was looking for a file in a directory and so I used the find command which then showed the directory path of where the file is. ex. $find . -name file.txt /folder/path/file-contents/file.txt Now ...
6
votes
1answer
862 views

cifs: Cannot cd into a directory

For some reason I cannot cd into a particular remote directory for which I have access, it fails with: $ cd Data\ Services/ -bash: cd: Data Services/: Invalid argument This is how I mounted it: $ ...
0
votes
1answer
83 views

How to disallow 'cd ..' for a chroot user

I wanted to restrict a user from accessing files (just outside his directory), so I used chroot, and made the restricted directory as his landing directory upon logging in. But, If I do cd .. that ...
7
votes
1answer
567 views

Can I create a one way symlink?

I want to create a one way symlink i.e. I can use it to go to the destination directory but I cannot go back. Let's say there is a directory called D with two subdirectories S1 and S2. I want to ...
1
vote
2answers
53 views

Symlinked directories and output redirect

When I run the following command, where symlinked-dir is just that - a symlink to another directory, cat complains that there is no such file. There is, indeed, no such file - it's created in the ...
10
votes
1answer
1k views

“cd” into /sys/kernel/debug/tracing causes permission change

I've faced a really strange issue today, and am totally helpless about it. Some of the servers I manage are monitored with Nagios. Recently I saw a disk usage probe failing with this error: DISK ...
39
votes
3answers
11k views

gnome-terminal: keep track of directory in new tab

I'm on Arch linux, and when I open a new terminal tab, it always goes to $HOME. How can I make it so that when I open a new tab, it opens the shell in the directory I was in previously?
0
votes
3answers
67 views

How to copy a file to a destination folder and cd to the destination folder in one command

To explain my question, here is the dumb way of how I'm doing things: cp fileFromMyFriend.txt ~/my_first_subfolder/my_second_subfolder/more_subfolders cd ~/my_first_subfolder/my_second_subfolder/...
4
votes
3answers
3k views

Change directory based on a pipeline's output

I want to go to a directory with using filter For example there is a file named this-is-awsome ls | grep this-is-awsome | xargs cd How can I go to a directory with filter?
0
votes
0answers
55 views

Xargs and cd command [duplicate]

Can someone can explain me why the code below: echo "dir1" | xargs cd doesn't actually change working dir to dir1? It just return an error:xargs: cd: No such file or directory. Shouldn't the xargs ...
15
votes
3answers
4k views

Why did my folder names end up like this, and how can I fix this using a script?

Sorry if this has an answer elsewhere, I've no idea how to search for my problem. I was running some simulations on a redhat linux HPC server, and my code for handling the folder structure to save ...
2
votes
1answer
53 views

User Function to cd to nearest directory with given name

Would anyone have a user-defined function to put in my .basrc to do this. The following example should explain what I have in mind. Given the following file system: Level1 Level2 Level3 / ...
0
votes
1answer
261 views

The root directory and slash in cd command

I'm new to Linux and I want to understand this simple Linux command: cd /boot/../dev cd = change directory The first / = go to the root directory boot = is the name of a directory The second / = .......
1
vote
3answers
316 views

How to create bash alias on Ubunth WSL when username has space and apostrophe

I'm trying to create the following alias in Ubuntu WSL: alias windocs='cd /mnt/c/Users/Firstname L'astname/Documents/' My username is unfortunately Firstname L'astname, including the space and ...
75
votes
3answers
6k views

What is the point of the `cd` external command?

As referenced in this fine answer, POSIX systems have an external binary cd in addition to the shell builtin. On OS X 10.8 it's /usr/bin/cd. You can't use it like the builtin cd since it exits ...
1
vote
1answer
232 views

Not able to use cd Getting fatal: Not a git repository (or any of the parent directories): .git

I am using zsh on an Ubuntu 16.04 Since today I have not been able to use the cd command. Whenever I try to change my directory from the terminal I get this error fatal: Not a git repository (or any ...
9
votes
5answers
5k views

Can I hook into the cd command?

I'm trying to set something up on a server I run, when ever I cd into a public_html folder 95% of the time there's a few commands I will always run to check certain things. Is there anyway I can hook ...
0
votes
2answers
390 views

Change directory of remote machine through ssh after ~./bashrc execution

I am trying to run a script on a remote machine via ssh. For this I want to change the directory and run the script from there. I found that the standard method on how to do this is: ssh -Y -t user@...
1
vote
2answers
67 views

sh: is there a command to interactively edit the PWD?

I'm looking for a command that invokes readline or similar, primed with the current $PWD, to let the user edit the current directory, then cd to the edited value. E.g. > cd ~/a/b/c/d > pwd > ...
2
votes
1answer
97 views

Complete a command fully relative to a different directory

I have a function to run a single command in a different category. cd1 SOMEDIR MYCOMMAND ARG… is equivalent to (cd SOMEDIR && MYCOMMAND ARG…), with two advantages. It's slightly easier to type ...
23
votes
4answers
28k views

Alias to CD in a directory and call a command

I have a .bash_profile and in that I have a set of aliases. Those aliases at the moment execute only a single command and it was fairly easy. I would however like to do two things with a new alias ...
4
votes
2answers
210 views

Execute cd in two windows with one command

I used iTerm2. I often split the pane into two windows. When I want to change the directory in one, I want to also change the directory in the other automatically. Is this possible? A Tmux solution ...
62
votes
3answers
44k views

Difference between “cd -” and “cd ~-”

The Bash command cd - prints the previously used directory and changes to it. On the other hand, the Bash command cd ~- directly changes to the previously used directory, without echoing ...
0
votes
2answers
34 views

Convenient way to cd into a frequently-used dir? [duplicate]

A dir I cd into a lot has a really long path. I'd like to reduce keystrokes. I have tried this... sudo ln -s /mnt/c/Users/me/ho/hum/bin /mybin It works, but something about it seems wrong. Is ...
-3
votes
1answer
2k views

Not able to Run cd command with restricted user!

I have restricted a normal user to limited commands using rbash, now am not able to cd (change directory) to other directory,can someone help me how can i run cd command with restricted user, please ...
2
votes
0answers
33 views

Add file to PATH only when in specific directory [duplicate]

Is it possible to make executable appear in the global search path when I am entering to the some specific directory and get it removed once directory changed again?
0
votes
1answer
224 views

tcl cd/pwd command with regard to real/symbolic path

When I work under tcl environment, once I cd to a directory, even if the path I specify is its symbolic link, then no matter whether I run pwd -L or pwd -P, they all return the absolute path. This is ...
7
votes
3answers
9k views

How to go back n levels of directories from the command line?

For example, I do the following cds in succession- cd /tmp cd /home/admin cd /root/ cd /some_other/directory Now I am in /some_other/directory. Now, is there anyway to go back to /tmp, the directory ...
0
votes
1answer
177 views

Accessing network location on domain

My computer is connected to a university network, in the computer science department. This domain is called "cs". However, "cs" is a subdomain of the whole university network, "myuni". For example, ...
0
votes
1answer
503 views

When can a “cd” command fail in a shell script and what can I do to remedy it?

I have a shell script that failed to finish last week; it was a failed "cd" command and it exits if it fails. The script is a bash shell script for configuring new Debian installs. Here is the full ...
1
vote
1answer
44 views

Can't see a directory that's supposed to exist

So I own a device (casa node) which is basically a raspberry pi 3b+ with a hard drive and a modified OS (they call it CasaOS) and I want to edit a file. I found the location of this file by looking at ...
1
vote
2answers
1k views

cd in bash script without alias, function, source [duplicate]

I've written a bash script which should cd me to a directory. My problem is that only the directory in the subshell changes. I've read of many similar problems to this, but I want to know if there ...

1
2 3 4 5
7