LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cd command and "No such file or directory" error (https://www.linuxquestions.org/questions/linux-newbie-8/cd-command-and-no-such-file-or-directory-error-794303/)

penguiniator 03-10-2010 05:21 PM

Point taken. It wasn't taken personally.

runinguy 03-11-2010 01:59 AM

Quote:

Originally Posted by bret381 (Post 3893222)
you can move executables to your /usr/bin directory and you won't have to use the ./ in front of it

I don't know what would be required to move each executable from its source code directory to this /usr/bin directory, but it seems like it would be simpler to type ./ before each executable. Maybe someone can enlighten me on what the /usr/bin directory is, and how I would go about moving these executable files to there, and then I can make a more informed decision.

Also, I would still like to know exactly what it is that I am doing when I use the ./ command?

colucix 03-11-2010 02:45 AM

Quote:

Originally Posted by runinguy (Post 3893880)
Also, I would still like to know exactly what it is that I am doing when I use the ./ command?

You should definitively read something about where the shell look for commands and the PATH environment variable. Here is a good starting point.

Personally, I'd not put my own executables in /usr/bin, since this is the place where many system wide commands are placed (moreover you need root privileges to add/remove something from /usr/bin). Better to keep them in your HOME directory, for example in /home/user/bin (user being your true user name). Furthermore, this directory is already listed in the PATH environment variable by many Linux distributions.

Hope this helps.

runinguy 03-11-2010 11:59 AM

Quote:

Originally Posted by colucix (Post 3893903)
You should definitively read something about where the shell look for commands and the PATH environment variable. Here is a good starting point.

Personally, I'd not put my own executables in /usr/bin, since this is the place where many system wide commands are placed (moreover you need root privileges to add/remove something from /usr/bin). Better to keep them in your HOME directory, for example in /home/user/bin (user being your true user name). Furthermore, this directory is already listed in the PATH environment variable by many Linux distributions.

Hope this helps.

Hey that's great thanks for the link, very informative.

Through my experimentation, it seems then that to move a file from its current directory to a subdirectory I use the command mv, then the name of the fie, then the name of the subdirectory into which I want to move the file. What if I want to go in the other direction though? For example:

BenardLenards-MacBook-Pro:g95 BenardLenard$ mv g95manual.pdf "fortran code files"
BenardLenards-MacBook-Pro:g95 BenardLenard$ ls
Fortran Code Files bin
INSTALL lib
BenardLenards-MacBook-Pro:g95 BenardLenard$ cd "fortran code files"
BenardLenards-MacBook-Pro:fortran code files BenardLenard$ ls
a.out g95manual.pdf ini_1.f95 ini_2.f95
BenardLenards-MacBook-Pro:fortran code files BenardLenard$ pwd
/Users/BenardLenard/g95/fortran code files
BenardLenards-MacBook-Pro:fortran code files BenardLenard$ ls
a.out g95manual.pdf ini_1.f95 ini_2.f95
BenardLenards-MacBook-Pro:fortran code files BenardLenard$ mv g95manual.pdf g95
BenardLenards-MacBook-Pro:fortran code files BenardLenard$ ls
a.out g95 ini_1.f95 ini_2.f95
BenardLenards-MacBook-Pro:fortran code files BenardLenard$

Here we can see that I have moved the file "g95manual.pdf" from the G95 directory into the subdirectory "Fortran Code Files" with success. Then, when trying to move the same file back to its original position, I seem to have somehow renamed the file to "g95" instead of moving it to the g95 directory.

My questions are:
How can I rename it to what it originally was.
How can I move the file to where it originally was.

(on a side note, what does the command "cd `" do? I accidentally entered this instead of "cd ~" and it gave me a ">".

MTK358 03-11-2010 12:14 PM

I would recommend you not use spaces in filenames, they are difficult to deal with because the shell assumes that spaces separate a list of filenames.

colucix 03-11-2010 12:44 PM

Code:

mv g95manual.pdf g95
This caused the file g95manual.pdf to be renamed as g95. What you really need when moving/copy files is to specify an absolute or relative path for the destination directory. Examples:
Code:

mv g95manual.pdf ..    # .. is a shortcut for the upper level directory

mv g95manual.pdf g95    # it moves the file in the g95 directory at the
                        # same level (if it exists, otherwise it simply
                        # renames the file as "g95" - this is what happened)


mv g95manual.pdf ./g95  # same as above, but we have specified a
                        # relative path here, where . is a shortcut
                        # for the current working directory


mv g95manual.pdf /Users/BenardLenard/g95
                        # full (absolute) path here: no way to mis-understand:
                        # the shell moves the file in that exact location (if it
                        # exists, otherwise move it to /Users/BenardLenard/ and
                        # rename it as "g95" at the same time

Hopefully, now you should be able to rename the file "g95" as "g95manual.pdf" and move it to its original location! :)
Quote:

cd `
Here you (accidentally) used an opening reverse quote (backtick) and the shells expects a closing one to complete the pair. When you press enter, the shell just offers its secondary prompt (the symbol ">" you have seen) to let you complete the command line. If you had typed another backtick and pressed enter the command would have been actually executed. You can try that and see what happens (trust me, nothing harmful... just use the pwd command after that, to see what is your current directory)
Code:

cd `
> `


MTK358 03-11-2010 01:11 PM

The way the backticks work is that they are substituted for the output of the command in them.

Code:

$ pwd
/home/michael
$ cd `echo '..'`
$ pwd
/home

The output of echo '..' is a pair of dots, which are then substituted for the backticks and their contents.

Note that the backticks are sometimes considered "deprecated". This is the new way:

Code:

$ pwd
/home/michael
$ cd $(echo '..')
$ pwd
/home

The $() is not as easily confused for single quotes, and also it makes nesting easier.

runinguy 03-11-2010 03:06 PM

So it seems that the ticks can be used to embed one command within another. Why is it then that if I put nothing between the ticks, for example:
Code:

cd ``
or
Code:

cd `
>`

it takes me directly to my user directory?

Also, if . is a shortcut for the current working directory, what is the / for?

penguiniator 03-11-2010 04:06 PM

The default action for cd is to change to your home directory. cd `` is equivalent to cd.

Path name components are separated by /, so when you specify the current directory with ., a slash must separate it from the file name following.


All times are GMT -5. The time now is 02:33 PM.