LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   How to "cp" or "rm" or "tar" all the files except a certain file? (http://www.linuxquestions.org/questions/slackware-14/how-to-cp-or-rm-or-tar-all-the-files-except-a-certain-file-432057/)

cqmyg5 04-05-2006 02:54 PM

How to "cp" or "rm" or "tar" all the files except a certain file?
 
Hi,

There're many files in a folder:
1.a
2.b
3.c
4.d
.
.
.
999.xyz

I want to cp *.* except one of them, or rm *.* except one of them, or tar *.* except one of them.

Is there any simple command or option could do it?

Thanks!

geeman2.0 04-05-2006 03:06 PM

RTFM!!!!

No really.
From the man page:
Code:

  -X file
  --exclude-from file    Exclude files listed in file.


cqmyg5 04-05-2006 03:58 PM

Thank you!

It only works for 'tar', when I use this:
rm *.* -X aaa
or
rm *.* --exclude-from aaa

it shows:
invalid option -- X
or
unrecognized option '--exclude-from'

I already RTFM of 'cp' and 'rm', no information yet!

mdarby 04-05-2006 04:19 PM

Why not use find with the exec option or just move the file you want to keep?

cqmyg5 04-05-2006 04:29 PM

Thanks!

I'll try find with exec option!

Wynd 04-05-2006 07:52 PM

Or maybe
Code:

ls | grep -v file | xargs rm

cqmyg5 04-05-2006 09:13 PM

wow!

I'll try it, thanks

tuxdev 04-07-2006 02:45 PM

"find <opts> -print0 | xargs -0 <command>" handles newlines in filenames.


All times are GMT -5. The time now is 01:44 AM.