Here’s an example of the command I’m using:
rsync --list-only --include "*2012*.xml" -exclude "*.xml" serveripaddress::pt/dir/files/ --port=111 > output.txt
How can I get a listing of just the file names without the extra information like permissions, timestamp, etc.?
Edit: And is it possible to output each file name on a new line?
Hoping the question will be moved to the appropriate site, I’ll answer here nevertheless.
You could append a pipe with
awk:This eliminates all the unwanted information by outputting everything from the 5th field, but works only if none of the first four fields in the output format gets an additional whitespace somewhere (which is unlikely).
This
awksolution won’t work if there are file names starting with whitespace.An even more robust way to solve could be a rather complex program which as well makes assumptions.
It works this way: For each line,
/instead of-– it is not compliant with ISO 8601.)It gets even worse: for very esoteric corner cases, there are even more things to watch: File names can be escaped. Certain unprintable bytes are replaced by an escape sequence (
#ooowithooobeing their octal code), a process which must be reversed.Thus, neither
awknor a simplesedscript will do here if we want to do it properly.Instead, the following Python script can be used:
This outputs the list of file names separated by NUL characters, similiar to the way
find -print0and many other tools work so that even a file name containing a newline character (which is valid!) is retained correctly:correctly shows the inode number of every given file.
Certainly I may have missed the one or other corner case I didn’t think of, but I think that the script correctly handles the very most cases (I tested with all 255 thinkable one-byte-filenames as well as a file name starting with a space).