move files using xargs


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting move files using xargs
# 1  
Old 11-24-2010
move files using xargs

Hi,

I have many files like below in my currect dir

test1.me
test2.me
test3.me

I wanted them to rename without .me extention

I tried below

Code:
find . -name "*.me" | xargs -i mv {} `echo {} | sed 's/\.me//'`

It thorws error that
cant mv ./test1.me to ./test1.me as they are identical

Not sure why `echo {}|sed 's/\.me//'` is not working , or may be xargs is looking for the place holder ({})
Please help

Thanks
Sunny
# 2  
Old 11-24-2010
Try:
Code:
for i in *.me; do
  mv "$i" "${i%.me}"
done

# 3  
Old 11-24-2010
Quote:
Originally Posted by Scrutinizer
Try:
Code:
for i in *.me; do
  mv "$i" "${i%.me}"
done

worked,

but how to do it with xargs

xargs -i mv {} {%.me} ?? ,

it dint work

Last edited by sunilmenhdiratt; 11-24-2010 at 03:54 AM..
# 4  
Old 11-24-2010
Code:
find . -name "*.me" | sed "p;s/\.me$//" | xargs -n2 mv

(if your filenames don't have spaces)

Code:
find . -name "*.doc" | sed 's/.*/"&"/;p;s/\.doc//' | xargs -L2 mv

(if they do)

Last edited by Scott; 11-24-2010 at 04:15 AM.. Reason: typo
# 5  
Old 11-24-2010
Or if you want to rename every .me in every sub directory too:
Code:
find . -name "*.me" | 
while read i; do 
  mv "$i" "${i%.me}"
done

# 6  
Old 11-29-2010
Easy with GNU Parallel

It is easy if you have GNU Parallel installed:

find . -name "*.me" | parallel mv {} {.}
# 7  
Old 11-29-2010
If we're listing third-party nonstandard app solutions now, it's also easy with mmv:
Code:
mmv "*.me" "#1"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Xargs to call python executable to process multiple bam files

I am running the below loop that to process the 3 bam files (which isn't always the case). A .py executable is then called using | xargs sh to further process. If I just run it with echo the output is fine and expected, however when | xargs sh is added I get the error. I tried adding | xargs... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

Xargs and rsync not sending all files

Hi all, I have a script issue I can't seem to work out. In a directory I have several folders and I want to send just the sapdata1 to sapdata14 folders and their contents but not sapdataXX/.snapshot the script is: #!/bin/bash # SETUP OPTIONS export SRCDIR="/scratch/doug/test/sapdata*"... (5 Replies)
Discussion started by: DougyC
5 Replies

3. Shell Programming and Scripting

SBATCH trinity for multiple files and rename/move the output files

Hey guys, I have wrote the following script to apply a module named "trinity" on my files. (it takes two input files and spit a trinity.fasta as output) #!/bin/bash -l #SBATCH -p node #SBATCH -A <projectID> #SBATCH -n 16 #SBATCH -t 7-00:00:00 #SBATCH --mem=128GB #SBATCH --mail-type=ALL... (1 Reply)
Discussion started by: @man
1 Replies

4. Shell Programming and Scripting

How to delete directories and files with xargs?

Hello, i have an dynamical apache_cache that I need to clean all days (older tant one day) with an unix command : find /usr/IBM/HTTPServer/apache_cache/ -name '*' -mtime +1 -print0|xargs -0 rm -r -- but it didn't work. Could you explain me why. So I will put below all my script :... (13 Replies)
Discussion started by: steiner
13 Replies

5. Shell Programming and Scripting

How to copy files from one location to another using xargs??

Hello Experts, I need to copy files from one location to another using xargs. Tried something like this (In Ubuntu & Solaris ). mkdir -p 1234; find /home/emd/Desktop/n007/M007/ -type f -name "A2014*" | xargs -0 cp -r {} /home/emd/Desktop/1234 But every time i run this, a weird error... (6 Replies)
Discussion started by: Saidul
6 Replies

6. Shell Programming and Scripting

Fast processing(mv command) of 1 million+ files using find, mv and xargs

Hi, I'd like to ask if anybody can help improve my code to move 1 million+ files from a directory to another: find /source/dir -name file* -type f | xargs -I '{}' mv {} /destination/dir I learned this line of code from this forum as well and it works fine. However, file movement is kinda... (6 Replies)
Discussion started by: agentgrecko
6 Replies

7. Shell Programming and Scripting

Move all files except sys date (today) files in Solaris 10

I want to move all files from one directory to another directory excluding today (sysdate files) on daily basis. file name is in pattern file_2013031801, file_2013031802 etc (2 Replies)
Discussion started by: khattak
2 Replies

8. Shell Programming and Scripting

help using find/xargs to apply mp3gain to files

I need to apply mp3gain (album mode) to all mp3 files in a given directory. Each album is in its own directory under /media/data/music/albums for example: /media/data/music/albums/foo /media/data/music/albums/bar /media/data/music/albums/more What needs to happen is: cd... (4 Replies)
Discussion started by: audiophile
4 Replies

9. Shell Programming and Scripting

find with xargs to rm found files

I believe what is happening is rm is executing in the script on every directory and on failure of the first it stops although returns status 0. find $HOME -name /directory/filename | xargs -l rm This is the code I use but file remains. I am using sun solaris system which has way limited... (4 Replies)
Discussion started by: Ebodee
4 Replies

10. Shell Programming and Scripting

MV files with xargs or -exec

Hi I need to move multiple (say 10 files) from one location to another location. My selection would be like this... ls -ltr *.arc | head ---> Need to move top 10 files with single command without iterating in loop. I know we can move files like this with find command but not sure if I can... (4 Replies)
Discussion started by: malaymaru
4 Replies
Login or Register to Ask a Question