General discussion

  • Creator
    Topic
  • #2130444

    moving files

    Locked

    by cozmos9 ·

    I want to move a bunch of files using mv or other commands. The files to be moved are either in an input file or piped from grep. Explicit examples would be appreciated.

    Thanks to all.

All Comments

  • Author
    Replies
    • #3547370

      moving files

      by cpfeiffe ·

      In reply to moving files

      If they are in an input file and assuming they will all follow the same pattern (ex. file1 becomes file1.old, filexyz becomes filexyz.old) you can write a small for loop in a script or run it from the command line if you’d like.

      for FILE in `cat input_file`
      do
      mv $FILE $NEWFILE
      done

      This also works if you just want to move the files to a new directory and not change the name
      for FILE in `cat input_file`
      do
      mv $FILE /new_directory
      done

      Or you can still change the name in the new directory to
      for FILE in `cat input_file`
      do
      mv $FILE /new_directory/newfile
      done

      This basically says that you will cat the input file and for each line (identified by variable $FILE) you want to execute the mv command on that line (variable) and move it to the new destination. The ` ` are just a way of enclosing an executable command. You can also do this with your grep in this manner

      for FILE in `your commands piped from grep`
      do
      mv $FILE wherever
      done

      I hope this helps.

      • #3441499

        moving files

        by cozmos9 ·

        In reply to moving files

        Poster rated this answer

    • #3441498

      moving files

      by cozmos9 ·

      In reply to moving files

      This question was closed by the author

Viewing 1 reply thread