cp: cannot create regular file: Invalid argument

21,932

The syntax of your command is correct. “Invalid argument” from cp usually means that the file name is not valid on the target filesystem. It may be too long, contain a forbidden character, or be a reserved word.

For example Windows filesystems (FAT, NTFS) forbid characters such as : and ? in filenames, so you can't copy these files to a Windows filesystem. There are several workarounds:

  • Use a different filesystem (that Windows doesn't support).
  • Rename the files.
  • Only store an archive (e.g. a zip file) containing the files. Windows won't be able to unpack that archive.
Share:
21,932

Related videos on Youtube

fleamour
Author by

fleamour

A computer enthusiast since fairly recently [Win2k] got the geek bug. A convert to off road mountain biking (used to snowboard.) Hobbyist mechanic, recently purchased an ’81 Citroen Dyane in need of some TLC (always wanted a 2CV.) As would not attempt to recap a mobo, would not attempt to build a wheel [MTB] but enjoy maintaining my car, bike & PCs. And well, who knows… I might just service those forks?

Updated on September 18, 2022

Comments

  • fleamour
    fleamour almost 2 years
    sudo cp -r "/home/fleamour/Music/Mum's Music" /run/media/fleamour/3732-6531
    cp: cannot create regular file '/run/media/fleamour/3732-6531/Mum'\''s Music/Louis Armstrong - At His Very Best/13 - Louis Armstrong; Ella Fitzgerald _ Gee, Baby, Ain'\''t I Good To You?.mp3': Invalid argument
    cp: cannot create regular file "/run/media/fleamour/3732-6531/Mum's Music/Various Artists/Good Mood Music/Disc 1 - 08 - The Four Seasons: Spring Allegro.mp3": Invalid argument...
    

    What is the correct syntax? I am losing roughly an album's worth of music this way. This is under Konsole (openSUSE Tumblweed.)

    • Mark Plotnick
      Mark Plotnick about 7 years
      You can use cp, but you need to change the filenames to avoid special characters such as * ? \ : < > | ". I will find a better question/answer to use as a reference.
    • Mark Plotnick
      Mark Plotnick about 7 years
      More info here at serverfault: Which common characters are illegal in Unix and Windows filesystems. If you're using a USB stick with a Windows filesystem on it, the filenames need to follow the Windows conventions.
    • fleamour
      fleamour about 7 years
      These were ripped with K3b, should I raise a bug?
    • Mark Plotnick
      Mark Plotnick about 7 years
      You could ask if they could add a feature to rename tracks to be Windows-friendly, I guess.
    • fleamour
      fleamour about 7 years
      Feature suggestion? FAT32 default on most car stereos.
    • Mark Plotnick
      Mark Plotnick about 7 years
  • fleamour
    fleamour about 7 years
    Is there a bulk renaming app?
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' about 7 years
    @fleamour Yes there are, including two common commands called rename (with different syntax, so check which one you have). Check questions under the rename tag.
  • fleamour
    fleamour about 7 years
    I used krename GUI. Can you add this to your answer. Not everyone wanna use terminal, although this is blasphemous to some!
  • fleamour
    fleamour about 7 years
    Kid3 is perfect for this.
  • fleamour
    fleamour about 7 years
    Or maybe EasyTAG?
  • fleamour
    fleamour about 7 years
    Even MusicBrainz Picard if files screwy on Google Music Library download.
  • daGo
    daGo almost 5 years
    I get the "cannot create regular file: Invalid argument" using terminal, but Files manager (elementary os) handled the task successfully without renaming anything.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' almost 5 years
    @daGo That means you didn't use the same name. Maybe you tried to use a name with some shell special characters which you didn't protect against shell expansion in the terminal?
  • daGo
    daGo almost 5 years
    @Gilles I just used bare cp foldername/* /media/myUSB/backup (foledrname directory contained files like "Screenshot from 2015-12-25 13_11_18.png")