16

I am following the directions @ Ubuntu community Help; however, I am still confused about a few things. I researched it & found this post: using the terminal to change directory, but it's above me & I'm still not sure how to go about it. I'm new & need a bit extra direction so stick with me! ;-) The following is the script from my terminal:

christy@ubuntu:~$ ls
Desktop    examples.desktop     install-tl-unx.tar.gz  Pictures  Templates
Documents  install-pkgs.log     libnautilus-gksu.so    Projects  Videos
Documents  install-pkgs.log     libnautilus-gksu.so    Projects  Videos
christy@ubuntu:~$ cd/
bash: cd/: No such file or directory

How do I tell what is in which directory and how do I navigate the directory. I know I must be leaving out something simple.

2
  • 4
    You always need a space after the command such as "cd". Your command would work if you enter "cd /", and would move to the root directory. Jul 8, 2012 at 21:26
  • Fantastic, Marty! Your assistance is greatly appreciated. ;-)
    – user74713
    Jul 8, 2012 at 21:53

3 Answers 3

20

In your session ls displays the content of the current directory (but not hidden files starting with a dot in the filename). You navigate into another directory by typing cd dirname. Here you have to substitude "dirname" by a directory's name you want to change into. Normally you start out with your home directory as current working directory. In your case that is most likely /home/christy. If ls shows you a directory called "Template" you can change into "Template" (=make it your current working directory) by typing (mind the space) the command:

cd Templates

you will change your current working directory to "Templates" or print "No such file or directory", if a dir of that name does not exist in your current direcotry. Typing pwd will always give you the full patch to your current working directory including parents.

You can supply optional arguments to each command. For cd the string "Templates" was such an optional argument. If you type ls -a for instance, the ls command will print out hidden files as well. Or with ls Templates it will print the content of the Tempaltes directory instead of you current working dir's content. Arguments must be separated by at least one space from the command name and from each other. The lack of a space between the two was the reason your command did not work.

Since the space character has a special meaning, you will need to quote or escape it, if it's part of an argument. So if for instance you want to change your current working directory to "Source Files" you need to type one of these commands:

cd Source\ Files
cd "Source Files"

The upper line being "escaped" while the lower line is "quoted".

If you want to learn more the better guide for you might be: Introduction to Linux (pdf) (html)


Edit:

Okay now, sorry I didn't see your link there. Your post was a bit misleading, now I think I got you:

So you want to install tex-live from the source archive that is linked in the "Getting Started" guide you posted. To do that you must first remove any pre-existing installation of tex-live. You do that by opening a terminal doing this:

christy@ubuntu:~$ pwd 
/home/christy # <---- This is the directory you are working in
christy@ubuntu:~$ sudo apt-get remove texlive-*
[sudo] password for christy: 

At this point you have to enter you password and will be rewarded with a few boring messages, that I will omit here. Then you'll have to download the archive named install-tl-unx.tar.gz (you already did that and don't have to download it again, but I show you how to do it none the less just in case):

christy@ubuntu:~$ wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz

--2012-07-09 15:08:23--  http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
Resolving mirror.ctan.org... 80.237.159.15
Connecting to mirror.ctan.org|80.237.159.15|:80... connected.
HTTP request sent, awaiting response... 302 Found
# ... some more stuff like this ...
Saving to: `install-tl-unx.tar.gz'

100%[=====================================>] 2,530,831   --.-K/s   in 0.1s    

2012-07-09 15:08:23 (17.3 MB/s) - `install-tl-unx.tar.gz' saved [2530831/2530831]

Now that you have downloaded the archive you can unpack it

christy@ubuntu:~$ tar xvf install-tl-unx.tar.gz
install-tl-20120701/
install-tl-20120701/readme-txt.dir/
install-tl-20120701/readme-txt.dir/README.RU-cp1251
# ... bla bla skipping over some more messages like this ...
install-tl-20120701/readme-html.dir/readme.sr.html
install-tl-20120701/readme-html.dir/readme.ru.html
install-tl-20120701/readme-html.dir/readme.de.html

Now that you've unpacked the archive you can change into the directory that was unpacked.

christy@ubunut:~$ ls | grep install-tl-  # <---- with this line you find out the number
install-tl-20120701                      # <---- in this case "20120701"
install-tl-unx.tar.gz                    # <---- if just this is present with no number you did something wrong
christy@ubuntu:~$ cd install-tl-20120701 # <---- enter this number here
christy@ubuntu:~$ pwd
/home/christy/install-tl-20120701/       # <--- this is your new working directory

The number "20120701" is a timestamp saying which version of tex-live you have. This number might be different for you but the command ls | grep install-t1- will tell you what to use instead. If all this worked, you can run the install script from here:

christy@ubuntu:~$ sudo ./install-tl
[sudo] password for jan: 
Loading http://ftp.univie.ac.at/packages/tex/systems/texlive/tlnet/tlpkg/texlive.tlpdb
Installing TeX Live 2012 from: http://ftp.univie.ac.at/packages/tex/systems/texlive/tlnet
Platform: x86_64-linux => 'x86_64 with GNU/Linux'
# ... bla bla and so on bla ...
Actions:
  <I> start installation to hard disk
  <H> help
  <Q> quit

Enter command: I
# ... and so on ...

From here on just answer the questions you're asked by the install script and you should be fine.

2
  • @ con-f-use: Great info! Now, referring to the terminal script in my original post: What directory is the install-tl-unx.tar.gz in and how do I run it? I'm familiar with the install commands, but I guess I need to install packages? Commands to unpack the tarball are @ ubuntu-manual.org/getinvolved/editors. If you can point me in the right direction... Thank you so much; you've been extremely informative.
    – user74713
    Jul 8, 2012 at 23:17
  • No problem. I'm not sure, what exactly your goal is in the end, so it's a little bit hard to help you without more information. Apparently you're trying to install TeX-Live from the archive 'install-tl-unx.tar.gz'. To do that you must first unpack the archive, than run the install script. I will edited my post above with some instructions to do that soon.
    – con-f-use
    Jul 9, 2012 at 13:00
10

Executive Summary (TL;DR)

  • Use pwd to know where you are (or look between the : and the $ in your prompt).
  • Use cd to change directory elsewhere. Unlike in Windows, cd must always be followed by a space; commands like cd/ and cd.. will not work, but cd / and cd .. will.

Knowing Where You Are

Way 1: Run pwd.

What directory you're currently in is shell-specific (and more generally, application-specific). You could be running one shell where you are in one directory, and another shell where you are in another directory.

To know what directory you are currently in, run:

pwd

For example (from a shell I happen to have open now, on my machine):

ek@Kip:~$ pwd
/home/ek

This tells me that I am in the directory /home/ek. /home is (somewhat confusingly) the directory that contains human users' home directories (it is not itself any user's home directory). The human user username has home directory /home/username.

The root user does not have a home directory in /home. Instead, root's home directory is /root. This is not to be confused with the root directory, which is /.

Way 2: Examine your prompt.

The default configuration for your prompt is that it tells you what directory you are currently in. Your prompt is the text that appears to notify you that the shell is ready to accept a command.

In the example you showed us in your question, your prompt is:

christy@ubuntu:~$

christy is your username. The @ character separates it from ubuntu, your computer's host name. (If you're running a live CD, its hostname will be ubuntu, and some people choose that as their computer's name during installation, too.)

The : character separates it from the name of the directory you are currently in. In this case, that is represented by ~. ~ is shorthand for your home directory. When you're not in your home directory, you should see a full directory name. For example:

ek@Kip:~$ cd /var/log
ek@Kip:/var/log$

(To finish up what each part of the prompt means: For prompts that follow this convention, either a $ or a # character appears. $, as in this case, means it's a normal user shell. A # character would mean it is a root shell.)

Changing Where You Are

Why your "cd" command did not work.

To change directory, use the cd command.

You ran cd/. This does not work because you did not actually run the cd command. In Ubuntu and other Unix-like operating systems (actually, in Unix-style shells like bash, the shell you are using), the name of a command is considered to end only at a space or the end of the line.

So unlike in the Command Prompt in Windows (where cd\ is interpreted the same as cd \ and cd.. is interpreted as the same as cd ..), in bash (the shell you're using in Ubuntu), cd/ is not a valid command. You must use cd /.

cd/ means "the entry in the current directory whose name is cd and which is also a directory." Whether or not such a subdirectory exists, it cannot be run as a command, so either way you'll get an error (though what error you get will differ):

ek@Kip:~$ cd/
bash: cd/: No such file or directory
ek@Kip:~$ mkdir cd
ek@Kip:~$ cd/
bash: cd/: Is a directory

Moving to Your Home Directory

To go to your home directory, run cd by itself without any arguments:

cd

Some people prefer to name their home directory explicitly. You can use its full name, or

cd ~

But cd by itself is sufficient.

Moving Up One Directory

To change directory to the current directory's parent directory (i.e., the directory that contains it), use:

cd ..

.. represents the current directory's parent directory. If you are in the root directory (/), there is an exception: .. just represents /. So running cd .. moves up one directory when run anywhere but /; when run in /, you stay in /.

Every directory contains a .. entry. They also all contain a . entry which refers to the current directory itself. It's not very to run cd . though. You always stay where you are.

Absolute and Relative Paths

If you cd to something that does not start with a /, then it tries to go to that directory within the current directory.

For example, if you ran

cd var/log

Then it would try to go into the var subdirectory of where you currently are, and into the log subdirectory of that. Unless both exist, and in those places, that cd command will fail (and you will remain where you were originally).

If you want to go to the log subdirectory of the var subdirectory of the root directory, run this instead:

cd /var/log

Only if you are currently in / is cd var/log equivalent to cd /var/log.

A path that starts with / is absolute. The way it is resolved does not depend on where you currently are.

The path ~ is absolute too, because it is (essentially) shorthand for $HOME. HOME is an environment variable, and the expression $HOME expands to the full, absolute path of the current user's home directory.

~ notation can also be used to represent another user's home directory. If you write ~username, this represents username's home directory.

Getting Back to Where You Were Before

The directory you are currently in is stored in the PWD environment variable. The last directory you were in is stored in the OLDPWD environment variable. You can view OLDPWD the same way you'd view any environment variable:

echo $OLDPWD

Because this information is stored, cd is able to have a special, quick and easy way to get back to where you were before. As pst007x says, to go to the last directory you were in, run:

cd -

If there was never any earlier directory you were in in that shell, then the OLDPWD environment variable will not have been set, and trying to run cd - will result in an error (and you'll stay where you are):

ek@Kip:~$ cd -
bash: cd: OLDPWD not set

Changing Where You Are Like A Boss

pushd and popd: The Directory Stack

Imagine a stack of directory names. By a stack, I mean something where when you add something it goes on the top, and you can only remove one thing at a time, and the thing you remove is always what's currently on the top.

You can push any directory dir onto the stack by running:

pushd dir

If you want to push the current directory to the top of the stack, you can use . (which, as explained above, always represents the current directory):

pushd .

Then you can go about your business, changing directories as much as you like. When you want to go back to the last directory you pushed onto the stack with pushd, run:

popd

This goes to that directory, and also pops it off the stack. Now the stack is one directory shorter. If that was the only directory on the stack, then the stack is now empty.

You can have a stack of size greater than 1. That is, you can use separate pushd commands to push multiple directories onto the stack. Each subsequent popd command will go to (and pop off, i.e., remove from, the stack) the most recent pushed directory not yet popped.

Here's an example:

ek@Kip:~$ cd /etc/apt/sources.list.d
ek@Kip:/etc/apt/sources.list.d$ pushd .
/etc/apt/sources.list.d /etc/apt/sources.list.d
ek@Kip:/etc/apt/sources.list.d$ pushd /home/ek
~ /etc/apt/sources.list.d /etc/apt/sources.list.d
ek@Kip:~$ cd /var/log/apt
ek@Kip:/var/log/apt$ pushd .
/var/log/apt /var/log/apt /etc/apt/sources.list.d /etc/apt/sources.list.d
ek@Kip:/var/log/apt$ cd
ek@Kip:~$ popd
/var/log/apt /etc/apt/sources.list.d /etc/apt/sources.list.d
ek@Kip:/var/log/apt$ popd
/etc/apt/sources.list.d /etc/apt/sources.list.d
ek@Kip:/etc/apt/sources.list.d$ cd /
ek@Kip:/$ pushd usr
/usr / /etc/apt/sources.list.d
ek@Kip:/usr$ cd
ek@Kip:~$ popd
/ /etc/apt/sources.list.d
ek@Kip:/$ popd
/etc/apt/sources.list.d
ek@Kip:/etc/apt/sources.list.d$ popd
bash: popd: directory stack empty
ek@Kip:/etc/apt/sources.list.d$

pushd and popd are used much less frequently than cd. They also have other, even more advanced uses. Run help pushd and help popd for details.

Learning More and Accessing Documentation

cd and pwd have more advanced uses too. To learn about them, run help cd and man pwd.

help is for shell builtins. man is for standalone commands--commands that run as separate processes and exist as separate executables. The type command reveals if a command is a shell builtin or not and, if not, where the program it runs is located. For example, you could run type help, type type, or type man.

5

For example:

cd Desktop/ Goes to the Desktop directory if you are in your home directory.

cd - Goes back to previous directory.

cd / Take you to the root directory.

cd ~/Desktop Will take you to your Desktop Directory no matter where you are.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .