With zsh
:
setopt extendedglob # best in ~/.zshrc
mv A/^(file|directory)(|2)(D) B/
(the (D)
to include dot (hidden) files).
With bash
:
shopt -s extglob dotglob failglob
mv A/!(@(file|directory)?(2)) B/
With ksh93
(FIGNORE='@(.|..|@(file|directory)?(2))'; mv A/* B)
I finally got this working! The trick was to create my own slice and set it in the service file, like this:
[Service]
# Everything else as in the original question
Slice=my_service_limit.slice
And create a slice unit file /lib/systemd/system/my_service_limit.slice
that looks like this:
[Unit]
Description=Slice that limits memory for all my services
[Slice]
# MemoryHigh works only in "unified" cgroups mode, NOT in "hybrid" mode
MemoryHigh=500M
# MemoryMax works in "hybrid" cgroups mode, too
MemoryMax=600M
Note: be careful with the naming of the slice, as -
is a hierarchy separator, as explained in https://systemd.io/CGROUP_DELEGATION - a very helpful page for anyone trying to configure this. You can check whether the service is really using the configured slice by looking at the output of systemctl status myservice
- it should say:
CGroup: /my_service_limit.slice/myservice@myinstance.service
It was not necessary to set systemd.unified_cgroup_hierarchy=1
(as per Ryutaroh Matsumoto's answer) for MemoryMax to work, but it was necessary for MemoryHigh - even in "hybrid" mode (the default in Ubuntu 18.04) it's silently ignored.
Also worth noting that these only apply to the physical RAM used - they do not include swap space used. (There is a separate MemorySwapMax setting, but no MemorySwapHigh, it seems.)
Best Answer
Try this :
but you need a
ext2-4
partition mounted withatime
option enabled.Ubuntu
by default have therelatime
option enables by default.From
man mount
:Example in
/etc/fstab
:Note : enabling this option have a cost in term of performance (disk I/O).
More on atime, ctime, mtime