Operating System - Linux
1832086 Members
2964 Online
110037 Solutions
New Discussion

Re: move log files in linux

 
suman babu mullangi
New Member

move log files in linux

Helllo All,
I am actually trying to move/copy all of the files with extension as '.log' to a different directory.
Itried using the command "find -name '*.log' -print -exec cp {} \;" But every time i try to run it i get the exception missing destination file.
can any one of you please help me out I am in immediate need of it Please Please please...
4 REPLIES 4
Alexander Chuzhoy
Honored Contributor

Re: move log files in linux

this will work:
find /var -type f -name "*.log" -exec cp {} /tmp/log \;


where /var is the directory to look in and the destination directory is /tmp/log
Muthukumar_5
Honored Contributor

Re: move log files in linux

Wrong syntax on the command of,

find -name '*.log' -print -exec cp {} \;

Use as,

find it is good to to start with /var as,

# find /var -name '*.log' -type f -exec cp {} /tmp/ \;
# find /var -name '*.log' -type f -exec > {} \;

First will do copy to /tmp directory. Second will remove (>) all contents in that file.

-Muthu
Easy to suggest when don't know about the problem!
Delrish
Trusted Contributor

Re: move log files in linux

You forgot to define search path in you command.This is the correct syntax for find:
find

If you want to find any logfile entire your linux you have to use the following command:

find / -name '*.log' -print -exec cp {} \;

Also most of the log files located in /var, you can use "/var" instead of "/", but if you have non-standard log files, "/" is a better choise.

Alireza
Ivan Ferreira
Honored Contributor

Re: move log files in linux

You have two errors:

You have not specified the path to the find command.

You have not specified the destination path to the cp command.

Change to something like this:

find /where/to/start/the/search -name "*.log" -exec cp {} /destination/to/copy/files \;

For example:

find /var/log -name "*.log" -exec cp {} /usr/oldlogs \;
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?