Tag Info

New answers tagged

1

You could try like this: for file in *Block* do echo mv "$file" "${file//[ ()@$]/_}" done If you're happy with the result, remove the echo before mv to actually rename the files.


0

Since the rename command didn't work for me for unknown reasons and i do not get any other answers for my question, i myself tried to make an effort to make the rename possible. This might not be the best approach to rename the files but it worked for me and this is why i would like to post it as an answer so that if anyone else reads this might get some ...


1

If the a_a part is constant and you're running Linux, then you can use the rename utility. On Debian and derivatives, change rename to rename.ul as the rename command is a different utility which can also do this job but has a different syntax. Iterate over the directories with a loop: for d in */; do … done Call rename to rename the files in each ...


1

With zsh: autoload zmv # best in ~/.zshrc cd /something/server/user/other_stuff/more && zmv -n '(*)/a_a(_*)' '$1/$1$2' Remove -n (dry-run) if happy. Or from /something/server/user looking recursively for a_a_* files: zmv -n '(**/)(*)/a_a(_*)' '$1$2/$2$3' (note that it doesn't look into hidden dirs, add a (#qD) to the end of the pattern for ...


1

I came up with this so far. var=("${PWD##*/}") sed -i "s/a_a/$var/g" filename


1

set '%s_q1.out %s_q2.out %s_q3.out\n' :|for d in several directories do cd -P -- "$d" || ! break set "$1" "../${PWD##*/}" { sed -ne'\|\( \.\./a_a_q[123]\.out\)\{3\}|q;s/.//p' printf "$@" "$2" "$2"; cut -c2- } <<-IN >./infile $(paste -d\ - ./infile) IN done That should work with a POSIX ...


1

In two steps in bash here is a way - epwd=$(basename `pwd`) sed -i "s/a_a/$epwd/g" <filename> The variable $epwd contains an escaped directory name, that can be taken to sed. And the sed command substitutes all occurrences of a_a by the working directory EDITED : The first line of the original answer has been edited to just have the current ...


2

I would use the mmv tool and do mmv eventDataLog.txt.\* abc-eventDataLog.txt.\#1 which is specifically designed to do mass renames.


9

Bash is good for this. for FILE in eventDataLog.txt.2015*; do mv "$FILE" "abc-$FILE"; done


5

You can accomplish this using the rename comamnd. In your case you'd do rename eventDataLog.txt.2015 abc-eventDataLog.txt.2015 eventDataLog.txt*. The syntax it uses is rename frompattern topattern listoffilessuchaswildcardmatch.


0

Command for FILE in $(ls -1 | egrep '^eventDataLog' | egrep -v '^eventDataLog.txt$'); do mv $FILE abc-$FILE; done Notes egrep is the regex-capable version of grep and is included with grep in most distributions First egrep will filter all files starting with "eventDataLog" Second egrep will filter all files that do not (note -v noting an inverse match) ...


1

The -n flag is for --no-act No Action: show what files would have been renamed. So it's normal if you don't have any changes. Regarding your command, it's working for me: $ touch "a @ test" $ ls a @ test $ rename -n 's/ |\$|@/_/g' * a @ test renamed as a___test Maybe depending on your shell, you have to escape the | $ rename -n 's/ ...


1

There's an option called numbered in mv: numbered, t make numbered backups Take a look at the mv man page You can incorporate that into your one liner.


2

You can just do this in bash/dash/zsh, no need to revert to utilities that might not be installed. In bash: for x in *"(12345678).txt"; do mv "$x" "${x%(12345678).txt}"abcdefghij.txt; done the $x%pattern is for removing matchin suffices. From man bash: ${parameter%word} ${parameter%%word} Remove matching suffix pattern. The word is ...


8

There are two Linux commands called rename that are commonly available in distributions. I prefer the perl-based rename, as it's more powerful. You can check which one you have using $ prename --version. If you have the perl-based rename, $ rename --version perl-rename 1.9 $ rename 's/\(12345678\)/abcdefghij/' *.txt If you want to check it first with a ...


0

try ls | awk '{printf "mv %s %s\n",$0,gsub("(12345678)","abcedfgh" );}' | bash


3

Try this. If happy with the proposed moves, remove the echo and rerun. $ ls download(12345678).txt img(12345678).txt upload(12345678).txt $ for F in *; do echo mv "$F" "${F/(12345678)/abcdefghij}"; done mv download(12345678).txt downloadabcdefghij.txt mv img(12345678).txt imgabcdefghij.txt mv upload(12345678).txt uploadabcdefghij.txt $


2

Use the find command to enumerate the files you need to rename. Select only file names with spaces for performance. Pass the -depth option to act on files in subdirectories before acting on the directory itself, since renaming the directories as find is traversing them will result in some directories being missed. find /path/to/directory -depth -name '* *' ...


0

Is there a simple way to remove the whitespace from all the names in the parent directory and all sub directories at once? Yes there is: find /tmp/ -depth -name "* *" -execdir rename 's/ /_/g' "{}" \; Further Reading Good Luck!


0

Giving all due credit to MelBuslan's excellent scriptlet, let me tweak it to address the request for one single e-mail: #!/bin/bash email_address=me@my.domain.com if test -n "$(find /my/directory/name -maxdepth 1 -name 'core*' -print -quit)" ; then for file in $(ls /my/directory/name/core*) do newname=$(echo ${file}|sed -e ...


0

#!/bin/bash email_address=me@my.domain.com for file in $(ls /my/directory/name/core*) do newname=$(echo ${file}|sed -e "1,1s/core/c.o.r.e/") mv ${file} ${newname} echo "File Renamed..."|mail -s "File ${file} renamed to ${newname} ${email_address} done This should do...


0

Use the rename command. rename /a/myfile /a/b/myfile I think most ftp clients use rename, not mv like lftp (as in slm's answer).


0

You can do it like this: cd -P files_input/.. && mkdir files_output && pax -rws'|.*/\(.*\)/\(.*\)|\1.\2|' \ files_input/??-2015/index.html files_output Which will glob all index.html files in folders in child directories of ./files_input named with two characters, then a dash, then the string 2015 and copy all of those files into ...


4

mv either renames a single file or moves many files into a single directory. If you want to rename many files you probably want to use rename. Depending on your version of rename you do: rename .1.gz.html .html *.1.gz.html or rename 's/\.1\.gz\.html/\.html/' *.1.gz.html The first version is a bit easier to write the second one is more powerful and ...


1

A wildcard like that gets expanded into everything that matches it before the mv command even runs. Making matters worse is that *.html will also match your *.1.gz.html files. This means that (for example two files named abc.1.gz.html and def.1.gz.html) your command above is essentially running: mv abc.1.gz.html def.1.gz.html abc.1.gz.html def.1.gz.html ...


0

Try removing the quotes around {}, as seemed to work for me that way. $ find foo* files_output -ls 27002 0 drwxrwxr-x 2 steve steve 60 Jul 2 15:04 foo1 25373 0 -rw-rw-r-- 1 steve steve 0 Jul 2 15:04 foo1/index.html 27003 0 drwxrwxr-x 2 steve steve 60 Jul 2 15:04 foo2 25374 0 -rw-rw-r-- 1 steve ...


0

Actually found out the reason it wasn't working is because in the machine I'm working there is a weird version of rename whose syntax is actually rename from to files*. Hadn't seen that one before.



Top 50 recent answers are included