home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 15987 < prev    next >
Encoding:
Text File  |  1993-01-28  |  1.6 KB  |  42 lines

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