Linked Questions

102
votes
11answers
23k views

Does cd . have use?

One of the tutorials I've been following briefly stated that cd . has no use. When trying to replicate issue shown by OP in Symbolic link recursion - what makes it “reset”?, I also tried cd ., which ...
43
votes
2answers
97k views

Is it better to use $(pwd) or $PWD?

I encountered BASEDIR=$(pwd) in a script. Are there any advantages or disadvantages over using BASEDIR="$PWD", other than maybe, that $PWD could be overwritten?
31
votes
2answers
81k views

What is $PWD? (vs current working directory)

So Wikipedia (link) tells me that the command pwd is short for "print working directory", and that makes sense. But for the environment variable, the "P" has to be an acronym for something else than ...
12
votes
2answers
15k views

Create an absolute symbolic link to the current directory

I am now under a directory with very long path. For future visiting it quicker, I would like to create a link to it. I tried ln -s . ~/mylink ~/mylink actually links to ~. So can I expand ~ into ...
10
votes
3answers
811 views

How to implement “generators” like $RANDOM?

The special variable $RANDOM has a new value every time it's accessed. In this respect, it is reminiscent of the "generator" objects found in some languages. Is there a way to implement something ...
9
votes
1answer
2k views

Understanding directory symlinks traversals and the parent directory

Let's say you have directories /dir1 and /dir2/linked, where the latter is a symlink to the former. When you cd to linked and pwd, you get the output /dir2/linked. If you then cd .., you'll be put ...
0
votes
1answer
3k views

How could I quickly find a recursive symbolic link? [duplicate]

I am experiencing an issue with a indexing program running much longer than expected. I want to rule out the possibility of a recursive symbolic link. How could I find a symbolic link that is ...
0
votes
3answers
1k views

Can a bash script tell what directory the user is when they run the script?

Is it possible for a shell script to know the directory the user is in when they run it? I am trying to develop a script like this which runs through a list of subdirectories and runs some git ...
5
votes
3answers
218 views

Retreat from deleted directory

Suppose I am editing some files. I have (say) a terminal open and a gui file manager. I am currently in /my/very/long/and/winding/directory/path in the terminal. In my gui, I delete /my/very/long/and/...
6
votes
2answers
494 views

How does cd .. know which directory is ..?

Drectories contain . and .. which are hard links to the current and parent directory. So how does the shell know for example in the prompt, that the current directory is called "a" in cd a/path/..? ...
1
vote
1answer
57 views

Relative symlinks not resolving in subdirectory

I've got the following directory layout: /home/me/mydir \- tiller -> ./cache/git-repo1/subdir1/tiller \- makefiles -> ./cache/git-repo2/subdir2/makefiles When I'm in /home/me/mydir if I ...