Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cp: target is not a directory

I have a bash script with this line:

cp -R /usr/lib/gcc/x86_64-linux-gnu/$GCC_VERSION/* /app/.apt/usr/lib/gcc/x86_64-linux-gnu/$GCC_VERSION

Full script: https://github.com/virtualstaticvoid/heroku-buildpack-r/blob/cedar-14/bin/compile

Unfortunately it fails with cp: target ‘/app/.apt/usr/lib/gcc/x86_64-linux-gnu/4.8’ is not a directory

Any tips what could be wrong? Unfortunately I do not have much experience with bash.

Previously this script was running alone and it was working. Now I had to add some apt-get install before it, and it started to fail so I am trying to fix it.

like image 608
Archeg Avatar asked Apr 12 '16 08:04

Archeg


People also ask

What is cp target?

If target is a directory, then cp copies one or more source files to that directory keeping the original file names. If a target file does not exist, cp creates it giving it the same permissions as the source file but only allocating as many blocks as required by the contents of the source.

Is a directory not copied cp?

By default, cp does not copy directories. However, the -R , -a , and -r options cause cp to copy recursively by descending into source directories and copying files to corresponding destination directories.

Is not a directory mv command?

When you specify a single source file and the target is not a directory, mv moves the source to the new name, by a simple rename if possible. If a destination file exists and you do not have write permission for it, mv prompts with the name of the existing file.

How cp command works in Linux?

cp command copies files (or, optionally, directories). The copy is completely independent of the original. You can either copy one file to another, or copy arbitrarily many files to a destination directory. In the first format, when two file names are given, cp command copies SOURCE file to DEST file.


2 Answers

There is no directory with the name 4.8...Thats your problem :)

Run this before your cp command:

mkdir -p /app/.apt/usr/lib/gcc/x86_64-linux-gnu/$GCC_VERSION

It creates all directories in the given path!

like image 53
Daniel Avatar answered Oct 05 '22 03:10

Daniel


This should work, add / at the end of cp command to make it clear for it that its dir:

mkdir -p /app/.apt
cp -R $BUILD_DIR/.apt/* /app/.apt/
like image 28
Drako Avatar answered Oct 05 '22 03:10

Drako