Cd is a command-line utility to change the working directory.
57
votes
6answers
4k views
Why is cd not a program?
I've always wondered why cd isn't a program, but never managed to find the answer.
Anyone know why this is the case?
48
votes
21answers
4k views
Quick directory navigation in the terminal
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 ...
29
votes
3answers
889 views
How can I cd to a directory just by typing the directory's name?
I either had this somewhere 20 years ago or I dreamed about it.
Basically:
If if type blobblob I get
blobblob: command not found
Fair enough.
I would like it so that when my shell gets those ...
19
votes
6answers
1k views
Why can't I redirect a path name output from one command to “cd”?
I am trying to get cd to accept a directory name redirected to it from another command. Neither of these methods work:
$ echo $HOME | cd
$ echo $HOME | xargs cd
This does work:
$ cd $(echo $HOME)
...
17
votes
3answers
790 views
How do you enter a directory that's name is only a minus?
I downloaded lessn to my webserver and unzipped it.
It contains a folder named -. I assumed I know how to deal with that, but I don't.
I tried cd -- -, but that doesn't have the desired effect. ...
17
votes
2answers
501 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 ...
14
votes
1answer
971 views
Execute bash scripts on entering a directory
What is the best way to execute a script when entering into a directory? When I move into a new directory I would like bash to execute the projectSettings.bash script much like RVM does.
12
votes
2answers
877 views
What is the bash shortcut to change to the previous directory?
Sadly, I only learned about this last year by stumbling upon it randomly on the internet. I use it so infrequently that I always forget what it is by the time I need it again.
How do you change to ...
12
votes
3answers
1k views
Changing parent directory (../) with symlinks
I have a symlink
~/link -> ~/a/really/long/path
When I do
cd ~/link
cd ..
it takes me to
~
but I want to go to
~/a/really/long
Is there a way to do this?
I am using bash.
11
votes
4answers
3k 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 questions is twofold:
When I schedule a cron ...
9
votes
6answers
3k views
Execute a specific command in a given directory without cd'ing to it?
Is there a way to execute a command in a different directory without having to cd to it? I know that I could simply cd in and cd out, but I'm just interested in the possibilities of forgoing the extra ...
9
votes
4answers
2k 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?
9
votes
4answers
2k views
symbolic link to a directory and relative path
I've created symlink with absolute path to the directory (Blink) and have for example following tree:
$ ls -l /tmp/A
total 0
lrwxrwxrwx 1 root root 6 Apr 3 12:27 Blink -> /tmp/B
-rw-r--r-- 1 root ...
8
votes
2answers
308 views
Change directory without typing cd?
Is it possible to make bash change directory in command line simply by typing that directory without any commands like cd?
For example is it possible instead of writing this:
$ cd /tmp
I just want ...
7
votes
3answers
2k views
~ is $HOME, but sometimes?
This is kind of a trivial and dumb question.
cd ~
does the same thing as
cd $HOME
which is also the same as
cd /home/tandu
However,
cd ~not-tandu
changes to /home/not-tandu
Is this ...
7
votes
2answers
346 views
How can I cd to the previous/next sibling directory?
I often have a project directory layout like this
project
`-- component-a
| `-- files...
`-- component-b
| `-- files...
`-- component-c
`-- files...
I'll usually be working in one of the ...
6
votes
2answers
388 views
Why `.` is displayed by `ls`?
After reading the question When you type “ls -a”, what is the significance of “.” and “..”?, I have a similar one.
Why to display .? I mean, is there any directory where cd . would not work? How is ...
6
votes
1answer
377 views
Show message when cd into specific directory
How can I display a message when I cd into a specific directory? This directory is a local one, and I just need a reminder when I go into it from the terminal.
6
votes
3answers
2k 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 ...
5
votes
4answers
829 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 ...
5
votes
2answers
158 views
Output of which command used for input to cd
I would like to take the output of a which command, and cd to the parent directory. For example, say I have the following:
which someprogram
With output:
/home/me/somedirectory/someprogram
And I ...
5
votes
2answers
236 views
Run a script automatically as I switch to a directory [duplicate]
Possible Duplicate:
Execute bash scripts on entering a directory
I am running an environment which requires some very specific tool versions.
The commands to set up the environment are in a ...
5
votes
3answers
525 views
How to verify a CD against an ISO image?
I've got a physical burnt CD and the original ISO image of it. No reference checksum files were provided for the CD contents. How do I check the actual CD is correct (corresponds to the original ...
5
votes
1answer
467 views
Can't get directory listing of folder I have permissions to
I was having some permission problems and used the following command on directory Media:
chmod -R ugo+r Media
It didn't help so then I did:
chmod -R 775 Media
Now I get this error when I try to ...
4
votes
4answers
198 views
How to make `cd dir/filename` take me to dir/?
I would find it very convenient to be able to use cd with a file argument.
cd myDirectory/anyname.anyExtension
would be equivalent to
cd myDirectory/
What would be the best alias or function to ...
4
votes
4answers
180 views
Follow a moved file to its destination directory
Is there a way to move a file from a directory to another and then cd into the latter in one command? Something like mv /a/file /another/dir && cd _ but without typing second time the ...
4
votes
2answers
194 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 ...
4
votes
1answer
201 views
Symbolic links with ls, mv: forcing the functions to utilize “logical” addresses (remembering the original path)
It seems that for many basic functions operating on symbolic links, the physical path is used by default. However, cd works fine. When moving into a symbolic link, cd remembers where I came from so it ...
4
votes
1answer
176 views
Any cd shortcut to switch an intermediate directory in current path?
if I have current path as a long one..and I want to switch to a directory with just one word from path replaced by something else..like say when using maven , I want to switch from main path to test ...
4
votes
1answer
81 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 ...
3
votes
5answers
673 views
Directory is not opening with cd command
I have a directory in Desktop named Project. I tried opening it using the cd command but it is not opening. What's the reason?
Check the screenshot. The directory has all the required permissions.
I ...
3
votes
3answers
971 views
Cannot execute command at GNU screen startup
I want to do something similar to what's written
here without using zsh (I use bash), but if I try to start screen with
screen 'cd /home/cataldo/Programs'
I get the following error:
Cannot exec ...
3
votes
2answers
198 views
Force change of a user's cwd as root
I'm looking to change a user's process such that I can set it's cwd.
Related, and secondary to the question, I have a filesystem I want to unmount but a user is sitting on it with a bash process. I ...
3
votes
2answers
153 views
How does bash continue to work correctly when you move its working directory?
On Linux, I moved a directory to another directory using mv, and in another shell, my working directory happened to be the directory that was moved.
I ran hg pull in that shell, and to my surprise, ...
3
votes
2answers
250 views
How to make cd arguments case INsensitive?
Sometimes while accessing the various directories it happens most of the times that I remember the names or at least part of the names of a directory under our Linux system. But some of the ...
3
votes
2answers
324 views
Behavior of stdin/stdout in conjunction with subshells and cd command
I have the following series of commands:
cd / && ls | ( cd /tmp && cat >dumpfile)
This series of commands does the following: it creates a file named /tmp/dumpfile. This file ...
3
votes
2answers
645 views
How do I create a ZIP archive that preserves only the structure of the target directory and below?
I need to create a zip archive where the unzipped result preserves the directory structure from the specified directory down. I also need to do this without actually switching to the directory.
My ...
3
votes
1answer
530 views
changing current working dir with a script
I've read this question and answer, but it doesn't quit fit my problem, even tho it's similar.
I'm writing a script (called cpj) that will launch one of my current projects. I have about 5 of them. ...
3
votes
2answers
335 views
Conflict between `pushd .` and `cd -`
I am a happy user of the cd - command to go to the previous directory. At the same time I like pushd . and popd.
However, when I want to remember the current working directory by means of pushd ., I ...
3
votes
1answer
144 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 */ | tail -1 | ...
3
votes
1answer
1k views
What is the best touch screen kiosk solution?
I'm a web developer and I'm looking for the best stripped-down linux experience that provides a full-screen experience for touch screens. I'll be looking for:
a robust experience that stops people ...
3
votes
1answer
231 views
Building an offline installer Debian CD
I have to build an install CD to help others people to setup a Debian server with Apache/Mysql/PHP and our application.
But the CD must install the full system offline (because servers will be ...
2
votes
5answers
949 views
Perl script, do cd on terminal
In Script to change current directory (cd, pwd)
it is shown how to run a bash script that changes terminal directory.
But how do i run a perl script that runs a bash script that changes terminal ...
2
votes
1answer
87 views
cd and ls in the same call [duplicate]
I often have to cd to a directory and ls to see the directory listing. Can it be done with one shot, so that I can add to .bashrc as alias. I searched on Google, there were some answers, but ...
2
votes
2answers
79 views
How do I escape a sub-directory name with an ampersand in it?
Running a kornshell and trying to traverse a directory tree.
Want to cd to a sub-directory named as follows:
-3ab_&_-3dc.img
My question is HOW do I need to escape the ampersand in this name?
...
2
votes
1answer
396 views
Make cd follow symbolic links
I have my code mounted as an sshfs in my home directory, but the hierarchy is difficult to remember, so I created a symlink in my home directory leading to that directory. Is there a way so that when ...
2
votes
2answers
84 views
How can I create a “base” for other aliases to refer to and enable cd base/x command directories?
I have .bash_aliases with:
alias c1='cd /home/me/code/php'
alias c2='cd /home/me/code/jquery'
alias c3='cd /home/me/code/ruby'
alias c4='cd /home/me/code/c'
How can I DRY this up and loosen the ...
2
votes
2answers
62 views
`cd` all screens to the PWD of the current screen
Suppose that I am running screen on a remote server with four open screens. Is there a quick way to cd all the screens to the working directory of the currently-open screen? Thanks.
2
votes
1answer
109 views
How do i run a process in a specific directory?
In an init.d file i wrote the below. Now i need to make the bin run in a specific directory. How do i tell it which directory to use?
mono --debug /path/bin &
2
votes
1answer
1k views
Why can't list file/directory relative to .. from a symbolic link directory (No such file or directory)?
I have a /usr/tomcat6/logs directory linked to /var/log/tomcat6.
When I changed directory to /usr/tomcat6/logs and try to ls files using a relative pathname ../conf/Catalina/localhost, a No such file ...