Use rsync to copy only hidden files - macos

I want to back up all the hidden files and directories in my homedir using rsync, but not the non-hidden files and directories.
For example, given this directory listing:
drwxr-xr-x 7 sophie sophie 238 31 Mar 08:45 .
drwxr-xr-x 15 sophie sophie 510 31 Mar 08:14 ..
-rw-r--r-- 1 sophie sophie 4 31 Mar 08:12 .foo
drwxr-xr-x 3 sophie sophie 102 31 Mar 08:45 .hiddendir
drwxr-xr-x 4 sophie sophie 136 31 Mar 08:13 VisibleDirectory
-rw-r--r-- 1 sophie sophie 9 31 Mar 08:13 VisibleFile
I want to back up .foo, .hiddendir, and all the contents of .hiddendir whether they are hidden or not. I don't want to back up VisibleDirectory or VisibleFile.
All the incantations I have come up with back up ".", and therefore all its contents including VisibleFile and VisibleDirectory, and I can't figure out how to exclude it. Please help!
I'm using Mac OS X 10.5.6 (Leopard) and rsync version 2.6.9 protocol version 29.

A common pattern to match the hidden items is .[^.]*
rsync -a ~/.[^.]* /path/to/backup
This copies all files starting with a single dot. Note that it doesn't include files starting with more than one dot.

It's usually ".??*" to make sure you don't copy "." and ".."
(What if you had a file that was just ".a" ?)

Have you tried incarnations like ./.*?
Could you copy the hidden files to a temp directory, back up the temp directory, then remove it?

Related

MacOS Catalina - Show all directories from root in Finder

As a reluctant Mac user, I am routinely frustrated by things that should be very simple. Finder is one of those. When trying to open an XML file from Firefox, I am asked what application I whish to open it with. Obviously MacVim. To do that, I need to navigate to /usr/local/bin/gvim which is a symlink to /Cellar, since it was installed with HomeBrew. However, when I select "Open with" and click "Choose", the Finder comes up and defaults to Applications. It's not in there, I just want to navigate directly to the symlink. Switching to "Macintosh HD" (also known as "/" to a more refined audience) only displays Application, Library, System, and Users. Where is everything else? Where is /usr, /bin, /etc? As a user, this seems disingenuous. It's not an accurate representation of my location in the filesystem. Sorry, this is a bit of a rant, but also a legitimate question. How do I display these all the time?
The UNIX (lowercase) directories are hidden from view, intentionally, through a special "hidden" flag. You can see those in ls -lO:
Chimera:~ morpheus$ ls -lO /
total 14
drwxrwxr-x+ 59 root admin sunlnk 1888 Sep 23 16:46 Applications
drwxr-xr-x+ 65 root wheel sunlnk 2080 Mar 20 2020 Library
drwxr-xr-x 2 root wheel hidden 64 Sep 30 2018 Network
drwxr-xr-x# 5 root wheel restricted 160 Sep 21 2018 System
drwxr-xr-x 7 root admin - 224 Mar 20 2020 Users
drwxr-xr-x# 8 root wheel hidden 256 Sep 23 21:17 Volumes
drwxr-xr-x# 37 root wheel restricted,hidden 1184 Mar 27 2019 bin
drwxrwxr-t# 2 root admin hidden 64 Feb 8 2019 cores
dr-xr-xr-x 3 root wheel hidden 4821 Aug 30 19:38 dev
lrwxr-xr-x# 1 root wheel restricted,hidden 11 Sep 30 2018 etc -> private/etc
dr-xr-xr-x 2 root wheel hidden 1 Sep 24 07:59 home
-rw-r--r-- 1 root wheel hidden,compressed 313 Aug 17 2018 installer.failurerequests
drwxr-xr-x 2 root wheel - 64 Oct 3 2018 mnt
drwxr-xr-x 2 root wheel - 64 Jan 21 2018 mnt1
dr-xr-xr-x 2 root wheel hidden 1 Sep 24 07:59 net
drwxr-xr-x 6 root wheel sunlnk,hidden 192 Sep 30 2018 private
drwxr-xr-x# 64 root wheel restricted,hidden 2048 Mar 27 2019 sbin
lrwxr-xr-x# 1 root wheel restricted,hidden 11 Sep 30 2018 tmp -> private/tmp
drwxr-xr-x# 9 root wheel restricted,hidden 288 Sep 21 2018 usr
lrwxr-xr-x# 1 root wheel restricted,hidden 11 Sep 30 2018 var -> private/var
Additionally, Finder will not display hidden "." files, the same way ls -l needs to be "persuaded" using -a (try "ls -lOa /", omitted here for brevity).
Pressing the apple key along with shift and '.' will display everything. To make this the default behavior:
defaults write com.apple.finder AppleShowAllFiles YES
In case you're interested in the rationale - it dates back to NeXTSTEP (the progenitor to MacOS X and later as we know it now), which wanted to provide a user interface to its own (Uppercase first letter) directories, while hiding those of the underlying UNIX (BSD layer), seeing as non-root users have nothing to look for there, anyway (and most users have no knowledge of terminal/shell).

Permission issues when changing path of files in Grade Copy Task

Wasn't really sure where best to ask this so, though the best place was here!
I have an issue with a Gradle Copy Task where I am unzipping a zip and then modifying the file paths to remove the root folder in the zip. This was a recommended workflow because the feature to elect certain sub-directories in a zip isn't available in Gradle: https://github.com/gradle/gradle/issues/1108
So here is my problem this is my Gradle Task:
task unpackTomcat( type: Copy ) {
from zipTree( "/Users/x/Downloads/tomcat-X.zip" )
into "/app/tomcat"
fileMode 0660
dirMode 0750
includeEmptyDirs = false
eachFile { details ->
def path = details.path
details.path = path.substring( path.indexOf( '/' ) + 1 )
}
}
This will unpack the zip and move all files out of the apache-tomcat-X folder and put them in my base folder. IE remove the first part of the path. However when it does this the permissions on the folders are incorrect:
drwxr-xr-x 3 X X 102B Oct 12 13:58 temp/
drwxr-xr-x 27 X X 918B Oct 12 13:58 lib/
drwxr-xr-x 12 X X 408B Oct 12 13:58 conf/
drwxr-xr-x 25 X X 850B Oct 12 13:58 bin/
-rw-rw---- 1 X X 1.7K Oct 12 13:58 NOTICE
-rw-rw---- 1 X X 57K Oct 12 13:58 LICENSE
drwxr-x--- 3 X X 102B Oct 12 13:58 ../
drwxr-x--- 8 X X 272B Oct 12 13:58 ./
Even setting a umask to 027 (Trying to remove other permissions from the files/directory) on the Gradle JVM doesn't even stop this (This should force the JVM to use the permissions of UMASK is there is no filemode set. If I remove the eachFile part of the above task the folders have the right permissions, but obviously would be in the apache-tomcat-X folder that gets created which I don't want to occur.
So I am at a lose as to why this is happening and would love people more experienced with Gradle to help me out here. It appears that the issue is that path change causes the folders to be created with my base UMASK instead of the UMASK that is supposed to be used and this appears to be a bug but thought I would check here.

Emacs 25.2 dired mode shows .. above . How do I change this?

On my win-10 machine, dired shows this:
drwxr-xr-x 58 jkb jkb 4096 Nov 5 11:08 ..
drwxr-xr-x 6 jkb jkb 4096 Nov 6 09:34 .
Where the .. entry comes first. How do I modify the installation to change it back to this:
drwxr-xr-x 6 jkb jkb 4096 Nov 6 09:34 .
drwxr-xr-x 58 jkb jkb 4096 Nov 5 11:08 ..
It is not a big issue, except that on my mint 18 machine it shows the traditional order. Uniformity would be good.
Many thanks for pointers and advice.
[See the first comment to this question for the answer]
Formal answer:
I can solve my issue by setting ls-lisp-UCA-like-collation to nil:
'(ls-list-UCA-like-collation nil)
in the customize section of my .emacs file or via the customize menus.
The change has the side-effect of changing the ordering of the cygwin home directory, the ~/.* files come first now.
There may be another option to fix that, if it is important.
Note that this is an issue with dired on emacs, using ls-lisp.

Bash - What is the best way to save the value of a quantity after the script has terminated?

I am attempting to write a script that changes my desktop wallpaper to the next picture in my ~\Picture\Wallpapers directory. I have already created a script, change_wallpaper, which can change my desktop background to any given picture.
My plan was to list all the pictures in ~\Picture\Wallpapers as an array, find the index i of the current wallpaper, and apply change_wallpaper to the i+1 element of the array of pictures. My only issue is finding a way to story the index of the current wallpaper. I could create a file which contains this value, but it seems really inelegant to just have a text file with the number 12, for example, saved somewhere in my home directory.
Is there a better way?
I agree with the general consensus of using a file to store the index of the current wallpaper. A slightly more elegant way would be to put a "." (dot) in front of the file name to keep it hidden in the directory where your script is located. Something like:
admin#myHost:/home/admin$ ls -la
total 6200
drwxrwxr-x 4 admin admin 4096 Jul 02 15:41 .
drwxr-xr-x 71 bin bin 4096 Jun 29 12:43 ..
-rw------- 1 admin admin 3939 Jun 29 16:02 .bash_history
-rw-r--r-- 1 admin admin 21 Nov 04 2014 .bashrc
-rwxr-x--x 1 admin admin 259 Oct 13 2014 .profile
-rw------- 1 admin admin 3939 Jun 29 16:02 .wallpaper_index
-rw------- 1 admin admin 3939 Jun 29 16:02 change_wallpaper
There are countless linux and unix applications that do this.

How to create drag and drop DMG file, Mac installer

Hi I have created an aplication myprogram.app file. Now I want to create Drag and drop DMG file for that application. Skype and other software does the same thing.
How to create Drag and Drop DMG file foe my application.
Thanks
Sunil Kumar Sahoo
It's actually pretty easy. You just need to compose some hidden files. Easy way to do this is to just copy someone elses and change to suit your app.
For example, if I mount the MonoDevelop DMG, then I see:
atom:MonoDevelop fak$ ls -al
total 40
drwxr-xr-x 8 fak staff 340 Nov 4 14:03 .
drwxrwxrwt# 10 root admin 340 Nov 10 21:33 ..
-rw-r--r--# 1 fak staff 12292 Nov 4 14:03 .DS_Store
d-wx-wx-wt 2 fak staff 68 Nov 4 14:03 .Trashes
drwxr-xr-x 3 fak staff 102 Nov 4 14:03 .background
drwx------ 4 fak staff 136 Nov 4 14:03 .fseventsd
lrwxr-xr-x 1 fak staff 13 Nov 4 14:03 Applications -> /Applications
drwxr-xr-x 3 fak staff 102 Nov 4 14:02 MonoDevelop.app
Here we see .background that is a directory with a PNG file (the background). The app itself (MonoDevelop.app) and a link to /Applications.
The .DS_Store contains the window size, icon positions, etc. Just setup a directory and use the .DS_Store from it.
There's really not any magic to this. You can create a disk image with Disk Utility. Put the stuff on it that you need, and then convert it to a compressed read-only image (again, with Disk Utility).
For some tips on prettying up the appearance of the window, check out this question. If you need to automate this process, check out this other question for some ways to do that.

Resources