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%/*}"
Related
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 3 years ago.
Improve this question
If /bin/foo is a program that output hi and /usr/bin/foo is a program that outputs hello what would be the output on your screen of this three command sequence:
PATH=/bin/foo:/usr/bin/foo:/usr ; cd /bin ; foo
The answer should be hi
The content of PATH should be a ':' separated list of directories, not paths directly to executables. Based on the rest of the question I assume the command sequence was meant to be PATH=/bin:/usr/bin:/usr ; cd /bin ; foo rather than PATH=/bin/foo:/usr/bin/foo:/usr ; cd /bin ; foo.
If so, the output would be "hi" because of the order of the directories in PATH.
When the command foo is executed the system checks each of the directories in the PATH variable for an executable by that name and executes the first one it finds. Since the directories in order are;
/bin
/usr/bin
/usr
the executables it will look for are
/bin/foo
/usr/bin/foo
/usr/foo
From your description we know that /bin/foo is a program that outputs "hi" so the first executable it looks for is found, run, and outputs "hi".
The cd /bin is a bit of a red herring because the working-directory isn't searched when trying to resolve a command to an executable (unless it happens to be in the PATH, in which case it would have been searched regardless).
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.
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
As the title says what does -LA do in a ls command?
I tried reading the manual for ls and this what it said:
-A List all entries except for . and ... Always set for the super-user.
-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P
option.
But I'm not quite sure what those mean.
the ls command prints a list of files and folders in the current directory.
When using ls -A, the command prints out ALL files and folders in the current directory. This includes hidden files and folders (like files/folders starting witch a dot). However, . (current directory) and .. (parent directory) will be ignored.
When using ls -L the command will follow symbolic links and print out the location of the reference too.
When combining this 2 options you get ls -LA which prints out a list of ALL files and folders, and also prints out the references to symbolic links in the folder.
Just try it out in the terminal. You'll see the difference.
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.
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
while compiling the c++ programs in which i'm using the libxml library it is showing errors at the header files that no file or directory found. I have installed the library but it still showing errors. So i just type the above command after that every thing is working fine but i didn't understand it.
what is the meaning of "../" in UNIX? my command in UNIX is like this "sudo cp -r libxml ../" what it means? how to give relative addresses in UNIX and what are the different wildcard is used.
.. represents the parent directory. For example, if the current directory is /home/user/ the parent directory is /home
. represents the current directory
The command sudo cp -r libxml ../ copies the entire directory libxml in the parent directory.