Search code examples
bashdirectorymv

Bash moving created file


I have a script that creates a file, what is the best way to edit that script that it moves the newly created file into a folder one above the directory it will be put in?

Thanks


Solution

  • It depends a little bit on how you create the file, but supposing you had a variable that held the name of your file. Then you could use dirname to get the directory, and then mv to move it.

    mv "$file" $(dirname "$file")/..
    

    Update: Based on the OP's comment the exact line would look like the following.

    mv "FileName$1" $(dirname "FileName$1")/..