Why do some simple commands in terminal end up with Cannot Find File or Directory?

Joined
Aug 23, 2016
Messages
5
Reaction score
0
Points
1
So I am new to Terminal, new to anything on the developer side of things. Starting out learning the common line, with that said I am learning basic commands and find when I test these commands in the Terminal I sometime am getting 'No such file or directory' which doesn't make sense as I am sure that I am doing everything properly. My latest example, I am playing around with making multiple intermediate directories, then going to verify that said directory and subfolder were created with the find command.

So this is what I was going off of:

To quickly double-check that all directories were built and that everything worked as intended by using the ‘find’ command like so:
find (parent directory) -type d -print
Using the above example again, the find command would be like so: find ~/Create/ -type d -print
The output of this command would look something like the following, recursively listing out from the parent directory to all child folders:
$ find ~/Create -type d -print
/Create
/Create/These
/Create/These/Folders
/Create/These/Folders/Within
/Create/These/Folders/Within/Each
/Create/These/Folders/Within/Each/Other

And this it my terminal from following the same example:

amberflexhaug$ mkdir -p Make/These/Folders/Within/Each/Other
amberflexhaug$ find ~/Create/ -type d -print
find: /Users/amberflexhaug/Create/: No such file or directory

I don't get it...Please help!!!

Thanks in advance
 
Joined
Nov 28, 2007
Messages
25,564
Reaction score
486
Points
83
Location
Blue Mountains NSW Australia
Your Mac's Specs
Silver M1 iMac 512/16/8/8 macOS 11.6
G'day and welcome to the forums.

May I suggest if you are new to Terminal to keep well away. Can seriously compromise your computer wrong or illegal commands. And none quoted look correct for sudo commands
 

IWT


Joined
Jan 23, 2009
Messages
10,292
Reaction score
2,231
Points
113
Location
Born Scotland. Worked all over UK. Live in Wales
Your Mac's Specs
M2 Max Studio Extra, 32GB memory, 4TB, Sonoma 14.4.1 Apple 5K Retina Studio Monitor
@yamber.harrison

A warm welcome to Mac-Forums.

There are many of us, like Harry and me, who view Terminal like a trip to the Dark Side of the Universe. There are many others on this Forum who use Terminal on a daily basis and are highly authoritative on the subject. We can await their input.

However, I believe almost all would recommend caution when starting out. Having a guiding hand, a tutor, joining a class or using a time-honoured and respected book would seem like a good idea.

As regards the latter, this book would be worth consideration: https://www.amazon.co.uk/dp/B00XV0ZZBA/

I'm sure our Terminal experts will chime in.

Ian
 
OP
Y
Joined
Aug 23, 2016
Messages
5
Reaction score
0
Points
1
Thanks all for your input, I am using a course to guide this journey. I guess I assumed I was relatively safe just learning the basics by creating files/ directories in my Documents via Terminal. Not necessarily digging too deep into "the dark side".
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,771
Reaction score
2,111
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
So I am new to Terminal, new to anything on the developer side of things. Starting out learning the common line, with that said I am learning basic commands and find when I test these commands in the Terminal I sometime am getting 'No such file or directory' which doesn't make sense as I am sure that I am doing everything properly. My latest example, I am playing around with making multiple intermediate directories, then going to verify that said directory and subfolder were created with the find command.

So this is what I was going off of:

To quickly double-check that all directories were built and that everything worked as intended by using the ‘find’ command like so:
find (parent directory) -type d -print
Using the above example again, the find command would be like so: find ~/Create/ -type d -print
The output of this command would look something like the following, recursively listing out from the parent directory to all child folders:
$ find ~/Create -type d -print
/Create
/Create/These
/Create/These/Folders
/Create/These/Folders/Within
/Create/These/Folders/Within/Each
/Create/These/Folders/Within/Each/Other

And this it my terminal from following the same example:

amberflexhaug$ mkdir -p Make/These/Folders/Within/Each/Other
amberflexhaug$ find ~/Create/ -type d -print
find: /Users/amberflexhaug/Create/: No such file or directory

I don't get it...Please help!!!

Thanks in advance

Simple really, the "parent folder" as described in the instructions you were reading indicated that you wanted to used the word Create as your parent directory, however, you ended up using Make as your parent directory. So, two possible fixes, either change the mkdir command as follows:
Code:
mkdir -p Create/These/Folders/Within/Each/Other
...or change the find command
Code:
find ~/Make -type d -print

A quick word of advice from a veteran of the Terminal Wars, always understand WHAT the intention/action/side-effect are of the commands you are running to ensure that you don't cause any damage. Additionally, if you are just going to be playing around creating/deleting folders and so on, you may want to do those in a temporary folder so that you don't mess up your data. On the command line, do
Code:
cd /tmp
and play around there, that folder doesn't have anything of importance and you can safely do anything destructive in there.
 
M

MacInWin

Guest
Also, if you use the Mac for anything other than playing with terminal commands (and maybe even if you don't), you need a bootable backup so that when (not if) you make a fatal mistake and whack the system to the point where it won't boot, you can recover and restore back to some point in time. Note that Time Machine is NOT bootable, so that's not what you need. You want something that boots.

And once it's made, test it to make sure it actually DOES boot.

The "deadly" commands are the ones that use recursion and wildcards. The combination can be really powerful and dangerous.
 
OP
Y
Joined
Aug 23, 2016
Messages
5
Reaction score
0
Points
1
Wow, I feel like I studied that forever and couldn't figure it out. Stare at something too long you loose focus. Thanks for the help and advice,
 
OP
Y
Joined
Aug 23, 2016
Messages
5
Reaction score
0
Points
1
Just out of curiosity, is there a more safe test environment one would use to learn the terminal commands?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,771
Reaction score
2,111
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Just out of curiosity, is there a more safe test environment one would use to learn the terminal commands?

If it's just a matter of focusing on terminal Bash commands or scripting, then the Linux environment is great for that. You can grab a copy of Virtualbox, which is a free virtual machine software and a copy of the Desktop version of Ubuntu Linux. Create a VM with say 20GB of space, about 4GB of RAM and point it at the Ubuntu ISO. Go through the straight-forward installer and now you have an environment you can mess around with.
 
Joined
Apr 16, 2016
Messages
1,096
Reaction score
51
Points
48
Location
CT
Your Mac's Specs
MacBook Air Mid-2012 / iMac Retina 5K Late-2014
Firstly, take the warnings about the Terminal with some "context". The folks warning you to stay away likely are not experienced with the command line and [rightfully] are a bit concerned (because they know the damage it can do if used incorrectly) or have actually been bitten by a command gone bad.

The biggest warning I can give you is to truly understand the command you are about to issue and to understand whether or not it is a "write" type of command (will change something) or read-only.

Bash is bash. Mac, Linux, Unix, and a fair number of various appliances all use it. If you really want a place just to tinker, I'd suggest you consider building some sort of development machine to become familiar with the command line and interacting with Bash. Get a Linux distribution and install it into an old Windows PC machine that you don't need any more or install something like VirtualBox on your Mac and create a virtual machine that you can boot up and work in INSIDE of the Mac. This second option has advantages, but may require an additional learning curve if you're not already familiar with Type II Hypervisor products and virtualization.

As far as the command you cited at the beginning: You can't find what you didn't create. Your find command should work, but ONLY if you actually created the folders where you believe you did. If created a folder called Create but did not actually create it at the top level of your personal directory, would likely need to change the command as follows:

find ~ Create -type d -print

Now you're searching starting at the top of your personal directory for anything that is a directory and matches "Create".

One other thing... Don't EVER enter your admin password or use "sudo" in the terminal unless you absolutely know what you're doing. You can crash out your system in the blink of an eye if you do something "wrong".
 
Joined
Jan 20, 2012
Messages
5,069
Reaction score
433
Points
83
Location
North Carolina
Your Mac's Specs
Air M2 ('22) OS 14.3; M3 iMac ('23) OS 14.3; iPad Pro; iPhone 14
@yamber.harrison

There are many of us, like Harry and me, who view Terminal like a trip to the Dark Side of the Universe. There are many others on this Forum who use Terminal on a daily basis and are highly authoritative on the subject. We can await their input.

However, I believe almost all would recommend caution when starting out. Having a guiding hand, a tutor, joining a class or using a time-honoured and respected book would seem like a good idea.

As regards the latter, this book would be worth consideration: https://www.amazon.co.uk/dp/B00XV0ZZBA/

Hi Yamber - I second Ian's excellent advice above; there are plenty of experienced terminal users in the forum, so if you're not sure about a command, then check here first - the lack of a space or a parameter/switch (or the addition) can be destructive and make your computer inoperable. Also, like any complex topic which requires remembering a lot of steps, features, etc. can be daunting to use if not on a daily basis - I occasionally delve into the 'terminal' but must admit when I return weeks later, most of what I've learned has left my head - yes, frustrating.

On my iPad, I have the two books below (one suggested by Ian - which is the shorter text w/ less detail but a good start) - the other book which has just come out in a second edition (I need to upgrade, in fact) is longer, much more thorough, and quite good. Good luck but always be wary when on the terminal line. Dave :)
.
Screen Shot 2016-08-24 at 10.52.01 AM.png Screen Shot 2016-08-24 at 10.50.01 AM.png
 
M

MacInWin

Guest
Firstly, take the warnings about the Terminal with some "context". The folks warning you to stay away likely are not experienced with the command line and [rightfully] are a bit concerned (because they know the damage it can do if used incorrectly) or have actually been bitten by a command gone bad.
Or, the folks giving the warning have see the damage that an errant CLI command can do and get nervous when they see rookies learning bash on a system that may or may not be critical to them. Like a lot of tools, bash is neither good nor bad, it just is. It's how it can be used that makes it dangerous for newbies. As a former operator and sysop of AIX, HPUX, Linux and true Unix systems, I've seen my share of disasters, some from some fairly knowledgable people who didn't check their typing before hitting Enter. Witness the OP's own comments:
Wow, I feel like I studied that forever and couldn't figure it out. Stare at something too long you loose focus.
She "knew" she had typed it correctly. But she hadn't. If the command were to rm the directory instead of mkdir, she could have created a disaster.

So, the advice to be careful of the lure of the CLI is simply that, advice to be careful. If I were her, I'd stay away from the CLI unless and until I had a fully functioning clone backup in place, just in case I fumble-fingered my way to "rm * -rf" at root. (BTW, we actually used that command in production, as a way to protect against intrusions on a business system at a major university. We had a gateway system connected to the Internet through which all traffic passed to the business systems, not the student systems. If our firewall detected a dedicated attempt to bypass our security, we ran that command on the gateway and just crashed it for the day. We had the luxury of not needing to be online to the Internet all the time. Next day we would restore the system from a backup and get back online. That approach really frustrated the CS students and the entire engineering school because both groups prided themselves on being able to get past any firewall. But one of my sysops was an engineer who had worked for AT&T on the original Unix code and knew just about every hole in the system. Yes, it was unfair. :) )
 
Joined
Apr 16, 2016
Messages
1,096
Reaction score
51
Points
48
Location
CT
Your Mac's Specs
MacBook Air Mid-2012 / iMac Retina 5K Late-2014
MIW: I'm with you. While your experiences seem to have been of having been a witness to disaster, I was lumping that in with those that "have actually been bitten by a command gone bad" without actually articulating it.

The point that I was trying to make was that you don't need to run screaming from the Command Line in terror because it's a dangerous place. You need to be cautious and aware that one wrong keystroke can total your system.

Here's one for only the bravest among us to try:

sudo rm -rf /


That should turn your beautiful system into a brick rather quickly and efficiently.

Seriously... do NOT run that command!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top