Questions tagged [cd-command]

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

Filter by
Sorted by
Tagged with
-2
votes
1answer
1k views

Not able to cd into folder in Linux machine. Says file/folder does not exist

I have written a test ksh file to cd into a folder and do a listing. Following is written: `cd "their_file/"`; `pwd`; `ls -l`; Gives me following output: ./test.ksh: line 2: /home/user/final: Is ...
2
votes
3answers
566 views

Asking Bash to cd into each directory under some path and run a command when it is inside?

Take this path for example: /var/www/html. Inside the dir html, there are a few subdirectories. I need the system to go into each one of these sub-directories via cd (it must be cd), and then running ...
6
votes
11answers
2k views

Ability to easily switch between directories in different areas [duplicate]

I'm doing something where I'm frequently changing between two directories far away from each other in the system's file tree. Is there anyway I can assign some kind of short name to each one for use ...
1
vote
2answers
541 views

Bash script to replace two steps: cd ./some_dir, ls -al?

I'd like to write a bash scipt that would change to target directory and list the contents of new directory, all in one step. It would replace the two commands I constantly use consecutively: cd ./...
3
votes
1answer
231 views

how to add a custom option to the mkdir command

I have created lots of directories and I would to make my life lazy and to auto cd into the directory that I made with the option of -g with the result of mkdir -g foo The terminal would be like this:...
3
votes
1answer
347 views

Bash 'cd' with cdable_vars: how to suppress CWD echo?

I have used the Bash shopt cdable_vars option for years. When I cd to a destination that requires cdable_vars to resolve, the shell echoes my CWD before returning me to the prompt. When I cd to a ...
1
vote
1answer
4k views

Cannot cd to .ssh

After adding new ssh key to .ssh/authorized_hosts I can no longer ssh to the machine without entering password. What is even more funny is that the .ssh directory is suddenly inaccessible when I'm ...
0
votes
2answers
69 views

Key I can hold down to only tab complete a folder

Say I have a directory like so: foo/ bar.js bar/ if I cd into foo and then type "ba" and then hit tab, I won't get completion because a file name overlaps with a folder. Is there a key I can ...
4
votes
2answers
207 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 ...
1
vote
1answer
348 views

service status keyword “service” is not needed

Could somebody help me understand why the following is happening? $ cd /etc/init.d; sudo service hadoop-hdfs-namenode status Hadoop namenode is running [ OK ] $ sudo /etc/init.d/hadoop-hdfs-namenode ...
1
vote
2answers
978 views

Execute command from specific folder

I have a screenshot tool that only works if I start it from the same directory where the file is in. Now I want to make a shortcut to just press print, the command is: bash -c '~/Documents/...
-4
votes
1answer
4k views

About bash : cd: too many arguments in my vmware kali linux

Having problems with this, it is not working.
5
votes
2answers
1k views

Symbolic link to change directory only works from home dir

Using this answer, I have created a symbolic link in my .bashrc file to make changing to a frequently used directory easier. E.g. ln -s ~/a/b/c/d/development dev I can change directory from my home ...
11
votes
4answers
4k 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 ...
1
vote
0answers
2k views

Navigating the file system: Difference between CD and PUSHD [duplicate]

Being very novice in navigating the file system, I always use the CD command line to change directories. I just find out that there is another command called: PUSHD I am having hard time to ...
2
votes
2answers
179 views

Get zsh not to complete users

I have a directory with a single subdirectory named src. I'd expect when typing in cd s and hitting TAB for the directory to be completed. Instead, zsh tries to complete all users on the system ...
0
votes
3answers
9k views

bash script to cd into directory

This bash file running on Mac terminal failed to change the directory. Rather reporting it does not exist when it actually does. Any thing I did wrong? #!/usr/bin/env bash set -e read name ...
15
votes
1answer
3k views

What exactly is dot dot (..)? Why is its behavior different with symlinks?

I am trying to understand the nature of .. (double dot). It seems to point to different targets depending on how you access it. Example:- /outer/ middle/ inner/ inner ...
33
votes
4answers
5k views

How to tell if I'm actually in a symlink location from command line?

Suppose I have a folder: cd /home/cpm135/public_html and make a symbolic link ln -s /var/lib/class . Later, I'm in that directory: cd /home/cpm135/public_html/class The pwd is going to tell me I'...
61
votes
3answers
42k 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
1answer
47 views

SU to unpriviledged user starting in priviledged directory

So here's the story. So, I usually work as root, and sometimes I switch to unprivileged users (for example, user1) to try out some things. I noticed something peculiar: When I switch to user1 and the ...
-3
votes
1answer
950 views

cd command does not work in my shell script

I have a script .sh that creates a directory and moves to this directory some files. I want to change the directory to this new one just created, but it doesn't work with the command cd ./$dirname1$...
25
votes
3answers
3k views

How does a shell know home(s)?

Each shell has an environment variable $HOME set (ex: /Users/lotolo). If I'm under csh I can unsetenv HOME and still if I do cd I'll be in my home. I've tested this also on bash (unset HOME) and it'...
1
vote
2answers
5k views

Bash can't run command from script: mkdir command not found [closed]

I have separate scripts for tasks in bash. Here is the broken one: #!/bin/bash PATH=/home/name/ mkdir $PATH cd $PATH && echo "done." exit 0 Today it broke and first time it simply didn't ...
-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 ...
1
vote
3answers
496 views

Run git fetch after any cd command

I need to run git fetch after any cd command in the background and only if I'm in a git directory.
2
votes
1answer
37 views

Create shorcuts in a terminal to navigate between folders [duplicate]

I am looking a way to create shortcuts for the cd command. My goal is to go quickly to distant folders. I have a new (big) drive which is not in my /home folder (but in /media/user/xxX/yyy/) and I ...
1
vote
2answers
822 views

How to define alias only for some directory? [duplicate]

I want to define some alias iex="iex -S mix" only for one directory - this alias should work only when I cd'ed to this directory. Another requirement - this functionality should be placed inside this ...
1
vote
1answer
1k views

alias to make a new directory and go to it [duplicate]

So here I've created, or at least tried to create an alias for a command that accepts a command-line argument, makes a new directory with that name, and goes to it. alias newfolder='mkdir $2 ; cd "$(...
15
votes
3answers
3k views

How to run one command with a directory as argument, then cd to the same? I get “no such file or directory”

I would like to construct a short function to do the following. Let's say that I move file 'file.tex' to my documents directory: mv file.tex ~/Documents Then, I'd like to cd to that directory: cd ~/...
0
votes
1answer
1k views

How to change directory to desktop on german ubuntu?

I fail to change to the desktop via command line. I tried it like this. cd ~/Desktop But then I get "File or Path not found"
4
votes
1answer
10k 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
3answers
2k 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 "`...
2
votes
1answer
2k views

Use a symbolic link to redirect?

Is it possible to set up a symbolic link such that cd called on the link redirects to the linked path? Kind of like this: $ ln /A/B /B/C $ cd /A/B $ pwd /B/C $
2
votes
1answer
240 views

how to have a custom zsh auto_cd command

Instead of the normal cd I've created my own function function cd { builtin cd "$@" && ls -F } This works great for when I use commands like cd someDir/subDir but not when I change ...
-1
votes
1answer
11k 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 . ...
2
votes
0answers
232 views

cd with double slash hangs forever on Mac OS X Terminal

If I type cd // on the Mac OS X Terminal (Version 2.6.1 (361.1)), the prompt hangs forever. Why? Curiously that doesn't happen if I do cd / or cd ///. I am using El Captain with the bash that comes ...
1
vote
1answer
879 views

Bash script SFTPing into remote server and downloading files, cd into proper directory on local machine

I have a cron on my Ubuntu server that runs this bash script daily: #!/usr/bin/expect -f spawn sftp user@ip expect "password:" send "password\n" expect "sftp>" send "cd remote_directory\n" expect "...
22
votes
1answer
664 views

Completion for the first argument of cd OLD NEW

In zsh, the cd command has a two-argument form: cd OLD NEW changes to ${PWD/OLD/NEW}. With the new-style completion system, zsh is capable of completing NEW: the second argument is completed based on ...
1
vote
2answers
99 views

How to work with symbolic links to directories

I am experimenting with symbolic links and I'm encountering a couple issues. The first is how after following a symbolic link to a directory to display the actual working directory instead of the ...
2
votes
1answer
1k views

Tab to show directory contents

I use the terminal app on OSX. Whenever I cd into a deep directory I find it useful to display the successive directory contents as I go. By tapping tab when typing the filepath, it lets me see the ...
1
vote
1answer
92 views

cd: permission denied: binutils-2.21.1

I'm following Tools Used in 6.828 to configure. $ sudo tar xjf binutils-2.21.1.tar.bz2 generate folder binutils-2.21.1 $ cd binutils-2.21.1 cd: permission denied: binutils-2.21.1 $ sudo cd binutils-...
4
votes
3answers
447 views

POSIX compliance of the cd program?

Is globbing and shell expansion same thing? I'm learning C by writing a custom shell and I'm also learning POSIX. Now I wonder if it is POSIX compliance that cd - takes you back and that ~ means home ...
2
votes
1answer
835 views

Change to a directory containing a space

I'm using a MacBook with OS X installed. I'm on Terminal trying to go to a directory. So I'm in Home and I use the command ls and there is a VirtualBox VMs directory. But when I try to do cd ...
1
vote
1answer
413 views

How can I get a persistent dirstack with unique entries in zsh?

The Arch Wiki has this interesting bit of zsh configuration: DIRSTACKFILE="$HOME/.cache/zsh/dirs" if [[ -f $DIRSTACKFILE ]] && [[ $#dirstack -eq 0 ]]; then dirstack=( ${(f)"$(< $...
2
votes
1answer
243 views

Change color when changing directory

I have two folders called Documents and Downloads. In zsh, when I type cdSpaceDoTabc the color of Documents change from white to (hard to read) gray. How can I turn off this color change or control ...
16
votes
1answer
18k views

pushd, popd vs cd, cd- in bash and zsh

Is there a difference between the behavior of pushd/popd in bash vs zsh? It seems in zsh cd, cd- behaves exactly the same as pushd/popd (which adds/pops directory automatically when cd) while in bash ...
-10
votes
2answers
12k views

What does the cd /etc command do?

I was asked the question "what does the cd /etc command do?". This is my answer: This command cd /etc changes directory to the directory specified after the slash /. The /etc refers to a folder in ...
2
votes
2answers
279 views

cd out of deleted folder

Is there a way to cd out of a directory which has just been deleted (go up one level into the upper folder which still exists? It often happens to me that I have a console opened for a folder, and ...
1
vote
2answers
7k views

Change Directory and execute command automatically then change directory back out

I'm attempting to write a script that will be run in a given directory with many single level sub directories. The script will cd into each of the sub directories, execute a command on the files in ...

1 2 3 4 5 7