Linux set current dir

How do I change directories in the terminal, and know which directory I’m in?

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.

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.

3 Answers 3

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:

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».

Читайте также:  Linux command to install app

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

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 #  

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- #  

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: start installation to hard disk help 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.

Источник

How to Use the Linux cd Command to Change Directory

Many Linux commands, such as the ls command, affect the current working directory. The current working directory is the directory your terminal window or command prompt is working in.

Linux treats the Home directory as the default working directory. Using the cd command in Linux allows you to change the current working directory.

In this tutorial, we will explain the cd command syntax and show examples of how you can use it.

How to use the Linux cd command to change directory

  • A system running a Linux distribution.
  • A user account with sudo privileges.
  • Access to the terminal window or command line.

Linux CD Command Syntax

The cd command in Linux uses the following syntax:

  • cd : Invokes the cd command.
  • [options] : Adding options changes the way the command executes.
  • [directory] : Path to the directory you want to move into.

For instance, to move to the Desktop directory, run:

If the command executes successfully, the current working directory is indicated in the terminal interface:

Path to the current working directory

If the terminal interface does not indicate the current working directory, using the pwd command displays it as the output:

Using the pwd command to show the current working directory

The cd command uses the following options:

  • -L : Force following symbolic links. This option is enabled by default.
  • -P : Do not follow symbolic links. This option resolves the symbolic link to determine the parent directory before moving to the user-requested directory.
  • -e : Exit with a non-zero status if using the -P option and the command cannot resolve the symbolic link.
  • -@ : Present a file with extended attributes as a directory containing the file attributes.

How to use Linux CD Command

The Linux cd command offers several ways to navigate and change the working directory using the terminal window. It lets you change directories using relative and absolute paths, move to parent or root directories, or find directories with incomplete names.

Note: The cd command is a built-in shell command. This means that its behavior varies slightly between shells since it uses shell environment variables. Learn more in our guide to environment variables in Linux.

Changing Directory

To change to a new working directory, use the cd command with a directory path.

For instance, moving to Example_Directory, located in the Home directory:

Using the cd command to change the current working directory

Change Directory and List Content

Append the ls command to the cd command using the && flag to change to a new directory and list its content simultaneously.

Using the previous example:

Using a combination of cd and ls command to change to a new working directory and list its contents

Note: Add ls command options to change the way directory contents are displayed.

Changing Directory Using an Absolute Path

Using an absolute path to the directory means that the path starts from the root directory. For instance, changing to the Downloads directory using its absolute path:

cd /home/phoenixnap/Downloads

Changing to a new working directory using the absolute path

Changing Directory Using a Relative Path

A relative path is a path to a directory relative to the current working directory. A relative path is best used when changing to a subdirectory of the current working directory.

In the example above, the Downloads directory is a subdirectory of Home. In this case, a relative path is a result of omitting the path to the current directory from the path to the new working directory:

Changing to a new working directory using the relative path

Since the path to the current directory is /home/phoenixnap, omitting that part of the absolute path to the Downloads directory (/home/phoenixnap/Downloads) results in a relative path (Downloads).

Changing to the Previous Directory

Adding a dash symbol ( - ) to the cd command returns the shell to the previous working directory. For instance, after moving from Downloads to Example_Directory, return to Downloads with:

Changing back to the previous working directory

Changing to Parent Directory

To change to the parent of the current directory, add two period symbols ( .. ) to the cd command.

For example, to move from Example01 to its parent directory Example_Directory:

Changing to the parent of the current working directory

Changing to the Root Directory

Add the slash symbol ( / ) to the cd command to move into the system's working directory:

Changing to the system root directory

Changing Back to the Home Directory

In Linux, the Home directory represents the default working directory. Using the cd command without any options or path changes back to the default working directory:

The absence of the current working directory path indicates that you are in the default working directory:

Changing back to the default working directory

Another way to do this is to add the tilde symbol ( ~ ) to the cd command:

Changing to Another User's Home Directory

Change to another user's Home directory by adding the tilde symbol ( ~ ) appended with the appropriate username.

For instance, changing to the Home directory of a user named alex:

Changing to another user

Changing to a Directory with Spaces in the Name

If the directory name contains blank spaces, change to it by surrounding the name with single quotation marks ( ' ' ). Alternatively, append a backslash symbol ( \ ) to every word in the name except the last one:

cd 'Directory name with blank spaces' cd Directory\ name\ with\ blank\ spaces 

For example, changing to a directory named This is a directory:

cd 'This is a directory' cd This\ is\ a\ directory 

Changing to a directory with blank spaces in the name

Autocomplete Directory Name

If you don't know the name of the directory you are trying to move to, the Linux terminal offers an autocomplete feature. After you start typing the directory name, press the Tab button on your keyboard to get autocomplete suggestions.

For instance, if you know that the name of the directory starts with an X (for instance, XYZ), type:

After reading this tutorial, you should be able to use the Linux cd command to navigate and change the current working directory in the terminal window.

Learn more about other Linux commands in our Linux commands cheat sheet.

Источник

Оцените статью
Adblock
detector