What is the '.' directory in Windows? - windows

For example, a directory has the following files: (as shown in explorer)
index.php
hello.php
img
If you query it using windows or just type dir in cmd prompt it will have the following files:
.
..
index.php
hello.php
img
I understand that '..' is a link to the previous directory, but what exactly is '.' and how can it be used? I've searched all over the internet, but no avail found for the single dot

The . can be used in some commands: This will copy the files from c:\temp to the current directory:
copy c:\temp\*.* .
The .. can be used to move to a higher directory.
This will change to the parent folder:
cd ..

The '.' indicates the current directory as per this. As you mentioned, '..' is a link to the previous directory. Ultimately the Operating System will choose how to indicate these, but it is pretty standard across all major OSs

. is the same as the current directory, but in a relative way.
For instance if the current directory is c:\temp and if you cd in this directory, then . == c:\temp.

In short . is the current directory and .. is the parent directory. It is convenient for you to write scripts with these keyword otherwise you have to write a long command.

Related

How to remove a file named '.'?

Ok so i did something very stupid (copying a file and renaming it '.') since I thought it would just copy it as .uniprot_sprot.fasta.gz.icloud.
cp /path/.uniprot_sprot.fasta.gz.icloud .
and now I don't know how to remove it from current directory as it would be removing '.' itself.
What can I do?
This doesn't work. It says: No such file or directory
rm .uniprot_sprot.fasta.gz.icloud
On the other hand:
ls -a
gives this:
.
..
uniprot_sprot.fasta.gz.icloud
You have not copied a file and renamed it . (at any rate if you're running a sane *nix). Instead you have copied the file to the current directory with the name of the original file. (If you pass a directory to cp as the destination, files will be placed in that directory. . is the current directory, so this is all that has happened.) If you want to remove it you can just rm uniprot_sprot.fasta.gx.iscloud or explicitly rm ./uniprot_sprot.fasta.gx.iscloud. What you have tried to do is to remove a file whose name starts with ., which is a different thing.
Edit: I was unaware when I wrote this, but this is in fact simply down to . existing as a real, regular hardlink. At syscall level you can create a file whose name contains anything except / and \x00 (yep, including \n), assuming your filesystem allows it. However, the links . and .. are already present and thus unavailable as a file name. #thatotherguy links to the kernel source for the rmdir syscall, showing that in modern Linux at least it is the kernel itself which ultimately prevents you from deleting . and ...
Note that in bash, . at the beginning of a line by itself means source.
See this question on unix.se and its linked dupe for more information on the filename problem.

find does not descend to some directories

find . should, according to my knowledge print out recursively everything in the current directory, however when I use it in a directory I'm getting the following
.
./WORKSPACE
./bazel-out
./lib
./lib/BUILD
./lib/hello-time.h
./lib/hello-time.cc
./main
./main/BUILD
./main/hello-world.cc
./main/hello-greet.h
./main/hello-greet.cc
./bazel-stage3
./bazel-bin
./bazel-testlogs
./README.md
./bazel-genfiles
however, this is not everything -- at least the folder bazel-bin contains some files. Actually, if I run find bazel-bin, this is what I get:
bazel-bin/
bazel-bin/lib
bazel-bin/lib/_objs
bazel-bin/lib/_objs/hello-time
bazel-bin/lib/_objs/hello-time/hello-time.pic.d
bazel-bin/lib/_objs/hello-time/hello-time.pic.o
bazel-bin/lib/libhello-time.a
bazel-bin/lib/libhello-time.a-2.params
bazel-bin/main
bazel-bin/main/_objs
bazel-bin/main/_objs/hello-greet
bazel-bin/main/_objs/hello-greet/hello-greet.pic.o
bazel-bin/main/_objs/hello-greet/hello-greet.pic.d
bazel-bin/main/_objs/hello-world
bazel-bin/main/_objs/hello-world/hello-world.pic.o
bazel-bin/main/_objs/hello-world/hello-world.pic.d
bazel-bin/main/libhello-greet.so
bazel-bin/main/hello-world.runfiles_manifest
bazel-bin/main/libhello-greet.so-2.params
bazel-bin/main/hello-world-2.params
bazel-bin/main/libhello-greet.a-2.params
bazel-bin/main/hello-world.runfiles
bazel-bin/main/hello-world.runfiles/__main__
bazel-bin/main/hello-world.runfiles/__main__/main
bazel-bin/main/hello-world.runfiles/__main__/main/hello-world
bazel-bin/main/hello-world.runfiles/MANIFEST
bazel-bin/main/libhello-greet.a
bazel-bin/main/hello-world
Why the find . does not descend into bazel-bin?
Thank you.
My bet is that bezel-bin is a soft link within your current directory.
Find will not traverse the soft link. You should try find . -follow

function in .profile to move a folder from location A to current working directory

I have folder called Demo on my desktop. The following line moves the default folder to the Demo folder.
mv /Users/me/Documents/Work/Projects/default Demo/
But I need to have the following:
in my .profile, I would like to have a function that moves the default folder's children (sub-folders and files) to the directory I'm currently in (cfr. Demo).
So I could do this in the Demo-folder:
generate-default-folder-structure (function name from .profile-file)
Could anyone help me out with this one, please?
Thanks
If I've understood you correctly, this should work:
mv ~me/Documents/Work/Projects/default/* .
It will move all (non-hidden, typically) contents of that default directory to your current directory.

What does slash dot refer to in a file path?

I'm trying to install a grunt template on my computer but I'm having issues. I realized that perhaps something different is happening because of the path given by the Grunt docs, which is
%USERPROFILE%\.grunt-init\
What does that . mean before grunt-init?
I've tried to do the whole import manually but it also isn't working
git clone https://github.com/gruntjs/grunt-init-gruntfile.git "C:\Users\Imray\AppData\Roaming\npm\gru
nt-init\"
I get a message:
fatal: could not create work tree dir 'C:\Users\Imray\AppData\Roaming\npm\.grunt-init"'.: Invalid argument
Does it have to do with this /.? What does it mean?
The \ (that's a backslash, not a slash) is a directory delimiter. The . is simply part of the directory name.
.grunt-init and grunt-init are two distinct names, both perfectly valid.
On Unix-like systems, file and directory names starting with . are hidden by default, which is why you'll often see such names for things like configuration files.
The . is part of a directory name. Filenames can contain . . The \ is a separator between directory names.
Typically, files or directories starting with . are considered "hidden" and/or used for storing metadata. In particular, shell wildcard expansion skips over files that start with ..
For example if you wrote ls -d * then it would not show any files or directories beginning with . (including . and .., the current and parent directories).
Linux hides files and directories whose names begin with dot, unless you use the a (for "all") option when listing directory contents. If this convention is not followed on Windows, your example is probably just a carryover.
It may well be something behind the scenes (later) expects that name to match exactly. While I like things, installers, for example, to just do what I said, I realize that keeping default value is the most tested path.
Directories starting with a dot are invisible by default on xNIX systems. Typically used for configurations files and similar in a users home directory.
\ before " has a special meaning on windows, the error is because windows won't let you create a file containing " as part of its name.

Ruby - Why does Dir.foreach pass `.` and `..` as the first two parameters?

In an empty directory, the following code
Dir.foreach("./") do |file|
puts file
end
returns
.
..
In my understanding . refers to the working directory and .. refers to the parent directory; why does foreach seem to treat them as files within the working directory?
Because they are files within the working directory. The . and .. directories are not magical; they appear the same way any subdirectory does, as entries in the directory. Every directory on a UNIX-type file system has actual directory entries named . and ... So if you don't want to include them when processing a directory, you need to exclude them yourself.

Resources