LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-23-2009, 12:57 PM   #1
pgb205
Member
 
Registered: Nov 2007
Posts: 129

Rep: Reputation: 15
problem with mv and cp


when I try to do mv *.txt /some/directory/
I get

mv: invalid option -- 'd'
Try `mv --help' for more information.


Then when I try cp *.txt /some/directory/
I get

cp: invalid option -- 'e'
Try `cp --help' for more information.

I tried this with zsh and bash with the same result.
Not sure what's changed but doesn't seem like anything wrong
with my syntax.

I'm running 64bit gentoo.
 
Old 11-23-2009, 01:00 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Try:

Code:
alias mv
alias cp
If they show up as having an alias you can unalias them via:
Code:
unalias mv
unalias cp
Edit: Might also want to run rkhunter and chkrootkit to be on the safe side.

Last edited by rweaver; 11-23-2009 at 01:02 PM.
 
Old 11-23-2009, 01:03 PM   #3
pgb205
Member
 
Registered: Nov 2007
Posts: 129

Original Poster
Rep: Reputation: 15
No, I don't believe either one of those commands is aliased:
alias<ENTER> gives:


alias grep='grep --colour=auto'
alias ll='ls -lh'
alias ls='ls --color=auto'



Quote:
Originally Posted by rweaver View Post
Try:

Code:
alias mv
alias cp
If they show up as having an alias you can unalias them via:
Code:
unalias mv
unalias cp
Edit: Might also want to run rkhunter and chkrootkit to be on the safe side.
 
Old 11-23-2009, 01:07 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
what is in the source directory? It seems that something is being substituted for "*" that mv and cp read as option flags.
 
Old 11-23-2009, 01:11 PM   #5
pgb205
Member
 
Registered: Nov 2007
Posts: 129

Original Poster
Rep: Reputation: 15
I'm trying to move several files that share the same extension and are located in my home directory(~/*.txt). The destination is the ~/Desktop

Quote:
Originally Posted by pixellany View Post
what is in the source directory? It seems that something is being substituted for "*" that mv and cp read as option flags.
 
Old 11-23-2009, 01:13 PM   #6
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
what does
Code:
echo *.txt
return?
 
Old 11-23-2009, 01:14 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Move a few of them to a new directory, then cd into that directory and run the mv command from there. This will tell us if a file in /home is causing the problem.

<edit>
PS: Also, post a few of the file names. Do any have spaces or other special characters?

Last edited by pixellany; 11-23-2009 at 01:15 PM.
 
Old 11-23-2009, 01:18 PM   #8
pgb205
Member
 
Registered: Nov 2007
Posts: 129

Original Poster
Rep: Reputation: 15
ahhh. there it is.

One of the files was starting with a dash in its name.
specifically -ddfasdfa.txt thats why it was complaining.

After rename was able to move without issues.

thanks all

Quote:
Originally Posted by AlucardZero View Post
what does
Code:
echo *.txt
return?
 
Old 11-23-2009, 01:26 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
[mherring@mystical stuff]$ echo "hello" > "-d words.txt"
[mherring@mystical stuff]$ ls
-d words.txt
[mherring@mystical stuff]$ mv *txt ..
mv: invalid option -- 'd'
Try `mv --help' for more information.
[mherring@mystical stuff]$
Just one example of a filename that mv will choke on. (as will many utilities)
 
Old 11-23-2009, 01:27 PM   #10
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Sorry---I was typing and testing while you were posting.

Good to see a happy ending
 
Old 11-23-2009, 03:54 PM   #11
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Check the mv and cp man page, look for "--". It's designed specifically for this purpose, you don't need to rename files.

Code:
mv -- * /dest/
 
Old 11-23-2009, 04:22 PM   #12
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by i92guboj View Post
Check the mv and cp man page, look for "--". It's designed specifically for this purpose, you don't need to rename files.

Code:
mv -- * /dest/
This works, but it is not discussed on the man page.

I did find this (which I had seen before and forgotten):
http://www.gnu.org/software/coreutil...Common-options
 
Old 11-23-2009, 04:38 PM   #13
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
It truly depends on the man page you look at. It is in mine. If you just search on the net you probably are going to hit some standard posix man page first, which will not include this extension. This is GNU extension, so it's more than probable that it's not present in any non-GNU OS.
 
Old 11-02-2022, 06:11 AM   #14
kmchen
LQ Newbie
 
Registered: Mar 2009
Posts: 7

Rep: Reputation: 0
Use find to protect file names

I solved this pb using find command:

find . -name "*.ext" -exec mv {} some_folder/ \;
 
Old 11-03-2022, 05:49 AM   #15
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
The -- is most elegant and works for all commands.
mv -- * /dest/
Another workaround for file names is a ./ prefix
mv ./* /dest/
 
  


Reply

Tags
cp, invalid, mv, syntax



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem linking f77 and f90 object files Make problem (I think) TheBrick Programming 1 05-22-2006 06:17 AM
Sound Card problem(every time i install linux i have diffirent hardware problem) jacka1l Linux - Newbie 7 08-11-2005 06:10 AM
Lan configuration problem - NFS boot problem - RX&TX packets errors 242VDM242 Linux - Networking 4 11-25-2004 01:35 PM
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration