Command to change directory in linux

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

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:

Читайте также:  Windows прочитать диск linux

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.

Источник

Terminal Basics #1: Changing Directories in Linux Terminal

Learn how to change directories in the Linux command line using absolute and relative paths in this part of the Terminal Basics series.

The cd command in Linux allows you to change directories (folders). You just have to give the path to the directory.

And here comes the first challenge if you are new to Linux. You are probably not sure about the path. Let's tackle that first.

Understanding paths in Linux

The path traces the location in the Linux directory structure. Everything starts at the root and then goes from there. You can check your current location with the following:

Path in Linux

It should show an output like /home/username. Of course, it will be your username. As you can see, paths are composed of / and directory names. Path /home/abhishek/scripts means the folder scripts is inside the folder abhishek , which is inside the folder home . The first / is for root (from where the filesystem starts), the trailing / are separators for the directories.

Type ls / in the terminal and press enter. It will show you the content of the root directory. Try it.

  • . (single dot) denotes the current directory.
  • .. (two dots) denote the parent directory taking you one directory above the current one.

Here's a pictorial representation.

Absolute path vs relative path

Want more on paths in Linux? This article will help you.

Changing directory with cd command

Now that you are familiar with the concept of path, let's see how you can change the directory.

If you just type cd and press enter, it will take you to your home directory from any location. Go on, try it.

Enter the following command to see the directories inside your home directories:

This is what it shows to me:

[email protected]:~$ ls Desktop Downloads Pictures Templates VirtualBoxVMs Documents Music Public Videos 

Yours may be similar but not exactly the same.

Let's say you want to go to the Documents directory. Since it is available under the current directory, it will be easier to use the relative path here:

The default terminal emulators of most Linux distributions show you the current location in the prompt itself. You don't have to use pwd all the time just to know where you are.

Most Linux terminal prompts show the current location

Now, let's say you want to switch to the Templates directory that was located in your home directory.

You can use the relative path ../Templates (.. takes you to the one directory above Documents to /home/username and from there you go to Templates).

But let's go for the absolute path instead. Please change 'abhishek' with your username.

Now you are in the Templates directory. How about going to the Downloads directory? Use the relative path this time:

Here's a replay of all the above directory change examples you just read.

Utilize the tab completion in the terminal. Start typing a few letters of the command and directory and hit the tab key. It will try to autocomplete or show you the possible options.

Troubleshooting

You may encounter a few common errors while changing the directories in Linux terminal.

No such file or directory

If you see an error like this while changing the directories:

Then you made mistake with the path or name of the directories. Here are a few things to note.

Common examples of

  • Make sure there is no typo in the directory name.
  • Linux is case sensitive. Downloads and downloads are not the same.
  • You are not specifying the correct path. Perhaps you are in some other location? Or did you miss the first / in the absolute path?

Not a directory

If you see an error like this:

It means that you are trying to use the cd command with a file, not a directory (folder). Clearly, you cannot enter a file the same way you enter a folder and hence this error.

Not a directory error with the cd command

Too many arguments

Another common rookie Linux mistake:

The cd commands take only one argument. That means that you can only specify one directory to the command.

If you specify more than one or mistyped a path by adding a space to the path, you'll see this error.

Too many arguments error in Linux terminal

If you press cd - , it will take you to your previous directory. It's quite handy when you are switching between two distant locations. You don't have to type the long paths again.

Special directory notations

Before ending this tutorial, let me quickly tell you about the special notation ~ . In Linux, ~ is a shortcut for the user's home directory.

If user abhi is running it, ~ would mean /home/abhi and if user prakash was running it, it would mean /home/prakash .

To summarize all the special directory notations you learned in this chapter of the terminal basics series:

Notation Description
. Current directory
.. Parent directory
~ Home directory
- Previous directory

Test your knowledge

Here are a few simple exercises to test your newly learned knowledge of the path and the cd command.

Move to your home directory and create a nested directory structure with this command:

mkdir -p sample/dir1/dir2/dir3
  • Go to the dir3 using either absolute or relative path
  • Move to dir1 using relative path
  • Now go to dir2 using the shortest path you can imagine
  • Change to the sample directory using absolute path
  • Go back to your home directory

Want to know if you got all of them right or not? Feel free to share your answers in the It's FOSS Community.

Now that you know how to change directories, how about you learn about creating them?

I highly recommend reading this article to learn small but useful things about the terminals and the commands.

Stay tuned for more chapters in the Linux Terminal Basics series if you want to learn the essentials of the Linux command line.

And, of course, your feedback on this new series is welcome. What can I do to improve it?

Источник

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