Moving files (Unix/Linux)- Some tips

Moving files from one machine to another machine is the most common activity for system engineer profile. Most common examples are moving backup files, log files and some time moving a large setup files which are created per transaction. Generally these types of files are placed on bug servers and moving them is easy because you can make an archive file(tar file) of all the files and move the tar file to destination. It creates problem when you have less space left ion source machine and you need to move large number of file to another machine.

Another case may be when you need to move similar files to some other location. Example is moving same day files or same extention files to some other location. I am here trying to list some of the unix commonds which can be useful for doing file moving activity.

1. Moving files older than certain time (older than yesterday in following example).

#find -mtime +1 -exec mv "{}" /destincation_folder 

2. Moving file date wise (All yesterday files)

#find -mtime 1 -daystart -exec mv "{}" /destincation_folder 

Another way to do is finding all files of specific date and then iterating over them to copy into any other folder

ls -la | awk '{ print $8}' > filenames

Shell script to iterate all files

#!/bin/sh
list=` cat filenames`

for i in $list; do
echo $i
mv $i /someDIR

done
exit

3. Moving files in chunk (e.g moving 10000 files in one go)

#ls -la | tail 10000 | xargs mv /destination_folder

Most Commented Posts

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

No comments yet.

Leave a comment

(required)

(required)