mv: target `xyz' is not a directory?
Hi guy,
I have a set of files like that: Code:
16 mat nai - Jimmy Nguyen [NCT 1188596568].mp3 Code:
16 mat nai - Jimmy Nguyen.mp3 Code:
$ for f in *; do mv "$f" `echo "$f" | sed 's/ \[NCT [0-9]*\]//'`; done Code:
$ for f in *; do mv "$f" `echo "$f" | sed 's/\(.*\) \[NCT [0-9]*\].mp3$/\1.mp3/'`; done Quote:
Thanks in advance, |
The problem is most likely the spaces in the filenames. Your shell treats them as word separators, so your mv command sees the final string as being a directory name to move the rest of the entries into. Double-quoting the string that generates the new filename will probably fix it.
But my favorite way to handle spaces (other than simply not putting them in filenames to begin with) is to temporarily change the shell's internal field separator so that it doesn't treat them as places to divide words. Code:
oldIFS=$IFS #first save the current values (default is space, tab, newline) Code:
`echo "$f" | sed 's/ \[NCT [0-9]*\].mp3$//'` Code:
"$(sed 's/ \[NCT [0-9]*\].mp3$//')" <<<"$f" (assuming you're using bash, of course) Edit again: Instead of using sed, try parameter substitution. Code:
$ for f in *; do mv "$f" "${f% [*}.mp3"; done |
if you have Python and don't mind a script for that, you use the script here
Code:
# ls -1 |
I just pasted your lines into a test.txt
Code:
16 mat nai - Jimmy Nguyen [NCT 1188596568].mp3 Code:
$ sed 's? \{1,\}\[?[?' test.txt |\ Code:
for f in *.mp3 |
in bash you can do something like this:
Code:
#!/bin/bash |
Quote:
Quote:
Quote:
Quote:
@ghostdog74: I am learning Python too, I will consider it later. @vonbiber, konsolebox: thanks for your help. But as I said above, I want to do that using one-line command. **************************************************************** Another question from a my friend, seem to more relate to title of this topic: Output from jobs -l: Code:
[1]+ 7989 Running okular sed.stream.editor.cheat.sheet.pdf & Code:
$ jobs -l | awk '{ print $2 }' Code:
jobs -l | sed -n 's/^\[[0-9]*\].*\([0-9]*\).*$/\1/p |
All times are GMT -5. The time now is 05:27 AM. |