If you are logging in as root you will be dropped in to the /root directory. If you are logging in as a non-root user you will likely be logged in to /home/.
$ ssh root@10.0.0.2
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic x86_64)
$ pwd
/home/vagrant
The prompt above shows the tilde ~
character which is shorthand for your home directory. You can use this in your commands to quickly get back to your users home directory or any relative path in your users home directory.
$ pwd
/usr/local/bin
$ cd ~
$ pwd
/home/vagrant
We will now show an example of changing a directory by giving an absolute path. In Linux, every file and directory is under the top-most directory, which is called the "root" or "slash" directory.
cd /home/vagrant/super/long/directory/path
To disect the command above and show how the system changes to a directory you can think of it like this:
The system cd's to the / directory, then cd's to /home, then to vagrant and so on down the line.
The alternative is to use relative paths. Relative paths refer to directories in relation to the current directory. Using the same path as above a relative path command for cd would look like this:
cd ~/super/long/directory/path
Now that you know how to display the directory that you are in, we can show you how to look at the contents of a directory using the ls
command.
$ ls
do_provisioner.sh install.sh postinstall.sh tokenfile
We can add some optional flags to the command to modify the default behavior. For instance, to list all of the contents in an extended form, we can use the -l flag (for "long" output):
$ ls -l
total 20
-rw-rw-r-- 1 vagrant vagrant 1947 Dec 4 19:58 do_provisioner.sh
-rwxrwxr-x 1 vagrant vagrant 295 Dec 4 19:58 install.sh
-rwxr-xr-x 1 vagrant vagrant 6487 Sep 14 2012 postinstall.sh
-rw-rw-r-- 1 vagrant vagrant 41 Dec 4 19:57 tokenfile
To get a listing of all files, including hidden files and directories, you can add the -a flag.
$ ls -la
total 240
drwxr-xr-x 12 vagrant vagrant 4096 Dec 4 20:07 .
drwxr-xr-x 3 root root 4096 Sep 14 2012 ..
lrwxrwxrwx 1 vagrant vagrant 28 Dec 4 20:00 .aprc -> /home/vagrant/.yadr/irb/aprc
-rw------- 1 vagrant vagrant 2037 Dec 4 20:01 .bash_history
-rw-r--r-- 1 vagrant vagrant 220 Sep 14 2012 .bash_logout
-rw-rw-r-- 1 vagrant vagrant 200 Dec 4 19:53 .bash_profile
-rw-r--r-- 1 vagrant vagrant 3554 Dec 4 19:53 .bashrc
drwx------ 2 vagrant vagrant 4096 Sep 14 2012 .cache
lrwxrwxrwx 1 vagrant vagrant 31 Dec 4 20:00 .ctags -> /home/vagrant/.yadr/ctags/ctags
-rw-rw-r-- 1 vagrant vagrant 1947 Dec 4 19:58 do_provisioner.sh