mv

unix move command regex

百般思念 提交于 2019-12-11 16:43:53
问题 I have a bunch of files in the format blahblah1.java.bak , blahblah2.java.bak , etc. And I want to change all the files ending with .bak to just .java . Is it possible to do this using the mv command? Perhaps something like mv (.*\.java)\.bak $1 ? 回答1: What's wrong with for i in *java.bak ; do mv "$i" `basename "$i" .bak` ; done or for i in *java.bak ; do mv "$i" "${i%.bak}" ; done if you are in bash. Command line file matching is not exactly the same as a regex in, say, Perl or =~ comparison

Moving multiple files in subdirectories (and/or splitting strings by multichar delimeter) [bash]

只谈情不闲聊 提交于 2019-12-10 22:43:33
问题 So basically, I have a folder with a bunch of subfolders all with over 100 files in them. I want to take all of the mp3 files (really generic extension since I'll have to do this with jpg, etc.) and move them to a new folder in the original directory. So basically the file structure looks like this: /.../dir/recup1/file1.mp3 /.../dir/recup2/file2.mp3 ... etc. and I want it to look like this: /.../dir/music/file1.mp3 /.../dir/music/file2.mp3 ... etc. I figured I would use a bash script that

unhide hidden files in unix with sed and mv commands

邮差的信 提交于 2019-12-10 16:59:03
问题 i wonder if u could help me with fixing bash script which should unhide all hiden files in dir. Where is the problem? param='.' for file in $param*; do mv $file $(echo $file | sed 's/^.\(.*\)/\1/') done exit 回答1: This for loop should work: export GLOBIGNORE=".:.." for file in .*; do mv -n "$file" "${file#.}" # mv -n "$file" "${file:1}" done PS: Better to backup your files before doing a mass mv/rename 回答2: @anubhava's answer works, but here's an amended, generalized solution for processing

Move all files in directory to parent with node.js

和自甴很熟 提交于 2019-12-10 12:43:43
问题 Question Is there a simple way to move all the files in a directory up to its parent directory then delete the directory? Use Case I'm doing a zip extraction and the source zip contains a root folder called archive , so when I extract I get extract_path/archive/ , but I'd like to just extract the contents of archive directly to extract_path . I thought this would be simple rename, but the following is throwing a "There is a file in the way" error message. fs.renameSync(extractPath + "/archive

How to use the mv command in Python with subprocess

那年仲夏 提交于 2019-12-09 15:36:23
问题 I have a lot of files in /home/somedir/subdir/ and I'm trying to move them all up to /home/somedir programmatically. right now I have this: subprocess.call(["mv", "/home/somedir/subdir/*", "somedir/"]) but it's giving me this error: mv: cannot stat `/home/somedir/subdir/*': No such file or directory I know that it does exist because when I type the mv command by hand using the exact same command as the script uses it works perfectly. 回答1: if you call subprocess that way: subprocess.call(["mv"

bash error renaming files with spaces - mv target is not a directory

纵然是瞬间 提交于 2019-12-09 15:10:21
问题 I'm trying to rename a bunch of files which contain spaces in them, getting rid of the spaces. I thought I found the correct bash command: for f in *.txt; do mv \"$f\" ${f/ /}; done However, this gives the error, "mv: target is not a directory" for each file. If I replace 'mv' with 'echo mv' in the command, it prints the proper mv command for each file, and if I type any of those mv commands individually, they work. For example, if I have 2 files, "a .txt", and "b .txt", and run the command

bash script problem, find , mv tilde files created by gedit

喜欢而已 提交于 2019-12-08 11:54:01
问题 im using linux with gedit which has the wonderful habit of creating a temp file with a tilde at the end for every file I edit. im trying to move all of these files at once to a different folder using the following: find . -iname “*.php~” -exec mv {} /mydir \; However, its now giving me syntax errors, as if it were searching through each file and trying to move the piece of text. I just want to move all of the files ending in .php~ to another directory. Any idea how I do that? Cheers Ke 回答1:

Cleartool move moves only top directory

喜欢而已 提交于 2019-12-08 07:14:51
问题 We're trying to move a bunch of folders from one location to another in our vob. The process is that: we check out the target parent folder check out the source parent parent folder ct mv source target This unfortunately fails with moving only the top folder in the tree... On the other hand ct relocate works fine and we avoid checking out thousands of vob elements. Are there any drawbacks with that command? We assume that the source and the target are in the same vob. 回答1: We assume that the

Bash mv not a directory

蓝咒 提交于 2019-12-08 01:32:10
问题 I have part of my script that goes like this: while read line do code=`echo ${line} | awk '{print $1}'` awk -f ${supscript}/rearrange.sh < ${base}/${code} mv temp_output* "$code"temp_output* done < filelist The script is working; the only problem is that when it is trying to rename the file I got the following error message: mv: target `pollcodetemp_output*' is not a directory Maybe it is something related with the IFS. I try to specify this at the beginning of the script as: IFS=' ' But it

mv: invalid option — '0'

怎甘沉沦 提交于 2019-12-07 11:56:48
问题 How can I rename files with "-" in front of the filename, for example: "-0001.jpg" Everyime I try to run: for i in *; do mv "$i" "${i//-/}"; done or: for i in *; do mv "$i" "${i#*-}"; done I got this error: mv: invalid option -- '0' Try `mv --help' for more information. Thanks for any light! 回答1: mv ./-00008.jpg to/some/where.jpg ^ - start with path... 回答2: as with most gnu commands, use the -- switch before the filename with the hyphen. it signifies "end of switches". 回答3: Put a double -