You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Why directory name is not recognized from Terminal window, but is recognized from my MacBook Air desktop?

Can anybody help me to understand, what is going on, please?

I have created a folder on my Desktop and put subfolders inside with individual files  (HideIt is the name of this folder). 

I  close  HideIt folder.

I  open   HideIt folder again. 

I can see the files, copy them, close , delete. No problems.

Now I open  Terminal utility

I  can see my desktop

when i type “ ls -l “ ,  I see the following:   drwx------@ 14 grigoryzubkis  staff     448 Jun 11 02:53 Desktop

I type “ cd Desktop”, 

type “ ls -l “ I see the following: drwxr-xr-x@ 28 grigoryzubkis staff 896 Jun 10 09:27 HideIt 

I try to step down into HideIt directory “ cd Hideit “, but get back: “ cd: no such file or directory: Hideit”

Why is that? Why      “ ls -l “ does show me directory, but when I try to step down into this directory  “ cd Hideit “, it doesnot work?

I try another thing. Instead of typing “ cd Hideit “,     I type “ cd Hide* “, and it works?

What is going on?????

Also when somehow I try to copy or delete or whatever files inside “ HideIt “ folder  , It does not work?

But if i do it just from my desktop, but not from Terminal utility,  it does work?

Any help is greatly appreciated.



MacBook Air 13″, macOS 12.4

Posted on Jun 11, 2022 5:52 AM

Reply
Question marked as Top-ranking reply

Posted on Jun 11, 2022 8:57 AM

spaces in file names and folders.


If you are going to be working from the command line a lot, then when you are naming a file or folder, just use _ (Underscore) where you would put a space, and your life in the command line will be easier.


Where you do not have control, or should not change a name macOS created, then you either single quote, double quote or backslash quote the name


Folder greg

would be specified on the command line as one of the following:

"Folder greg"
'Folder greg'
Folder\ greg


You can drag and drop a file or folder from the Finder to the Terminal window, and it will be properly quoted for use.


Copying a directory


cp -rp /path/to/directory/to/be/copied  /path/to/parent/directory/


So if I have a directory $HOME/Downloads/Fred and I want to make a copy in the parent directory $HOME/Documents, I would enter:

 cp -Rp  $HOME/Downloads/Fred  $HOME/Documents/

OR

cd $HOME/Downloads
cp -Rp Fred  $HOME/Documents/

Or

cd $HOME/Documents
cp -Rp $HOME/Downloads/Fred  ./


The -R will is for recursive and it will make sure all subdirectories under Fred are copied as well.

The -p is so that file permissions are preserved.

5 replies
Question marked as Top-ranking reply

Jun 11, 2022 8:57 AM in response to grigory193

spaces in file names and folders.


If you are going to be working from the command line a lot, then when you are naming a file or folder, just use _ (Underscore) where you would put a space, and your life in the command line will be easier.


Where you do not have control, or should not change a name macOS created, then you either single quote, double quote or backslash quote the name


Folder greg

would be specified on the command line as one of the following:

"Folder greg"
'Folder greg'
Folder\ greg


You can drag and drop a file or folder from the Finder to the Terminal window, and it will be properly quoted for use.


Copying a directory


cp -rp /path/to/directory/to/be/copied  /path/to/parent/directory/


So if I have a directory $HOME/Downloads/Fred and I want to make a copy in the parent directory $HOME/Documents, I would enter:

 cp -Rp  $HOME/Downloads/Fred  $HOME/Documents/

OR

cd $HOME/Downloads
cp -Rp Fred  $HOME/Documents/

Or

cd $HOME/Documents
cp -Rp $HOME/Downloads/Fred  ./


The -R will is for recursive and it will make sure all subdirectories under Fred are copied as well.

The -p is so that file permissions are preserved.

Jun 11, 2022 6:47 AM in response to BobHarris

Thanks a lot!

You are absolutely right!!!!

I have a trailing space at the end of directory name . So, directory name is not "HideIt", but "HideIt " !!!!


Another question:

when i use " cp " comand to copy complete directory to another direcory , how do I specify directory name?

Or if the source directory name is "Folder greg" (with space embedded between "Folder" and "greg" , how must my "cp" command look like?

Thanks a lot for help.


Why directory name is not recognized from Terminal window, but is recognized from my MacBook Air desktop?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.