Ivan Herlambang
Ivan Herlambang

Reputation: 398

How to move multiple files with whitespace on linux

Hello I'm newbie in linux, what I'm going to ask is about moving file on linux using awk and xargs, apologies if I'm reposting..

I have apprx 1000-5000 files like this:

-rw-rw-r-- 1 wm files 77641 Mar 3 11:20 sendOrder.ZBAM.0005167032-20130503 11:20:35.txt
-rw-rw-r-- 1 wm files 77647 Apr 3 11:20 sendOrder.ZBAM.0005167033-20130503 11:20:36.txt
-rw-rw-r-- 1 wm files 77655 May 3 11:20 sendOrder.ZBAM.0005167034-20130503 11:20:37.txt
-rw-rw-r-- 1 wm files 77661 May 3 11:20 sendOrder.ZBAM.0005167035-20130503 11:20:38.txt
-rw-rw-r-- 1 wm files 77556 May 3 11:20 sendOrder.ZBAM.0005167036-20130503 11:20:39.txt
-rw-rw-r-- 1 wm files 77549 May 3 11:20 sendOrder.ZBAM.0005167037-20130503 11:20:40.txt
-rw-rw-r-- 1 wm files 77549 Jun 3 11:20 sendOrder.ZBAM.0005167038-20130503 11:20:41.txt
-rw-rw-r-- 1 wm files 77543 Jun 3 11:20 sendOrder.ZBAM.0005167039-20130503 11:20:42.txt

As you can see the filename contains whitespace at -20130503 11:20:42.txt, so I'm using:

STEP 1

ls -la|grep -e "May"|awk "{print $9, $10}" > some.files


In step 1 I've already got the list file i want to move by month of "May" inside some.files

STEP 2

xargs -0 some.files mv -t dir/newdir/

Step 2 won't work.. What am I supposed to do? I'm using Linux CentOS 5.3

Upvotes: 0

Views: 1653

Answers (2)

Ole Tange
Ole Tange

Reputation: 33685

With GNU Parallel you can do:

 ls | parallel -X mv {} dir/newdir/

10 seconds installation:

wget -O - pi.dk/3 | sh

Learn more: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Upvotes: 0

fyn
fyn

Reputation: 52

There's probably 400 ways to do this.. using find is likely the more efficient way, but:

You can use a for loop:

for i in `ls`; do mv $i dir/newdir/; done

Or a while loop with the file you created in your step 1:

ls -la|grep -e "May"|awk "{print $9, $10}" > some.files; cat some.files | while read mFILE; do mv $mFILE dir/newdir; done

Or with find (where +30 is greater than X days):

find ./ -mtime +30 -exec mv dir/newdir {} \;

OR, if you want to use awk and xargs:

ls -la|grep -e "May"|awk "{print $9, $10}" | xargs mv dir/newdir/

Upvotes: 1

Related Questions