Tag Info

Hot answers tagged

9

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


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 ...


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.


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

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


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 ...


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 '* *' ...


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 ...


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.


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.



Only top voted, non community-wiki answers of a minimum length are eligible