home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!destroyer!ncar!mimbres.cs.unm.edu!cs.sandia.gov!jhgreen
- From: jhgreen@cs.sandia.gov (Jethro H. Greene)
- Subject: Re: how do you move everything to a subdirectory?
- Message-ID: <1993Jan16.005306.1874@cs.sandia.gov>
- Sender: usenet@cs.sandia.gov (Another name for news)
- Organization: Sandia National Laboratories, Albuquerque, NM
- References: <1993Jan15.213131.4376@welchgate.welch.jhu.edu> <1993Jan15.222125.14969@news.eng.convex.com>
- Date: Sat, 16 Jan 93 00:53:06 GMT
- Lines: 30
-
- In article <1993Jan15.222125.14969@news.eng.convex.com> faught@convex.com (Danny R. Faught) writes:
- >Given that 'foo' is a directory containing files and subdirectories, and one
- >of those subdirectories is 'bar', how do you move everything in foo (except
- >bar of course) to bar?
- >
- >If I try 'mv * bar' I get 'mv: bar: rename: Invalid argument' because
- >mv tries to copy bar into itself. I could probably do it with some
- >arcane 'find' sequence, or maybe ls piped into grep to remove bar,
- >piped into mv. I have tried several find combinations, none of which
- >seem to work very well. Moving everything back up a level with
- >'mv bar/* .' is trivial.
- >
- >I was surprised that this wasn't in the FAQ. Is there an elegant solution?
-
- Well, what I would do is to 'mv * bar' and ignore the error.
-
- The elegant solution is, assuming that you are using a shell whichs supports
- command line programming (sh, ksh, bash, etc...) is:
-
- for i in *; do
- if [ $i != bar ]; then
- mv $i bar
- fi
- done
-
- --
- Jethro H. Greene
- Massively Parallel Computing Research Laboratory,
- Sandia National Laboratories, Albuquerque, New Mexico
-
-