Cygwin Access Windows UNC Mapped Drive - linux

I often need to do some text processing for windows network drive. Since there are so many of them I have almost all my drive letters are used (I think T is still available).
I something need to do:
cd "\lonshr-cad\cad\Feeds\BondPricesNYClose\" or
less "\lonshr-cad\cad\Feeds\BondPricesNYClose\BondPrices_display_16112011.txt"
but my Cygwin shows that the MS-DOS sytle path detected.
Is there a quick way to access these file?

Try with the normal slash "/" or with single quotes instead of double quotes. If you want to use an absolute path then use /cygdrive/t for the T drive

Just use forward slashes:
cd //lonshr-cad/cad/Feeds/BondPricesNYClose
and
less //lonshr-cad/cad/Feeds/BondPricesNYClose/BondPrices_display_16112011.txt
You can also create aliases that can cd to these directories or less specific files. That way you don't have to type the entire UNC path (or copy/paste/change slashes).

Related

Batch replacing unidentified Characters in Unix that were created by macOS

On a Linux volume as part of a NAS with many TB of data some files were created from macOS and some of those files uploaded from macOS seem to include characters in filenames that cannot be reproduced via FTP or SMB file protocol. These files will appear as e.g. "picture_name001.jpg". Where the "" probably stands for a colon or slash.
I can search for "" and found out it applies to 2171 files in distributed locations on the volume. Way too much to manually find and correct each file name.
I thought I can connect to the NAS via SSH and simply loop through each directory doing an automated replace of the "" into "_", but this doesn't work because:
for file in **; do mv -- "$file" "${file///_}"; done
this attempt will throw back an error on the first item matching  with:
mv: can't rename '120422_LAXJFK': No such file or directory
So obviously this substitute character displayed as "" is not the way to address the file or directory as it refers to a name that doesn't actually exists in the volume index.
(A) How do I find out if "120422_LAX:JFK" or "120422_LAX/JFK" is meant here, and (B) how do I escape these invalid characters to eventually be able to automatically rename all those names to for example "120422_LAX_JFK"?
Is there for example a way to get a numerical file ID from the name and then instruct to rename the file by number in case its name contains ""?
I think the problem is that behind this "" can be different codes of symbols. When the system can't represent some characters (for example, given encoding is not supported), then it automatically replaced by some default character (in your case it is ""). But actually there is some code of the character, that should be in the name. BUT when you trying to do this for file in **; do mv -- "$file" "${file///_}"; done system can't recognize code, that symbol is "" is stands for.
I think this problem can be solved by changing the encoding of characters (they should be compatible and better the same) on both devices (mac and NAS)
Hope this would help

Cross-platform paths in CMake

I have a project I can build on both Linux and Windows using CMake. The only issue is that Unix-style paths, in CMakeLists.txt, can't work on Windows (which uses backslashes instead of slashes, also requiring the drive letter).
Is there any way I can write a cross-platform CMakeLists.txt?
You question affects different details:
Just don't use backslashes. Windows will also process slashes.
Don't use drive letters. Use relative paths everywhere.
GET_FILENAME_COMPONENT(X "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH) can solve the whole path without writing any absolute paths.
Add the tool binary paths into your PATH environment variable. So you do not need to search them by yourself (with absolute paths) or
Use FIND_PROGRAM() to get the tools absolute path without guessing around. You could add hints in which registry entries and paths cmake will search for the tool or
Consider to write your own module for every tool. You can copy the skeleton from any module of the modules folder (have a lock at FindJava.cmake; a very good and portable example on how to search a program).
If all those does not help, you can detect the platform by IF(WIN32) or IF(UNIX).
Hope, this helps...

Path variable: Find folder path of specific file

On Linux and other Unix-likes, how do I find the path to a specific file that I can use because of the PATH environment variable? For example, if I can use, from the command line:
ls # technically the file name is "ls.exe"
is there a way I can find the path of the ls.exe file explicitly without looking through the PATH variable myself (i.e. maybe have a program search through it but not look myself)?
I understand there are many pitfalls/caveats of doing this, for example a PATH can be a file or even part of a file (I think), plus symlinks, etc. could make it unreliable, but I'm looking for general use cases.
The reason I am asking is I have Windows with msysgit so I have A LOT of folders in my path, and searching every one would be annoying & time-consuming, not to mention harder because of Windows limitations, but I can still presumably use almost anything Linux can use.
$ type ls.exe
ls.exe is /usr/bin/ls.exe

GVim taking forever to load when connected to office network

When I load GVim from the Cygwin command line or when I'm not connected to the office network (mapped to U:/) it loads instantaneously. It takes a good minute or so to open when I'm on the network. What is going on here?
You probably need to set your $HOME directory to something other than U:/. Create a $HOME environment variable for Windows that points to My Documents or whatever and it won't try and use U:/. You may need to log-off/log-in to pick up the changes.
You should check what your $HOME directory is mapped to in each case. I bet that it is different depending on if you are connected to the network or not.
Do you have any custom .vimrc or other config files read at startup? If nothing else, vim will query your $HOME directory to look for such files. If your network is slow, it could cause your problem.
See ":help startup" inside vim for more details on the startup process.
It might also be a good idea to set the directory and backupdir options so they prefer a local directory. Something along the lines of
set backupdir^=C:/Temp
set directory^=C:/Temp//
The ^= syntax puts the directory at the start of the list of directories for each option. The trailing // for directory tells Vim to encode the full path to the file being edited in the swapfile's name. This allows for swapfiles to be created in one directory when editing multiple files with the same name, but different paths.

Comparing folder structure in two environments

Are there any good tools for comparing two folder structures (files included) between two environments?
i.e. comparing a dev computer with production
Edit:
A note on some lessons learned: dir /s /o:N >> output.txt works well in conjunction with a text comparison tool (I used WinMerge), but the filesystem does appear to matter. NTFS against FAT32 doesn't work well, as one scans the folders in reverse alphabetical order, and the other doesn't. To solve this issue, I copied the files from the FAT32 to an NTFS drive.
Also, DiffMerge is nice, but slow. It actually hung when run on the server (that's where I had access to both sets of files) to a point that I had to force a quit.
I'm sure others have thoughts on doing this with *NIX. Probably a similar technique like ls -alR > output
It's still pretty manual, but it works well.
Just keep in mind that the times on the folders will more than likely be different, so you may want to use a regex to replace them and make them more consistent, since that's fairly benign (I used [\d]{2}/[\d]{2}/[\d]{4}[\s]*[\d]{2}\:[\d]{2}\sAM[\s]*\<DIR\> and [\d]{2}/[\d]{2}/[\d]{4}[\s]*[\d]{2}\:[\d]{2}\sPM[\s]*\<DIR\>).
I use Diff merge (http://www.sourcegear.com/diffmerge/ - it has a free version) for comparing folder structures on Windows
For a tool that runs on Windows (but can work against Linux samba shares), try BeyondCompare.
One windows.
Use your favorite diff tool on the files generated from this cmd.
Run this from the folders you wish to compare.
c:\somefolder>dir /s > searchResult.txt
WinMerge also does folder and file comparison and its FREEE
Option 1)
Mount one of the machines on the other, then use some standard directory compare utility.
Option 2)
Use rsync --dry-run and use the output in some way.
Option 3)
Generate hashes (e.g. sha256) of the files on each side, then compare the lists.
WinDiff and KDiff both seem good at doing this without the need for command line dir listing. My personal preference is KDiff.
WinDiff shows an expanded list of all files/folders. (I was only interested in differences so turned off "Show Identical Files" in the Options menu).
KDiff presents an expandable tree view with nice colour coding.

Resources