"No such file or directory", trying to copy files in terminal?

Hi there,


I'm just starting to learn how to use the terminal, and I'm starting with simple commands. I'm trying to copy a little test file I made, but no matter what I do I get "No such file or directory". I've also tried deleting the file and moving it, with the same exact results. I've looked up multiple online tutorials and followed them to a T, but I still get the same thing.


Here's the exact lines...

Jaylies-MacBook-Pro:~ jayliepiatt$ cp TestFile.txt TestFile-Copy.txt cp: TestFile.txt: No such file or directory Jaylies-MacBook-Pro:~ jayliepiatt$


I'll ask if you could keep it in total layman's terms, as I literally just decided to learn how to use the terminal tonight.


Thank you!

Mac Pro, OS X Yosemite (10.10.3)

Posted on Oct 31, 2015 6:21 AM

Reply
11 replies

Oct 31, 2015 6:57 AM in response to afternoonofthefaun

Let's say you are in your home directory. The standard shortcuts that red_menace suggested are among the following, all of which do the same thing — make a copy of TestFile.txt in the current directory location.

cp ./TestFile.txt TestFile-Copy.txt

cp ~/TestFile.txt TestFile-Copy.txt

cp $PWD/TestFile.txt TestFile-Copy.txt

cp $HOME/TestFile.txt TestFile-Copy.txt


The Bash Shell that supplies your Terminal prompt, and interactivity — only knows what you tell it about your current filesystem location. Thus, the prefixes to your files as shown above, help Bash understand.

Oct 31, 2015 3:29 PM in response to afternoonofthefaun

afternoonofthefaun wrote:


Tried this, dragged and dropped in the terminal then pressed return, and all I got was

" -bash: /Users/jaylielastname/Documents/TestFile-Copy.txt: Permission denied

Jaylies-MacBook-Pro:~ jaylielastname$ "

You type

cp <and type a space>

then you drag and drop the file from the Finder to the Terminal

<and type a space>

then drag and drop the destination folder from the Finder to the Terminal

<and type a return>

Do this a few times and you will start to learn the correct syntax.


Of course we just told you how to copy one file. If you tell us why you are using the Terminal instead of the Finder, we might be able to give you more useful information.

Nov 1, 2015 11:47 AM in response to afternoonofthefaun

Be sure to do a complete backup of your system. It's ease to mess up your system from the terminal.


Here is an overview of the terminal commands. Lets assume that your account has a short user name of mac.
Macintosh-HD -> Applications -> Utilities -> Terminal
#What is my short user name? Type the whoami command.
mac $ whoami
mac
mac $
#How to list all of your disks.
# The ls command is for list
mac $ ls /Volumes/
Audio CD Macintosh-HD Spotless Tiger-ext
mac $
# Let's say your flash drive is named Spotless


# cd is change directory
mac $ cd /Volumes/Spotless
# pwd is Print Working Directory. A directory is the Unix name for a folder. You are always in a directory.
mac $ pwd
/Volumes/Spotless
mac $
# The ls command is for list
# l is long
# F is type of file where / is directory. For directories, the slash is pasted to the end of the name.
mac $ ls -lF
total 134704
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files/
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards/
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009/
... trimmed ...
What does all this mean?

drwxrwxrwx

d = directory
r = read
w = write
x = executeable program

drwxrwxrwx
|| &nbsp|&nbsp |
|| | all other users not in first two types
|| |
|| group
||
|owner
|
What type of entry is this? d = directory, - = file, etc.


Every Unix resource: files, folders, etc has an owner, group, other
A Unix resource has one owner.
A Unix resource has one group. A group contains a list of users.


To gain access to a file, you can be the owner, in the group, or not the owner and not in the group hence you end up as other. The owner, group, or other has read, write, or execute permissions.


# l is long
# a is all to show hidden files & folders
mac $ ls -lFa
total 134736
drwxr-xr-x 41 mac staff 1496 Dec 22 17:11 .
drwxrwxrwt 8 root admin 272 Dec 24 13:55 ..
-rwxrwxrwx 1 mac staff 15364 Dec 23 12:52 .DS_Store*
drwx------ 4 mac staff 136 Jan 22 2009 .Spotlight-V100
drwxrwxrwt 5 mac staff 170 Sep 14 16:36 .TemporaryItems
d-wx-wx-wx 4 mac staff 136 Dec 31 1969 .Trashes
-rw-r--r-- 1 mac staff 64560 Mar 3 2009 A-picture-of-Youpi-key.png
drwxr-xr-x 83 mac staff 2822 Nov 7 14:52 Applescript files
drwxrwxrwx 12 mac staff 408 Dec 13 2008 Christmas Cards
drwxr-xr-x 9 mac staff 306 Dec 21 17:39 Christmas Cards 2009

... trimmed ...
# mv is move or rename
mv -i the-name the-new-name




# You can just rename the file back to what it was with mv command.
mv -i old-name new-name


Here is what these commands mean:
cd is change directory
pwd is a print working directory
ls is list
sudo is Super user do
mv is move or rename


For cryptic comments, you can always uses the manual command which is man. For example:
man mv


# Type the letter q to quit.
In case you have spaces in your filenames or directories, you need to escape them. See examples:

mac $ ls -l ~/"see it"
-rw-r--r-- 1 mac staff 3171 Oct 26 23:38 /Users/mac/see it
mac $
mac $ cd /Users/mac/Desktop/ttt\ html\ copy/


Do you know about tabbing? Type in a few letters of a name then press the tab key. The computer will type out the rest of the name if it is unique.


Press the up arrow key to see the previous command(s).


To edit a command, use the left arrow key to more left and the right arrow key to move right. Use the delete key to delete the key to the left. Type a letter to insert.


history to see many previous commands.


mac $ history

1 pwd

2 man ls

3 history

You may copy then paste from this list.


----------------------


http://discussions.apple.com/thread.jspa?threadID=2692161&tstart=0


Robert

Nov 1, 2015 8:50 PM in response to BobHarris

Thank you, this helped.


I dragged and dropped and it worked fine, copied right where I wanted to. Then I tried actually typing out the command and got the same message I've bene getting. I copied exactly the text it showed when I dragged and dropped, but for some reason something's different. No clue why.


To answer your last question, I'd eventually like to learn something like Python, and I feel like it's a good idea to at least be able to execute basic commands on the terminal first.

Nov 2, 2015 6:25 AM in response to afternoonofthefaun

I copied exactly the text it showed when I dragged and dropped, but for some reason something's different. No clue why.

The terminal was a stop of from 80 columns punched cards (back in my day 🙂), however, it is still very unforgiving of typos. including forgetting to protect white space in a file path.


To understand what you did vs what drag and drop did, you are going to have to look at the command lines character for character, because if they are identical then they will work the same.


And just to cover my bases, are any of the file names using language characters with umlauts, accent characters, etc... That is to say, something besides simple a through z upper and lower case and numbers. The keyboard tends to require extra finger gymnastics to enter those characters that drag and drop does not have any problems doing.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"No such file or directory", trying to copy files in terminal?

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