2022 Developer Survey is open! Take survey.

Questions tagged [cd-command]

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

Filter by
Sorted by
Tagged with
3 votes
1 answer
242 views

Use the parent directory from the symlink instead of where the directory actually resides on the filesystem

So let's set up the context. Two paths: /some/very/convoluted/path/name/the-wanted-directory /myhome I create a symbolic link in /myhome and then cd into it: /myhome $ ln -s /some/very/convoluted/path/...
user avatar
  • 973
-3 votes
1 answer
63 views

What does 'cd ../..' mean in linux?

I am aware that cd is used to navigate between files in linux commandline. However, I am not sure what the following, that I came across while trying to replicate something, means: cd ../.. It was ...
user avatar
1 vote
2 answers
69 views

Use parent directory base name for making a new directories in a for loop

I am attempting to use a for loop to move files (e.g. .txt) into a new directory, where the original directory name as part of the name, but add an extra "with-new-files" onto the name so I ...
user avatar
1 vote
0 answers
36 views

ls displays no files even though folder contains files

This question is actually derived from a problem I have with a python library which deletes a file tree and then recreates the content, but on attempt of execution of a file inside the directory, the ...
user avatar
2 votes
2 answers
24 views

Is there a way to quickly change dir to one from where one of the jobs is running?

The output of jobs looks something like this [1] Stopped TERM=xterm-256color vim --servername vim ~/.gitconfig [2]- Stopped TERM=xterm-256color vim --servername vim ~...
user avatar
  • 1,012
-1 votes
2 answers
35 views

How to define a new command that is a wrapper of an existing command and accepts all original flags?

What I want to do is to make a command that prints some related info if the command is successful. As an example, if I define an alias as alias cd='cd /path/to/destination/ && echo "...
user avatar
  • 131
-4 votes
1 answer
204 views

Can't find /etc/passwd [closed]

For some reason, every time I need to go to passwd or even shadow, It does not allow me. For example: cd /etc/passwd Output: cd: not a directory: /etc/passwd Same thing with shadow. Because of this, ...
user avatar
0 votes
1 answer
53 views

how to cd into previous directory

I am using Ubuntu and sometimes when I use cd - I don't go into the previous directory. And every time I get the directory which it cded to. example:- $cd - /home/[usrname]/Downloads $cd - /home/[...
user avatar
0 votes
0 answers
18 views

cd command to a variable containing a path with spaces gives different output than actually giving the path as an input [duplicate]

I have a directory named "test 1" and I create a variable dest="test\ 1" I want to navigate to the directory using the cd command, so I type cd $dest which gives the output as -...
user avatar
2 votes
2 answers
97 views

What is the zsh equivalent of "pushd -n" in bash?

I want to push a directory onto the directory stack in order to refer to it using "tilde shorthand" (eg. ~1 refers to the second entry in the directory list), but I don't want to actually ...
user avatar
  • 546
-2 votes
1 answer
369 views

Permissions denied in Kali Linux

I cannot get into /root and even when i use "sudo ls /root" it asks me for the password then nothing happens. Im new to linux and when I was testing out Kali linux i tried using permission ...
user avatar
0 votes
1 answer
128 views

Changing directory with if else condition

Below is a small extract of my code for you to have a better visibilty on my problem. As each file in the directory enters the loop, the value of em is extracted from the filename and compared with ...
user avatar
1 vote
1 answer
36 views

Sourcing a script to change pwd, ignore piping at end of command?

I have a little script I wrote that lets me change to the directory of a script that's on the path, which helps me quickly get to other scripts I tend to want to edit, in the same folder as the ...
user avatar
  • 1,327
-2 votes
1 answer
156 views

why couldnt I cd /etc/group but return not a directory in ubuntu?

I switch user to root used su. but i still couldnt cd /etc/group but the group folder is in my /etc folder. root@Desktop:/etc# cd group bash: cd: group: Not a directory
user avatar
  • 99
0 votes
2 answers
97 views

How to use substitute with cd command in Linux

We recently migrated from HP-UX B.11.31 to Linux 3.10.0-1160.15.2.el7.x86_64. I am trying to achieve the below (which worked in the earlier HP-UX system): $ pwd /global/app/opt/prod/ee/01/custo/src/ $ ...
user avatar
0 votes
1 answer
102 views

How to tell 'find' command to jump to a position and search? [duplicate]

I'm preparing headers for a C++ project and I decided to use find to get include option to other header files. To list the right path, I need to use cd with it, like: cd 'PATH/TO/HEADER/FILE' find ../....
user avatar
1 vote
0 answers
45 views

bash: run command from script, but affect the shell where it´s called from

There is a script that should change the path of the shell where it was run from. I used this code: #!/bin/bash TTY=$(tty) echo -e "cd /tmp/ \r" > $TTY exit But that does not work. Is ...
user avatar
0 votes
0 answers
53 views

The cd command on macOS performs an ls after dc. Why?

On MacOS terminal with bash, I get an ls after a cd. When the directory contains many files, I can't see the effect of the cd since it scrolls away due to the ls. This is what I see $ which cd cd is a ...
user avatar
  • 211
-6 votes
2 answers
394 views

in what language is bashrc written

I came across a cool way to go up more than 1 directory level by adding a function to the .bashrc file. It is done by just opening the .bashrc file and inserting the function: #user defined functions ...
user avatar
  • 1
2 votes
2 answers
281 views

Why do I have to use this command twice to execute it?

I made an alias alias goto="cd $@ && source ~/.zshrc" and it works, but only if I execute it twice. Even after I execute it twice in one shell, and if I want to move to another dir, ...
user avatar
  • 23
3 votes
1 answer
184 views

Are there any caveats in using shopt -s autocd?

I have recently discovered the feature shopt -s autocd: autocd If set, a command name that is the name of a directory is executed as if it were the ...
user avatar
  • 415
2 votes
1 answer
48 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 ...
user avatar
  • 23
2 votes
1 answer
119 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 ...
user avatar
  • 189
8 votes
3 answers
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 ...
user avatar
2 votes
1 answer
100 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 ...
user avatar
10 votes
5 answers
617 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 ...
user avatar
  • 205
0 votes
1 answer
125 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 ...
user avatar
1 vote
0 answers
23 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” ...
user avatar
0 votes
4 answers
89 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 ...
user avatar
-2 votes
2 answers
129 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.
user avatar
  • 103
1 vote
1 answer
137 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 ...
user avatar
  • 113
0 votes
1 answer
67 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 ...
user avatar
  • 111
0 votes
1 answer
84 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 "...
user avatar
2 votes
3 answers
322 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 ...
user avatar
  • 39
-1 votes
1 answer
507 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 ...
user avatar
0 votes
2 answers
32 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/...
user avatar
1 vote
4 answers
88 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?
user avatar
13 votes
3 answers
1k 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 ...
user avatar
  • 199
10 votes
4 answers
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 |-- ...
user avatar
  • 219
2 votes
1 answer
2k 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?
user avatar
0 votes
0 answers
198 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 ...
user avatar
8 votes
1 answer
711 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/...
user avatar
0 votes
1 answer
121 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 ...
user avatar
3 votes
2 answers
245 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 ...
user avatar
  • 165
1 vote
1 answer
216 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?
user avatar
  • 2,198
1 vote
2 answers
71 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 ...
user avatar
-1 votes
4 answers
566 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
user avatar
  • 117
0 votes
1 answer
88 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 ...
user avatar
  • 1
0 votes
1 answer
307 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 ...
user avatar
0 votes
2 answers
1k 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....
user avatar

1
2 3 4 5
8