What is the difference between . ./ ./* in linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
when i copy files, execute the file in linux, I am Not quite understand the difference and how to use them.
please help. thanks.

. means current directory
./ means current directory, too
./* means all files in current directory

. means the current directory, and ./ is the same but more explicit, saying "Hey, I'm a directory!" It's like any other folder: TheFolder and TheFolder/ refer to the same object. One case where the meaning is different is when looking at a symlink pointing at a directory: TheLink can refer either to the link object or the directory that you pointed at, depending on the situation, while TheLink/ will always refer to the directory. Also, when you run the rsync command, it will treat TheFolder and TheFolder/ differently.
./* just means all the files in the current directory, same as *. Bash expands that asterisk before the command is run, so the program doesn't see the asterisk, instead seeing all the files as arguments. The difference between these two is that for the former, the command will see "./" prepended to each filename.
To see how these differ, echo is a safe command to run. It will just print the value of what you send it:
echo *
echo ./*

. and ./ both mean current working directory
../ means parent directory of the current working directory
./* means all files and directories in current working directory plus all files and directories in all directories in the current working directory.

./* is all files in current directory
./ is current directory

Related

What does the command "sudo mv home/* *" do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I know each part of this command.
sudo mv home/* *
sudo: super-user do, execute with root privileges.
mv: move a file or directory.
home/*: argument of mv command. It indicates the content of home directory. The asterisk * is a wildcard that expands to the list of files in the current directory in lexicographic order.
The next argument is the destiny folder. However, I specify an asterisk as destiny directory, and if I execute the command the folder disappear completely. So, what does the * in this case?
Let's say you have /home/userA, /home/userB and /home/userC. Let's further say you're running this in a directory that contains 1.txt, 2.txt, and a directory 3.d.
Under those circumstances, this would expand to:
sudo mv /home/userA /home/userB /home/userC 1.txt 2.txt 3.d
That is to say, both globs are expanded -- the first to the list of entries in /home, an the subject to the list of files in the current working directory -- and the result is everything being moved into the directory 3.d.
Flagged Community Wiki since this is an answer to an off-topic question.

What does the command cd . mean? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I understand that cd .. goes up a directory, but what exactly does cd . do?
This is a question on my study guide, which is why I am asking.
Thanks!
As most people realize, cd . doesn't really do anything, because . means "the current directory". Changing to the current directory is seemingly pointless.
However, there is at least one interesting side effect:
When you cd to some directory, an environment variable OLDPWD is set, which allows you to execute cd - to return to the previous directory that you cd'ed from. When you execute cd ., OLDPWD actually gets set as the current directory, so it renders cd - ineffective in getting you back to the previous directory you were in.
Example:
$ cd /foo
$ cd /tmp
$ cd -
$ pwd
/foo
I'm in /foo just like I expected, but
$ cd /foo
$ cd /tmp
$ cd . # does nothing, right?
$ cd -
$ pwd
/tmp
Now I didn't return to /foo like I was hoping, due to this side effect!
Nothing. cd changes directory to the argument provided. And . means "the current directory" just as .. means "the parent of the current directory".
As others have said, cd . will change to the current directory, which has basically no effect in scripting/programming or to the operating system.
However that doesn't mean it will do nothing. In practice, you may be using a terminal to type this command. It will happily execute the command and - perhaps, though not likely - do something like echo the contents of the directory. If something else on your system (say a background process or another shell) have changed the contents of the directory, you may see modified output when the command echoes out the new directory listing.
In short: the cd . command doesn't have any real effect, but it could - in rare instances - have useful side effects that you could leverage in practical use.

Why do I need to put dot forward slash when running a 'sh' command in Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have found that if I have a .sh file in a certain directory then I can run it (using sh) from that folder with or without dot forward slash. So why even bother adding it?
Please check http://www.linfo.org/dot_slash.html as well.
Basically this is a safety mechanism to indicate the program to execute is in the current directory and NOT a built-in command, a command in some other folder specified in the PATH etc.
From the link:
Files in the current directory can be accessed for reading and writing by merely entering the command name (e.g., cat or vi) followed by the name of the file. That is, no absolute path is necessary. However, when execution is desired, either an absolute path (or its dot slash equivalent) or the inclusion of the directory containing the command's executable file in the PATH variable is necessary. This is a built-in safety mechanism.
If your script is running without ./ then it means the specific location is in the path or . is in the path as mentioned in comments.
Hope it helps.
Your PATH is a list of directories which is searched to find files to execute. If your command is in one of those directories it will be executed. If it is in a different directory, then you need to indicate to the shell what directory it is in. . means the current directory, so
./prog
will run the prog file found in the current directory
/some/other/path/prog
will run the file in the directort /some/other/path
and
subdir/prog
will run prog in subdir relative to your current directory.
To see what your path is set to type echo $PATH.

Why is the 'mv' command not working when moving a file up multiple levels [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
Operating system: SLES12 VM
So I start off in a directory:
DirA: /home/user/testA/testB
My goal is to move a file from this directory to a directory given by
DirB_rel: /home/user/testA/testB/../../deliverables/rpm/SOURCE
Note: testA is a symlink which is not included in DirB_abs
Which, when I cd to it, gives a pwd of
DirB_abs:/home/user/deliverables/rpm/SOURCE
The problem is, when I try move a file using mv (have tried tar.gz and .txt) from DirA to DirB_rel, the file is deleted from original location as expected, but it does not appear at new location and is therefore lost.
E.g. mv testFile.txt DirB_rel -> File disappears
However, when I use the absolute path for directory B, mv works correctly.
E.g. mv testFile.txt DirB_abs -> Success
Any idea whats going on here?
Thanks!
The problem is with the symlink. When you do user/testA/testB/../../ and testA is asymlink, you wont go back to user, but to the parent directory of the directory testA links to
the mv command will reference the directory you are currently in and not from where the file is. So if we are in home ~/ and want to move ~/A/file to ~/B/file you use mv as follows:
mv A/file B/
Note that if you use this
mv A/file ../B/
the command will look for B in /home/B and not ~/B since we are in the ~/ directory issuing the command.

Why does `cd ..` reflect symlink traversal, whereas `ls ..`does not? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
ls ..
means ‘list upper directorie’s files and directories.’
When I changed directory following a symbolic link, ls .. does not follow the symblic link. It just shows the real upper directory.
For example, when the directory structure is as follows,
r ┬ a - b - sub#
└ sub
(sub# is a symbolic link to sub directory)
ls ..command after cd a/b/sub gives files at r directory as I’m in r/sub. not b directory’s. But cd .. command takes me to b directory.
How can I use ls command to show files in directory b?
A directory doesn't know what symbolic link you used to get to it; .. is an actual directory entry that points to the real parent directory. But when you use the shell command cd .., bash cheats. It knows what path you used to get there (it's in $PWD), so it just removes the last component of that and changes to the resulting directory.
You can use the same trick yourself for the benefit of other commands by using "${PWD%/*}" instead of ..:
ls "${PWD%/*}"

Resources