Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-28-2012, 09:18 PM   #1
LQ Newbie
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
How to find and move files to a dir

Env: SuSE 10.3 GNU Linux ksh
I need to find all log files (sys*.log.gz) in dir /export/log and move them to /export/log/archive
So i tried:
find /export/log -name 'sys*.log.gz' -print|xargs -exec mv {} /export/log/archive \;

results in:
mv: target `/export/log/sys_main_08042012_231020.log.gz' is not a directory

What am I doing wrong? Thanks!!!
Old 09-28-2012, 10:29 PM   #2
Registered: Aug 2012
Location: Chiang Mai, Thailand
Distribution: Kubuntu 12.10 x86_64
Posts: 192
Blog Entries: 2

Rep: Reputation: 22
ofc! because it is not directory, you are moving a file or folder to a file.
Old 09-29-2012, 12:17 AM   #3
Registered: Jul 2009
Posts: 623

Rep: Reputation: 42
in the find command try using the -t option and specifying file.Also .gx is a file not a directory so you get that error.
Old 09-29-2012, 12:58 AM   #4
Registered: Sep 2012
Posts: 47

Rep: Reputation: 4
@ azstyx

find /export/log/ -type f -iname 'sys*.log.gz' -exec mv -t /export/log/archive/ '{}' \;
This is how to use the mv command in a find syntax. It works because I've done it many times.

-type f means to find files only.
-iname means case insensitive search. Which means it will get lower and uppercase or in between file names.
mv -t is the target directory to move the files it finds.

find /export/log/ -type f -iname 'sys*.log.gz' -exec mv -t /export/log/archive/ '{}' '+'
This works as well too. Do you notice the difference? The one above has '{}' \; and the other has '{}' '+'

The '{}' \; executes the mv command for each instance it finds a file(s) based on the criteria.

The '{}' '+' executes the mv command after it collects all file(s) based on the criteria. Sort of like what xargs does.


Last edited by linux_BSD; 09-29-2012 at 01:09 AM.
1 members found this post helpful.
Old 09-29-2012, 02:25 PM   #5
LQ Newbie
Registered: Sep 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for suggestions!!
Both of these work for me:
find /export/log/ -maxdepth 1 -type f -iname 'sys*.log.gz' |xargs mv -t /export/log/archive
find /export/log -maxdepth 1 -type f -iname 'sys*.log.gz' -exec mv -t /export/log/archive {} \;
Old 09-29-2012, 02:54 PM   #6
Registered: Sep 2012
Posts: 47

Rep: Reputation: 4
Happy to assist.

PS: If your issue is solved mark it as SOLVED from the thread tools.

Welcome to LQ!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script for Identifying the file and zip all files, move the files to Target Dir gvenkat Linux - Newbie 3 05-07-2011 10:53 AM
[SOLVED] How to find root files and dirs in some dir? Mr. Alex Linux - Newbie 2 11-01-2010 12:56 AM
[SOLVED] find and replace text from many files in a dir bckr Linux - Newbie 6 07-09-2010 02:19 PM
Count files in dir then move that many files in a script? chuckycharms Linux - Newbie 3 12-18-2009 11:31 AM
find and move most recent files in dir backnine_99 Linux - Software 2 06-14-2005 12:03 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration