Is there a way to make mv create the directory to be moved to if it doesn’t exist?

How about this one-liner (in bash): mkdir –parents ./some/path/; mv yourfile.txt $_ Breaking that down: mkdir –parents ./some/path # if it doesn’t work; try mkdir -p ./some/path creates the directory (including all intermediate directories), after which: mv yourfile.txt $_ moves the file to that directory ($_ expands to the last argument passed to the previous … Read more

How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

To rewrite the history with the files moved: If you want the project’s history to look as though all files have always been in the directory foo/bar, then you need to do a little surgery. Use git filter-branch with the “tree filter” to rewrite the commits so that anywhere foo/bar doesn’t exist, it is created … Read more

How to rename with prefix/suffix?

You could use the rename(1) command: rename ‘s/(.*)$/new.$1/’ original.filename Edit: If rename isn’t available and you have to rename more than one file, shell scripting can really be short and simple for this. For example, to rename all *.jpg to prefix_*.jpg in the current directory: for filename in *.jpg; do mv “$filename” “prefix_${filename}”; done; or … Read more