rsync: failed to set times on "/cygdrive/e/.": Invalid argument (22) - windows

I get the below error message when I try to rsync from a local hard disk to a USB disk mounted at E: on Windows 10.
rsync: failed to set times on "/cygdrive/e/.": Invalid argument (22)
My rsync command is as below (path shortened for brevity):
rsync -rtv --delete --progress --modify-window=5 /cygdrive/d/path/to/folder/ /cygdrive/e/
I actually need to set modification times (on directories as well) and rsync actually sets modification times perfectly. It only fails to set times on root of the USB disk.

I experienced exactly the same problem.
I created a dir containing one text file and when trying to rsync it to an removable (USB) drive, I got the error. However, the file was copied to the destination. The problem is not reproducible if the destination is a folder (other than root) on the removable drive
I then repeated the process using a fixed drive as destination, and the problem was not reproducible
The 1st difference that popped up between the 2 drives, was the file system (for more details, check [MS.Docs]: File Systems Technologies):
FAT32 - on the removable drive
NTFS - on the fixed one
So this was the cause of my failure. Formatting the USB drive as NTFS fixed the problem:
The USB drive formatted as FAT32 (default):
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ ll /cygdrive/
total 20
dr-xr-xr-x 1 cfati None 0 Jul 14 17:58 .
drwxrwx---+ 1 cfati None 0 Jun 9 15:04 ..
d---r-x---+ 1 NT SERVICE+TrustedInstaller NT SERVICE+TrustedInstaller 0 Jul 13 22:21 c
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jul 14 13:19 e
drwxr-xr-x 1 cfati None 0 Dec 31 1979 n
drwxr-xr-x 1 cfati None 0 Dec 31 1979 w
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ rsync -rtv --progress --modify-window=5 ./dir/ /cygdrive/w
sending incremental file list
rsync: failed to set times on "/cygdrive/w/.": Invalid argument (22)
./
a.txt
3 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 111 bytes received 111 bytes 444.00 bytes/sec
total size is 3 speedup is 0.01
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ ll /cygdrive/
total 20
dr-xr-xr-x 1 cfati None 0 Jul 14 17:58 .
drwxrwx---+ 1 cfati None 0 Jun 9 15:04 ..
d---r-x---+ 1 NT SERVICE+TrustedInstaller NT SERVICE+TrustedInstaller 0 Jul 13 22:21 c
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jul 14 13:19 e
drwxr-xr-x 1 cfati None 0 Dec 31 1979 n
drwxr-xr-x 1 cfati None 0 Dec 31 1979 w
After formatting the USB drive as NTFS:
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ ll /cygdrive/
total 24
dr-xr-xr-x 1 cfati None 0 Jul 14 17:59 .
drwxrwx---+ 1 cfati None 0 Jun 9 15:04 ..
d---r-x---+ 1 NT SERVICE+TrustedInstaller NT SERVICE+TrustedInstaller 0 Jul 13 22:21 c
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jul 14 13:19 e
drwxr-xr-x 1 cfati None 0 Dec 31 1979 n
drwxrwxrwx+ 1 Administrators Administrators 0 Jul 14 17:59 w
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ rsync -rtv --progress --modify-window=5 ./dir/ /cygdrive/w
sending incremental file list
./
a.txt
3 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=0/2)
sent 111 bytes received 38 bytes 298.00 bytes/sec
total size is 3 speedup is 0.02
cfati#cfati-e5550-0 /cygdrive/e/Work/Dev/StackOverflow/q045006385
$ ll /cygdrive/
total 24
dr-xr-xr-x 1 cfati None 0 Jul 14 17:59 .
drwxrwx---+ 1 cfati None 0 Jun 9 15:04 ..
d---r-x---+ 1 NT SERVICE+TrustedInstaller NT SERVICE+TrustedInstaller 0 Jul 13 22:21 c
drwxrwx---+ 1 SYSTEM SYSTEM 0 Jul 14 13:19 e
drwxr-xr-x 1 cfati None 0 Dec 31 1979 n
drwxrwxrwx+ 1 Administrators Administrators 0 Jul 14 13:19 w
As a side note, when I was at step #2., I was an idiot and kept the --delete arg, so til I hit Ctrl + C, it deleted some data. Luckily, it didn't get to delete crucial files / folders.

Related

Is there a way to remove the owner's read permissions on a file in macOS?

Is there any way to take away the owner's permission to read a file in macOS? I know there's no reason to do this but I have to for school and I can't find an answer anywhere. Removing my write permission works fine but when I try to remove my read permission it automatically give me my read and write permissions back. As you can see in the console when I use chmod -v -v (extra verbose) it shows the correct permissions it should be changed to but then when checking afterwards they havent changed into that...
thijs#Thijss-MacBook-Air-2 week6 % ls -l
total 16
-rw----r-- 1 thijs staff 12 Oct 11 21:10 greeting.txt
-rw-r--r-- 1 thijs staff 0 Oct 11 21:10 hello.txt
-rw------- 1 thijs staff 15 Oct 11 21:11 weather.txt
thijs#Thijss-MacBook-Air-2 week6 % chmod -v -v u-w weather.txt
weather.txt: 0100600 [-rw------- ] -> 0100400 [-r-------- ]
thijs#Thijss-MacBook-Air-2 week6 % ls -l
total 16
-rw----r-- 1 thijs staff 12 Oct 11 21:10 greeting.txt
-rw-r--r-- 1 thijs staff 0 Oct 11 21:10 hello.txt
-r-------- 1 thijs staff 15 Oct 11 21:11 weather.txt
thijs#Thijss-MacBook-Air-2 week6 % chmod -v -v u-r weather.txt
weather.txt: 0100400 [-r-------- ] -> 0100000 [---------- ]
thijs#Thijss-MacBook-Air-2 week6 % ls -l
total 16
-rw----r-- 1 thijs staff 12 Oct 11 21:10 greeting.txt
-rw-r--r-- 1 thijs staff 0 Oct 11 21:10 hello.txt
-rw------- 1 thijs staff 15 Oct 11 21:11 weather.txt

Listening to a different process's socket?

I have one process (PID1) that does:
exec 3<>/dev/tcp/127.0.0.1/12713
And when I do:
$ ls -lh /proc/self/fd/
lrwx------ 1 0 0 64 Mar 24 12:19 0 -> /dev/pts/9
lrwx------ 1 0 0 64 Mar 24 12:19 1 -> /dev/pts/9
lrwx------ 1 0 0 64 Mar 24 12:19 2 -> /dev/pts/9
lrwx------ 1 0 0 64 Mar 24 12:20 255 -> /dev/pts/9
lrwx------ 1 0 0 64 Mar 24 12:19 3 -> socket:[83968639]
Now let's say I have a second process PID2, is it possible to read the socket opened through the PID1?
I have tried:
exec 1>/proc/PID1/fd/3
but i get the error message: No such device or address
My scenario has the PID1 writing to the socket and PID2 reading it. (basically for experimentation with the file descriptors)

How to set world permissions to be the same as group permissions?

How would you go about changing permissions for a file or in a directory recursively in such a way that group permissions would be copied over to world permissions, with no other changes? For example, to go from this directory listing:
drwxr-x--- 2 septi septi 4096 Jun 29 01:14 example.d
-rw-r----- 1 septi septi 0 Jun 29 01:14 example.r
-rwxr-x--- 1 septi septi 0 Jun 29 01:14 example.x
...to:
drwxr-xr-x 2 septi septi 4096 Jun 29 01:14 example.d
-rw-r--r-- 1 septi septi 0 Jun 29 01:14 example.r
-rwxr-xr-x 1 septi septi 0 Jun 29 01:14 example.x
From the chmod(1) man page (relevant parts extracted):
-R Change the modes of the file hierarchies rooted in the files
instead of just the files themselves.
And:
The symbolic mode is described by the following grammar:
who ::= a | u | g | o
op ::= + | - | =
perm ::= r | s | t | w | x | X | u | g | o
The who symbols "u", "g", and "o" specify the user, group, and
other parts of the mode bits, respectively. The who symbol a is
equivalent to ugo.
The perm symbols represent the portions of the mode bits as follows:
g The group permission bits in the original mode of the file.
So for you:
chmod -R o=g *
Example:
$ ls -l
total 0
drwxr-x--- 2 carl staff 68 Jun 28 10:25 example.d
-rw-r----- 1 carl staff 0 Jun 28 10:25 example.r
-rwxr-x--- 1 carl staff 0 Jun 28 10:25 example.x
$ chmod -R o=g *
$ ls -l
total 0
drwxr-xr-x 2 carl staff 68 Jun 28 10:25 example.d
-rw-r--r-- 1 carl staff 0 Jun 28 10:25 example.r
-rwxr-xr-x 1 carl staff 0 Jun 28 10:25 example.x

Rename or remove prefix for multiple files to each ones' number in Windows

I am trying to change all the files names in a current folder and I am trying to achieve this either by removing the files prefix (every file has a common prefix) or changing their names to their count (if there are 5 files, the filenames will be 1.txt 2.txt 3.txt 4.txt 5.txt).
Now I have found the ren command in cmd and played with it a little but so far I was not able to achieve the result and I can only run this in cmd, so no batch files can be used.
This is the closest that I got, but it only adds a prefix:
FOR %f IN (*.*) DO ren %f prefix%f
I have tried doing the opposite:
FOR %f IN (*.*) DO ren prefix%f %f
But of course, didn't work so I am now asking for help and some explanation if possible (I like to understand how these things work). Thanks in advance for any help.
A much simpler solution is provided in
https://superuser.com/a/871799/497147
I copied it here for easier access.
Forget about complicated scripts for this.
rename is a very old and never properly completed command. If you do not use it properly, the result might surprise you.
For example to remove a prefix abcd from abcd1.txt, abcd2.txt, abcd3.txt etc. in order to get 1.txt, 2.txt, 3.txt simply use
rename "abcd*.txt" "////*.txt"
You need the same number of / as the number of initial characters you would like to remove.
Do place double quotes for both arguments.
I don't understand why you can't use a batch file. But here is a solution that should work with most file names.
Critical - first you must make sure you have an undefined variable name, I'll use fname
set "fname="
Next is the command to actually do the renaming. It won't work properly if fname is already defined.
for %a in (prefix*.txt) do #(set "fname=%a" & call ren "%fname%" "%fname:*prefix=%")
The fname variable is defined for each iteration and then the syntax %fname:*prefix=% replaces the first occurrence of "prefix" with nothing. The tricky thing is Windows first attempts to expand %fname% when the command is first parsed. Of course that won't work because it hasn't been defined yet. On the command line the percents are preserved if the variable is not found. The CALL causes an extra expansion phase that occurs after the variable has been set, so the expansion works.
If fname is defined prior to running the command, then it will simply try to rename that same file for each iteration instead of the value that is being assigned within the loop.
If you want to run the command again with a different prefix, you will have to first clear the definition again.
EDIT - Here is a batch file named "RemovePrefix.bat" that does the job
::RemovePrefix.bat prefix fileMask
#echo off
setlocal
for %%A in ("%~1%~2") do (
set "fname=%%~A"
call ren "%%fname%%" "%%fname:*%~1=%%"
)
Suppose you had files named like "prefixName.txt", then you would use the script by executing
RemovePrefix "prefix" "*.txt"
The batch file will rename files in your current directory. The batch file will also have to be in your current directory unless the batch file exists in a directory that is in your PATH variable. Or you can specify the full path to the batch file when you call it.
The rules for expansion are different in a batch file. FOR variables must be referenced as %%A instead of %A, and %%fname%% is not expanded initially, instead the double percents are converted into single percents and then %fname% is expanded after the CALL. It doesn't matter if fname is already defined with the batch file. The SETLOCAL makes the definition of fname temporary (local) to the batch file.
You can do it this way (let's say your prefix is "AS"):
x=1; for k in AS*; do y=$((x++)); echo "mv ${k} ${k:0:2}$y.txt"; done
if you want to save extensions use this (pre-test):
x=1; for k in AS*; do y=$((x++)); echo "mv ${k} ${k:0:2}$y.${k#*.}"; done
if pre-test is OK then remove echo and code will run this time:
x=1; for k in AS*; do y=$((x++)); mv ${k} ${k:0:2}$y.txt; done
*for saving extensions (remove echo and code will run this time):
x=1; for k in AS*; do y=$((x++)); mv ${k} ${k:0:2}$y.${k#*.}; done
${k:0:2} --> first two letters of file 0 to 2...
${k#*.}--> extension of the file
I had a similar situation myself and solved it.
My files were like this:
1-6-4-20.txt onar.mol2 replace.py z.out z__06.mol2 z__09.mol2 z__12.mol2 z__15.mol2 z__18.mol2 z__27.mol2 z__30.mol2 z__33.mol2 z__36.mol2
make_com_files.py pt.dat valid.txt z.xyz z__07.mol2 z__10.mol2 z__13.mol2 z__16.mol2 z__25.mol2 z__28.mol2 z__31.mol2 z__34.mol2 z__37.mol2
makepymol.py pymol.pml x.py z__05.mol2 z__08.mol2 z__11.mol2 z__14.mol2 z__17.mol2 z__26.mol2 z__29.mol2 z__32.mol2 z__35.mol2
Note that there is no z_01.mol2 z_02.mol2 z_03.mol2 z_04.mol2 and z_19.mol2 z_20.mol2 etc.. so my z files are not in sequence. I can't get rid of the problem by omitting the z_* prefix. and also I have onar.mol2
Here is my solution:
pre-test using echo to see if it is working correctly:
x=1; for k in *.mol2; do y=$((x++)); echo "mv ${k%%.*}.mol2 $y.mol2"; done
output:
mv onar.mol2 1.mol2
mv z__05.mol2 2.mol2
mv z__05.mol2 2.mol2
mv z__06.mol2 3.mol2
mv z__07.mol2 4.mol2
mv z__08.mol2 5.mol2
mv z__09.mol2 6.mol2
mv z__10.mol2 7.mol2
mv z__11.mol2 8.mol2
mv z__12.mol2 9.mol2
mv z__13.mol2 10.mol2
mv z__14.mol2 11.mol2
mv z__15.mol2 12.mol2
mv z__16.mol2 13.mol2
mv z__17.mol2 14.mol2
mv z__18.mol2 15.mol2
mv z__25.mol2 16.mol2
mv z__26.mol2 17.mol2
mv z__27.mol2 18.mol2
mv z__28.mol2 19.mol2
mv z__29.mol2 20.mol2
mv z__30.mol2 21.mol2
mv z__31.mol2 22.mol2
mv z__32.mol2 23.mol2
mv z__33.mol2 24.mol2
mv z__34.mol2 25.mol2
mv z__35.mol2 26.mol2
mv z__36.mol2 27.mol2
mv z__37.mol2 28.mol2
seems correct then I can use this as a command for my aim (by removing echo):
x=1; for k in *.mol2; do y=$((x++)); mv ${k%%.*}.mol2 $y.mol2; done
RESULT: ls -ln:
-rwxrwxrwx 1 0 0 1695 Nov 18 12:07 1-6-4-20.txt
-rwxrwxrwx 1 0 0 1813 Nov 18 13:27 1.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 10.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 11.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 12.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 13.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 14.mol2
-rwxrwxrwx 1 0 0 2784 Nov 18 13:27 15.mol2
-rwxrwxrwx 1 0 0 2785 Nov 18 13:27 16.mol2
-rwxrwxrwx 1 0 0 2785 Nov 18 13:27 17.mol2
-rwxrwxrwx 1 0 0 2786 Nov 18 13:27 18.mol2
-rwxrwxrwx 1 0 0 2786 Nov 18 13:27 19.mol2
-rwxrwxrwx 1 0 0 2781 Nov 18 13:27 2.mol2
-rwxrwxrwx 1 0 0 2787 Nov 18 13:27 20.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 21.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 22.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 23.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 24.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 25.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 26.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 27.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 28.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 3.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 4.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 5.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 6.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 7.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 8.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 9.mol2
-rwxrwxrwx 1 0 0 1383 Nov 17 12:27 make_com_files.py
-rwxrwxrwx 1 0 0 5687 Nov 17 16:34 makepymol.py
-rwxrwxrwx 1 0 0 1206 Nov 17 11:36 pt.dat
-rwxrwxrwx 1 0 0 964 Nov 18 13:29 pymol.pml
-rwxrwxrwx 1 0 0 2288 Nov 18 13:27 replace.py
-rwxrwxrwx 1 0 0 1284 Nov 18 13:07 valid.txt
-rwxrwxrwx 1 0 0 3809 Nov 18 12:37 x.py
-rwxrwxrwx 1 0 0 19622334 Nov 18 04:11 z.out
-rwxrwxrwx 1 0 0 34717 Nov 18 12:37 z.xyz
enter code here
EXTRA:
and if I want my files as 00001.mol2 00002.mol2 etc, I can add this command too:
rename 's/\d+/sprintf("%05d",$&)/e' *.mol2
Here are my mol2 files:
-rwxrwxrwx 1 0 0 1813 Nov 18 13:27 00001.mol2
-rwxrwxrwx 1 0 0 2781 Nov 18 13:27 00002.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 00003.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00004.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00005.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00006.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00007.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 00008.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 00009.mol2
-rwxrwxrwx 1 0 0 2782 Nov 18 13:27 00010.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00011.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00012.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00013.mol2
-rwxrwxrwx 1 0 0 2783 Nov 18 13:27 00014.mol2
-rwxrwxrwx 1 0 0 2784 Nov 18 13:27 00015.mol2
-rwxrwxrwx 1 0 0 2785 Nov 18 13:27 00016.mol2
-rwxrwxrwx 1 0 0 2785 Nov 18 13:27 00017.mol2
-rwxrwxrwx 1 0 0 2786 Nov 18 13:27 00018.mol2
-rwxrwxrwx 1 0 0 2786 Nov 18 13:27 00019.mol2
-rwxrwxrwx 1 0 0 2787 Nov 18 13:27 00020.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00021.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00022.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00023.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00024.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00025.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00026.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00027.mol2
-rwxrwxrwx 1 0 0 2788 Nov 18 13:27 00028.mol2
-rwxrwxrwx 1 0 0 1695 Nov 18 12:07 1-6-4-20.txt
-rwxrwxrwx 1 0 0 1383 Nov 17 12:27 make_com_files.py
-rwxrwxrwx 1 0 0 5687 Nov 17 16:34 makepymol.py
-rwxrwxrwx 1 0 0 1206 Nov 17 11:36 pt.dat
-rwxrwxrwx 1 0 0 964 Nov 18 13:29 pymol.pml
-rwxrwxrwx 1 0 0 2288 Nov 18 13:27 replace.py
-rwxrwxrwx 1 0 0 1284 Nov 18 13:07 valid.txt
-rwxrwxrwx 1 0 0 3809 Nov 18 12:37 x.py
-rwxrwxrwx 1 0 0 19622334 Nov 18 04:11 z.out
-rwxrwxrwx 1 0 0 34717 Nov 18 12:37 z.xyz
Following is straight way to trim the prefix with rename for all the files
rename -d your_prefix *

How to include a library in the path while compiling?

I'm reading this post about go and was trying to compile the source code found here
I downloaded the source code, compiled the first file with make and I can see the object is generated:
$pwd
/Users/oscarryz/code/go/rsc/rosetta/graph
$ls -ltR
total 136
-rw-r--r-- 1 oscarryz staff 61295 Sep 17 16:20 _go_.6
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 _obj
-rw-r--r-- 1 oscarryz staff 126 Sep 17 16:17 Makefile
-rw-r--r-- 1 oscarryz staff 2791 Sep 17 16:17 graph.go
./_obj:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 rsc.googlecode.com
./_obj/rsc.googlecode.com:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 hg
./_obj/rsc.googlecode.com/hg:
total 0
drwxr-xr-x 3 oscarryz staff 102 Sep 17 16:20 rosetta
./_obj/rsc.googlecode.com/hg/rosetta:
total 136
-rw-r--r-- 1 oscarryz staff 68486 Sep 17 16:20 graph.a
No my question is, how do I refer to that compiled code from the maze directory:
/Users/oscarryz/code/go/rsc/rosetta/maze/maze.go
Whose import declarations are:
import (
"bytes"
"fmt"
"rand"
"time"
"rsc.googlecode.com/hg/rosetta/graph"
)
And right now is failing to compile with the error message:
6g -o _go_.6 maze.go
maze.go:20: can't find import: rsc.googlecode.com/hg/rosetta/graph
make: *** [_go_.6] Error 1
Ok, I found it, wasn't that hard.
6g flags: -I DIR search for packages in DIR
I have to specify the -I option like this:
6g -I ../graph/_obj/ -o _go_.6 maze.go

Resources