cd .. command

hi,

i have installed cygwyn and practicing on my local windows laptop
https://cygwin.com/install.html

i gave commands as below


saiganesh@LAPTOP-EJBON1NM ~
$ whoami
saiganesh

saiganesh@LAPTOP-EJBON1NM ~
$ ls

saiganesh@LAPTOP-EJBON1NM ~
$ pwd
/home/saiganesh

saiganesh@LAPTOP-EJBON1NM ~
$  cd /

saiganesh@LAPTOP-EJBON1NM /
$ ;s
-bash: syntax error near unexpected token `;'

saiganesh@LAPTOP-EJBON1NM /
$ ls
bin       Cygwin.bat  Cygwin-Terminal.ico  etc   lib   sbin  usr
cygdrive  Cygwin.ico  dev                  home  proc  tmp   var

saiganesh@LAPTOP-EJBON1NM /
$ cd home/saiganesh

saiganesh@LAPTOP-EJBON1NM ~
$ pwd
/home/saiganesh

saiganesh@LAPTOP-EJBON1NM ~
$ cd ..

saiganesh@LAPTOP-EJBON1NM /home
$ ls
saiganesh


saiganesh@LAPTOP-EJBON1NM /home
$


my question is when i gave cd .. it supposed to go to home right and when i said ls it should have said home instead of saying saiganesh
please advise
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JustInCaseCommented:
it supposed to go to home right and when i said ls it should have said home
Actually, no.
cd .. will get you to parent directory ( since you were in home/saiganesh parent directory is home) and ls will list context of that directory (so saigash will be listed)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prabhin MPEngineer-TechOPSCommented:
Hi,
The command cd .. means goto previous directory not the home directory.
use cd ~ to go to Home directory.
0
gudii9Author Commented:
Actually, no.
cd .. will get you to parent directory ( since you were in home/saiganesh parent directory is home) and ls will list context of that directory (so saigash will be listed)
my bad i should have typed pwd not ls here


i verified here
sh-4.4$ /bin/bash                                                                                                                        
bash-4.4$ ls -ltr                                                                                                                        
total 4                                                                                                                                  
-rw-r--r-- 1 25589 25589 978 Jan 29 20:03 README.txt                                                                                      
bash-4.4$ pwd                                                                                                                            
/home/cg/root                                                                                                                            
bash-4.4$ mkdir gp2                                                                                                                      
bash-4.4$ ls -ltr                                                                                                                        
total 8                                                                                                                                  
-rw-r--r-- 1 25589 25589  978 Jan 29 20:03 README.txt                                                                                    
drwxr-xr-x 2 25589 25589 4096 Jan 29 20:03 gp2                                                                                            
bash-4.4$ cd gp2                                                                                                                          
bash-4.4$ pwd                                                                                                                            
/home/cg/root/gp2                                                                                                                        
bash-4.4$ cd ..                                                                                                                          
bash-4.4$ pwd                                                                                                                            
/home/cg/root                                                                                                                            
bash-4.4$ ^C                                                                                                                              
bash-4.4$
0
Ernie GronblomCloud Systems EngineerCommented:
Directory structure is a tree.  The directory you cd to is your current working directory, which is referenced as dot (.) and the previous directory in the tree is dot dot (..).  So, when you are in /home/cg/root/gp2, cd .. will go 'up' one level to /home/cg/root and cd .. typed from there will go to /home/cg.
You can see the .. in your ls -l output if you also use a (ls -la).
home
   cg
      root
          gp2
In /home/cg/root, you can cd gp2 and get to /home/cd/root/gp2.  In /home you can type cd cg/root to get to /home/cg/root.  In /home/cg/root, you can type cd ../.. to get to /home (../.. means go up TWO directories in the tree.  The first .. gets you to /home/cg and the second goes to /home.

The only exception is the .. in / (top level directory, or root directory - not related to the root user) points to . so if you cd .. from / you will be in / still.  If you are in /home and you type cd ../.. you will be in home (the first goes to / and the second goes nowhere).  You can cd ../../../../../../.. and you will most likely be at / afterwards, unless you are already more than 7 levels deep in the directory tree.

You mentioned going 'home'.  The tilde (~) is special which means 'home directory'.  Your home directory is just ~ alone, while you can specify another user's home directory like ~root so if you cd ~root you will end up in the root user's home directory (if you are logged in as root, just cd ~ will do the same thing).

So you can cd / to get to the 'top level', also known as filesystem root directory (which is different than the user 'root' user home directory).
You can cd to a specific spot in a directory tree by cd /dir/dir/dir (cd /home/cg/root) which is an absolute path (it doesn't matter where your current directory is).  You can specify a relative path by not starting with a /, like cd cg/root from the /home directory.  If you cd cg/root from the / directory, you will get an error because there is no /cg/root, so the cd command is run relative to your current directory.  The cd is a relative type of cd because it always goes up a level, unless you are already at the top level.

Ernie
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.