Questions tagged [cd-command]

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

Filter by
Sorted by
Tagged with
4
votes
4answers
3k views

Pass output of “whereis” command to “cd” to change directory in one step

I can't find a way to pass output of whereis command to cd command in same line so I don't have to do cd in the second step. I have tried passing like below: cd $(whereis node_modules) Or cd "`...
-1
votes
1answer
15k views

I cant cd hidden files/dir

I have been working on git a little bit and i tried to cd into /home/pi/Desktop/python_git/.git But it complained there was no directory called /.git. I know that this is because it begins with a . ...
30
votes
8answers
30k views

How can I open a new terminal in the same directory of the last used one from a window manager keybind?

I'm using a tiling window manager and I switched from gnome-terminal with multiple tabs to multiple urxvt instances managed by the window manager. One of the features I miss is the ability to open a ...
2
votes
1answer
32 views

Why do I get an error when using cd as env's utility argument? [duplicate]

I'm studying the env command and trying to understand how it works. Here's the command synopsis: env [-iv] [-P altpath] [-S string] [-u name] [name=value ...] [utility [argument ...]] I decided to ...
85
votes
10answers
231k 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?
63
votes
6answers
19k views

Is there a way to cd back multiple times in bash? [duplicate]

I often use cd - to go back to where I was. How can I do this multiple times in bash? Or would zsh or some other tool support this?
2
votes
1answer
68 views

change directory based on file shell script

Firstly come background I am trying to write an executable shell script I can easily map as the default for .tgz files to auto-extract. so far so simple tar -xzvf $1 which works to drag/drop but not ...
55
votes
12answers
56k views

Make cd automatically ls

I find that I often do the following: %> cd bla/bla %> ls I would like it that whenever I cd into a directory it automatically does an ls. I fiddled with my .bashrc for a while, but couldn't ...
8
votes
3answers
2k views

is there a way to cd into a directory based on the last characters?

I have directories that begin with 164 but they differ based on the last few digits. I would like to cd into a directory based on the last few digits if not the last digit itself, say 9 vs 8. The ...
397
votes
10answers
396k 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 ...
7
votes
2answers
15k views

How do I access a folder which I can't sudo cd into?

I'm trying to change my directory to /boot/efi, but running sudo cd /boot/efi does nothing. I'm on fedora 23. Is there a more powerful command for this?
2
votes
1answer
38 views

How to get recent places in terminal/shell?

Is there any way to get a list of the most recent 'places' (directories) have been navigated in terminal (osx)? I mean, I'd like to open my terminal, tipe some command, get the last 2 or 3 places I've ...
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-...
10
votes
5answers
599 views

Changing directory by changing one early word in a pathname

How do I change to a near-identical path with a different low-level parent? If you’re working in for instance ~/foobar/foo/data/images/2020/01/14/0001/ and need to get to the same path in bar instead ...
0
votes
1answer
50 views

Unix Executable to the directory it is housed in Mac

I am trying to make an executable script on Mac where it makes the directory it is housed in the current directory (cd) and then runs some more commands. I started with a find command however in the ...
1
vote
2answers
46 views

issues Debugging cd on custom shell [closed]

I am having issues with my custom shell cd command I created. Right now I am testing the base case where cd is the only argument, when that is the case its suppose to change the default directory to ...
5
votes
1answer
900 views

How do I cd up and down again with symlinks in bash?

Structure: /base/ +- somedir/ +- symlink/ -> /some_other_dir This command (in addition to my Makefiles) fails: cd /base/symlink ls ../somedir Bash complains that ../somedir does not ...
1
vote
0answers
22 views

Is it possible to directly access files out of a symlink-directory? [duplicate]

Say I have this directory structure: foo │ ╲ bar baz │ ╲ wun ← wunl │ blarg Here, wunl is a symlink pointing to ../bar/wun. Now I can $ cd foo/baz/wunl/blarg At this point, I'm not “actually” ...
12
votes
5answers
6k views

How do I use `find` to go to directory of that file

I want to find a file and then enter the directory containing it. I tried find /media/storage -name "Fedora" | xargs cd but of course, I the is not a directory error. How do I enter its parent ...
-3
votes
2answers
50 views

Add a directory to path

I would like to know how to add a directory to path (such as my Downloads folder) so that whenever I type cd Downloads from whatever directory, I go to ~/Downloads.
0
votes
4answers
42 views

Changing to a frequently used directory easily

Every time I need to go to a new directory I give the command cd and the name of the directory and ls to see the contents inside it. Is there any method or command to directly go the directory of my ...
250
votes
6answers
262k 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 ...
1
vote
1answer
35 views

How to navigate to a filesystem

I am using a cloud linux desktop and when I typed in df -h I get a list of filesystems as so: Filesystem Size Used Avail Use% Mounted on /dev/xvda1 9.8G 4.5G 5.3G 47% / tmpfs ...
1
vote
6answers
688 views

How can I go to a directory at a certain depth in the current tree?

I generally work within multiple folders (dev1, dev2 and dev3) in the same server. The folder structure is something like: /var/www/html/dev1/a/b/c/d/e/f /var/www/html/dev2/a/b/c/d/e/f /var/www/html/...
-1
votes
3answers
6k views

How to change to home directory using “cd” and a relative path?

I am doing an assignment that requires me to change in to my home directory from my current directory which is ~/sample_dir1/sample_dir/cambridge. It asks me to change to my home directory using a ...
2
votes
1answer
403 views

Call vared and complete files from a different directory

I have the following zsh function which lets me edit symbolic links using the vared ZLE builtin. function lned { emulate zsh setopt err_return extended_glob local_options local_traps local -a ...
0
votes
1answer
28 views

Accidently use “mv” command on home directory

I was in my home directory and then I typed cd .icons/a_folder/ For a weird moment, I typed mv ../.. instead of cd ../.. I do not know why I made that mistake, but since ../.. was my home directory ...
0
votes
1answer
68 views

How to find a file and make that the current working directory (cd)

I am trying to make an executable script on Mac where it searches for a file and makes that the current directory (cd) and then runs some more commands. I started with find . -type d -name "...
2
votes
3answers
153 views

Has “cd .. .. ..” ever worked for going up 3 directories?

I was reading a book published in 2018 titled "Linux Basics for Hackers: Getting Started with Networking, Scripting, and Security in Kali" from no starch press. And this was written there ...
127
votes
36answers
63k 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]/...
-1
votes
1answer
119 views

Add variable to cd directory path

I know these questions might have been asked somewhere but their solutions don't really work. I need help. I want to add a variable to a directory name then change directory to it. The approach below ...
0
votes
2answers
31 views

I copied a file into my VM, but the folder is a regular file

I'm new to Linux, and I'm trying to untar the following file, so I moved from GCS to the Virtual Machine with the following command gsutil cp gs://ghtorrent_datadump/mysql-2020-07-17.tar home/...
2
votes
4answers
351 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 ...
1
vote
4answers
57 views

Taking a File Argument and Moving to That Directory? [duplicate]

Is there a Unix command or shell script that takes a file argument and moves to the containing directory, ignoring the file part of the argument altogether?
13
votes
3answers
916 views

What is an “alternative directory name” in CDPATH for the cd command?

In the cd, bash help page: The variable CDPATH defines the search path for the directory containing DIR. Alternative directory names in CDPATH are separated by a colon (:). A null directory name is ...
9
votes
4answers
3k views

How to `cd` with word in the middle of a folder?

I have workspace with many folders which all are consisted of long paths. For example: |- workspace |-- this.is.very.long.name.context |-- this.is.another.long.path.authors |-- // 20 more folders |-- ...
1
vote
1answer
306 views

why cant I sudo cd into /root [duplicate]

when I run sudo cd /root it says sudo: cd: command not found but it works perfectly fine if I first sudo su and then do cd /root. Isn't sudo supposed to give me root privileges?
10
votes
3answers
9k views

bash: cd to the most recently modified child directory

Wondering if there's an easy and/or portable way to say "change to the most recently modified child directory". I can use ls and awk but there's probably a better way. cd $( ls -ltrd */ | ...
49
votes
13answers
14k views

Do we have more history for cd?

cd - can move to the last visited directory. Can we visit more history other than the last one?
210
votes
7answers
224k views

What is the 'working directory' when cron executes a job?

I have a script that works when I run it from the command line, but when I schedule it with cron I get errors that it cannot find files or commands. My question is twofold: When I schedule a cron ...
0
votes
0answers
19 views

How to use cdir in multiple tmux panes?

I use cdir python package to navigate between folders and it works very fine. Documentation here. But I have an issue in using it with tmux I am explaining the situation below: I have started a ...
6
votes
2answers
2k 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: $ ...
1
vote
2answers
82 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 > ...
0
votes
0answers
56 views

How to change directory from environment variable in tcsh?

I have captured a linux path into an environment variable. Now I want to change the directory to the path in that environment variable. Lets say the environment variable is named: gr I can see the ...
8
votes
1answer
512 views

libtool error cd: ../..: Not a directory

Getting this very bizarre error from libtool when trying to install a package I built. It happens when running in a subdirectory (src/api) of the source tree: make[5]: Leaving directory '/users/...
0
votes
1answer
75 views

What will this do? “ cd /; ls -al > $HOME/outputfile.log ”

This was an exercise proposed to us in class' but I didn't get it. What exactly will these commands do? cd / ls -al > $HOME/outputfile.log I did try it (in Linux) but (apparently) nothing ...
3
votes
2answers
153 views

what is the purpose of “cd .” command?

We know that the cd command is used to change directories. For example cd dirname valid dirnames include . and .. as well. The purpose of cd .. is clear. From the manpage: A null directory name ...
1
vote
1answer
83 views

Is there a way to change the directory where cd without argument change to?

cd without argument change to the home directory. I'd like it to change to another one. Is there another way than writing a function to do that?
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 ...
0
votes
1answer
68 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
2 3 4 5
8