Tag Info

New answers tagged

1

find is rarely useful when you don't need to traverse a directory tree recursively. Here a simple loop and shell wildcards are enough. for x in */161901.pdf; do mv -- "$x" "xyz/${x%/*}.pdf" done Or, with the Perl-based rename command on Debian, Ubuntu and derivatives (prename on Arch, not the Linux rename command on other distributiosn): rename ...


0

Later I found while read -r line very helpful and I've succeed with following command:- find -name 161901.pdf | while read -r line; do mv $line ./xyz/$(echo $line | cut -d "/" -f 2).pdf; done Explanation:- Here find -name 161901.pdf list the founded files (already mentioned in question) which piped to while loop in while path stored in variable line. ...


0

If you have rename / prename command find -name 161901.pdf -exec prename -n 's!/!-!g; s!\W*!xyz/!' {} + and remove -n if you like what you see. (Larry Wall and Robin Barker' prename is installed with perl.deb package; Brian d Foy Unicode::Tussle rename also works)


0

Sweet and simple: #!/bin/bash find . -name 161901.pdf | while read -r line do # this will create new filenames e.g. ./May-2013/161901.pdf will be now May-2013-161901.pdf filename=$(echo $line | grep -oP "\/\K.+$" | sed 's/\//-/g') # now just move the files mv $line xyz/$filename done So, essentially it's just a 2-step process. Create new ...


0

This could be a possible solution. The argument of the script is the directory in which you are searching, and now it is just printing what will do: #!/bin/bash find "$1" -type f -name '161901.pdf' -print0 | while IFS= read -r -d '' f do # get folder name d="$(basename "${f%/*}")" target="${d}.pdf" echo cp $f "xyz/${target}" done


1

One way is to use find -print and pipe the filelist to awk where you can transform it to whatever you want, e.g. a cp command: $ find -name 161901.pdf -print | awk -v TARGET=xyz -F'/' '{ printf "cp %s %s/%s.pdf\n", $0, TARGET, $2; }' cp ./May-June-2011/161901.pdf xyz/May-June-2011.pdf cp ./Nov-Dec-2011/161901.pdf xyz/Nov-Dec-2011.pdf and this can then be ...


3

Perl module Unicode::Tussle comes with a very useful script named rename (which is unfortunate, because the name clashes with the standard rename(1) on Linux). With it, you could do something like this: mkdir xyz find . -name '*.pdf' -print0 | \ rename -0 's!^\.!xyz!; s!/[^/]*\.pdf$!.pdf!' Without Perl, you could still do the same thing with a bit ...


1

Using perl's rename (named prename in Ubuntu) prename 's/^([^_]*).*(_R.*)/$1$2/' *.fastq.gz


3

In bash or POSIX sh: for file in *.fastq.gz; do mv -- "$file" "${file%%_*}_${file##*_}" done


1

With zsh: autoload zmv # best in ~/.zshrc zmv '(*)_*(_R*)' '$1$2'


0

Looks to me like you don't need a the text file at all if your renames can be mechanically inferred from the order: ls | sort -n | while read file do echo mv "$file" "`printf "n%.2d" "$i"`" ((i++)) done #Replace newlines with semicolons if you want a one-liner #Delete the `echo` if this gives you the correct move commands #Assumes no "\n" characters ...


0

It doesn't seem that detox has an option for that. It should be fairly simple to modify the source code to add a filter with your desired output (a small modification of the safe filter; don't forget to ensure that any leading - gets removed). You could postprocess the result of detox, or use other tools altogether. There are many file renaming tools that ...


0

you can use find without ‍‍-exec‍ as well: mkdir /path/to/dest cp `find /path/to/source -name "*.jar"` /path/to/dest


0

Why don't you simply use quotes? So you don't need to escape those [. rename "[800p]-[WOLU-H]" "[WOLU-H]" "[800p]-"* (Note the * is out of the "...") EDIT: Comments make me notice it doesn't work. I don't understand why, because it works here: $ ls -1 [800p]-[WOLU-H]-foobar.txt [800p]-[WOLU-H]-hello.txt [800p]-[WOLU-H]-world.txt $ rename ...


6

[ and ] have a special meaning in bash and also in regular expressions, so you have to escape them as \[ and \]. Something like this should work: rename 's/\[800p\]-\[WOLU-H\]/\[WOLU-H\]/' \[800p\]-* Example: $ touch [800p]-[WOLU-H]-test1.mkv [800p]-[WOLU-H]-test2.mkv $ ls [800p]-[WOLU-H]-test1.mkv [800p]-[WOLU-H]-test2.mkv $ rename ...


0

What exactly is the question here? You should add some detail on your invocation pattern of rsync to get any meaningful assistance. I've used rsync for years without problems. I think it's safe to say that any apparent corruption is due to improper usage of this versatile tool. If you don't pass -c, rsync skips based on modification time and size. Even if ...


1

Use the find command to enumerate files in a directory and its subdirectories recursively. There are several ways to rename files. You can use the Linux rename command: find Music -depth -name '*_000' -exec rename _000 '' {} \; This removes the first occurrence of _000 in each file name. Beware that if you had files whose name contains _000 in the middle, ...


2

Although mikesrv solution is much better and safer I think this can be done also with rename: find Music/ -type f -name '*_000' -print0 | xargs -r0 rename -v '_000' '' But there are still potential problems as mentioned, for example album_00020_000 will be renamed to album20 which obviously is not the desired behaviour. I think on debian distribution was ...


2

cd Music/.. && mkdir Music2 && pax -'rwls|\([^/]\)_000$|\1|p' Music Music2 If run from Music's parent directory, the above commands will create a directory called Music2 then mirror Music's path structure in Music2 w/ hardlinks while removing any occurrence of _000 found at the tail of any filename therein. Afterward you'll have ...


1

Here is a shell-only solution for the three cases you have in your question: for f in *.png.png ; do mv -i "${f}" "${f%.png}" ; done for f in *.jpeg.jpg ; do mv -i "${f}" "${f%.jpeg.jpg}.jpg" ; done for f in *.JPEG ; do mv -i "${f}" "${f%.JPEG}.jpg" ; done Type it in the directory where the files are to be renamed. If you like to generalize this type ...


2

Here is something using find to rename *.png.png -> *.png: find ./ -name '*.png.png' -type f \ -exec sh -c 'mv {} ./$(basename -s .png.png {}).png' \; It isn't really gerenic, so you have to customize it for the other file extensions.


0

With pax: pax -'rws|/|_|' -- */u_ex150407.log target/dir pax is the standard file-archiver specified by POSIX. Unfortunately - though it is required in the Linux Standard Base and has been for a few version increments of same - for whatever reason, many distribtions do not package it with the default installation as both standards require. I consider this ...


0

Zsh comes with a function called zmv that makes it easy to move or copy files and apply pattern-based transformations on the name. Put this in your .zshrc (or run it on the command line): autoload -U zmv alias zcp='zmv -C' alias zln='zmv -L' Then your copy-with-renaming can be done with any of the following equivalent commands: zcp 'Logfiles/(*)/(*.log)' ...


0

You can use following script to copy files from one location to another with modified name. Note: In following script we have hard-coded two values. /Logfiles/ :- change Logfiles name to valid folder name from which you have to copy files. /tmp/ :- It is a directory under which you want to copy files. Change this directory name according to your ...



Top 50 recent answers are included