File management: Difference between revisions

From Han Wiki
Jump to navigation Jump to search
add Delete files recursively
No edit summary
Line 1: Line 1:
== Copy including hidden files ==
= Copy including hidden files =


* ''Last tested on Ubuntu 14.04.2 LTS (trusty)''
* ''Last tested on Ubuntu 14.04.2 LTS (trusty)''
Line 7: Line 7:
</source>
</source>


== Delete files recursively ==
= Delete files recursively =


* ''Lasted tested on Ubuntu 16.04.2 LTS (xenial)
* ''Lasted tested on Ubuntu 16.04.2 LTS (xenial)
Line 15: Line 15:
</source>
</source>


== Setting a default group for a folder ==
= Setting a default group for a folder =
* ''Last tested on Ubuntu 16.04 LTS (xenial)''
* ''Last tested on Ubuntu 16.04 LTS (xenial)''


Line 47: Line 47:




== Unpacking gz files ==
= Unpacking gz files =


The files are compressed using Lempel-Ziv (LZ77) algorithm. GNU zip (gzip/gunzip) is used for this.
The files are compressed using Lempel-Ziv (LZ77) algorithm. GNU zip (gzip/gunzip) is used for this.
Line 57: Line 57:
<syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight>
<syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight>


== Mirror a folder ==
= Mirror a folder =
* ''Last tested on Ubuntu 16.04 LTS (xenial)''
* ''Last tested on Ubuntu 16.04 LTS (xenial)''


Line 77: Line 77:
</syntaxhighlight>
</syntaxhighlight>


== Move files older or less than x days ==
= Move files older or less than x days =
* ''Last tested on Ubuntu 14.04.5 LTS (trusty)''
* ''Last tested on Ubuntu 14.04.5 LTS (trusty)''



Revision as of 17:21, 26 May 2017

Copy including hidden files

  • Last tested on Ubuntu 14.04.2 LTS (trusty)
$ cp -r folder1/. target/

Delete files recursively

  • Lasted tested on Ubuntu 16.04.2 LTS (xenial)
$ find . -type f -name "*.mp4" -exec rm {} \;

Setting a default group for a folder

  • Last tested on Ubuntu 16.04 LTS (xenial)

This is to set permission for an existing folder for collaboration. This assumes the group name to be dev, and the folder to be /srv/www/project.

This sets setgid bit on the folder.

$ sudo find /srv/www/project -type d -exec chgrp dev {} +
$ sudo find /srv/www/project -type d -exec chmod g+s {} +

Make it writable by the group.

$ sudo chmod -R g+w /srv/www/project

Change group ownership of existing files.

$ sudo chown -R mhan:dev /srv/www/project

These commands should be executed for a new folder.

$ sudo chgrp dev /srv/www/project
$ sudo chmod g+s /srv/www/project


Unpacking gz files

The files are compressed using Lempel-Ziv (LZ77) algorithm. GNU zip (gzip/gunzip) is used for this.

$ gunzip file.gz

or

$ gzip -d file.gz

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
$ rsync -azv /folder_a/ /folder_b/

This one is between different servers.

$ rsync -azv ~/folder_a/ mhan@tom.myserver.com:~/folder_b/

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.

$ find . -type f -mtime +365 > /tmp/rsyncfiles

This is a list of files younger than 365 days

$ find . -type f -mtime -365 > /tmp/rsyncfiles

rsync across the network to another server. This command deletes the source files after they are moved.

$ rsync --remove-source-files -zvh --files-from=/tmp/rsyncfiles . mhan@zinc.wherever.com:/target/folder/