File management: Difference between revisions

Jump to navigation Jump to search
add a section Move files older or less than x days
add unpacking gz files
add a section Move files older or less than x days
Line 50: Line 50:
<syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight>
<syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight>


== Mirror a folder ==
* ''Last tested on Ubuntu 16.04 LTS (xenial)''
This also works between servers. The first one is on the same server.
Explanation of parameters used:
* -a: archive - preserve permissions, ownership, and timestamps
* -v: verbose
* -z: compress
<syntaxhighlight lang="bash" highlight="1">
$ rsync -azv /folder_a/ /folder_b/
</syntaxhighlight>
This one is between different servers.
<syntaxhighlight lang="bash" highlight="1">
$ rsync -azv ~/folder_a/ mhan@tom.myserver.com:~/folder_b/
</syntaxhighlight>
== Move files older or less than x days ==
* ''Last tested on Ubuntu 14.04.5 LTS (trusty)''
Make a list of files to copy.  Example here is a list of files older than 365 days.
<syntaxhighlight lang="bash" highlight="1">
$ find . -type f -mtime +365 > /tmp/rsyncfiles
</syntaxhighlight>
This is a list of files younger than 365 days
<syntaxhighlight lang="bash" highlight="1">
$ find . -type f -mtime -365 > /tmp/rsyncfiles
</syntaxhighlight>
rsync across the network to another server. This command deletes the source files after they are moved.
<syntaxhighlight lang="bash" highlight="1">
$ rsync --remove-source-files -zvh --files-from=/tmp/rsyncfiles . mhan@zinc.wherever.com:/target/folder/
</syntaxhighlight>


[[Category:System administration]]
[[Category:System administration]]

Navigation menu