Universal copy command for Windows and Linux - shell

I was just curious that is there any universal command to copy files. Which should work for both Windows and Linux system.
I know Windows uses copy command and Linux uses cp command. But is there any universal command to do so.

If powershell is installed in your Windows OS,
then you can use the built-in command cp as well, just like Linux does.

UNIX/Linux, Mac, and Windows can all run PowerShell Core 6. https://github.com/powershell/powershell
The command is Copy-Item, but there are three (3) aliases. Using an alias at a command prompt is fine, but they should not be put into script files.
>Get-Alias -Definition Copy-Item
CommandType Name
----------- ----
Alias copy -> Copy-Item
Alias cp -> Copy-Item
Alias cpi -> Copy-Item
Since there is no "universal" command, something will need to be installed on every machine except those that already have the command you choose to make "universal." At a minimum, it would be a .bat/.cmd script on Windows or a shell script on UNIX/Linux/Mac. Choosing to implement it in Python or any other language would require that language to be installed.

There is no universal command to do this, but you have several workarounds:
use cygwin or msys on Windows to have the Linux equivalent commands on windows
use Windows Powershell (partially compatible, but works for cp)
provided that your environments all have python installed, write a python script that does what you want .

Related

How to use Cygwin version of find rather than Windows version

I have got Cygwin installed in my machine and set its bin folder in my PATH.
I can use all the Cygwin commands in the Windows command prompt.
However, one problem I encountered is that both Cygwin an Windows have a command "find". Whenever I use find, the Windows version is picked up.
Is there anyway I can force using the Cygwin version of find rather than the Windows version?
Make sure the the cygwin executables folder /usr/bin is ahead of the cmd executables folder c:\Windows\system32 in the PATH variable for both the cmd and bash shells to be sure you run cygwin's find instead of windows's find command.
Use which -a find in the cygwin shell to list executable files found via the bash shell's PATH variable.
Use where $PATH:find in cmd shell to list executable files found via the cmd shell's PATH variable.
This is because find is a shell built-in in cmd, so it doesn't even try to go through the executable search path.
In general Cygwin symlinks will not be understood by Windows, but as explained https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks it is possible in modern Windows versions to create native Windows symlinks on NTFS file systems, as long as the link doesn't cross file systems.
I would consider instead just wrapping it in, say, a batch script placed in your Cygwin /usr/local/bin with a name like cygfind.bat (or whatever you want to call it) that explicitly calls Cygwin's find by C:\path\to\find.exe.
The wrapper approach has the advantage that if you upgrade Cygwin and find is updated, the batch script wrapping it will still work transparently.
I've never tried it myself but according to this answer you can also use the special #doskey variable to override cmd builtins.

adb: command not found- Window 10 shell

I am trying to run the adb command using adb shell. Running well on mac but not in the window.
Add the path to the folder containing adb.exe to the PATH environment variable. If you don't have adb.exe in your computer, download one.
(Off topic) Besides, you seems trying to run a Linux shell script on Windows, please use some software like Cygwin or MSYS2.

Convert simple line of batch file to bash

To run the program zandronum.exe with the file brutalv21.pk3, the instructions for windows give this piece of batch file code:
#echo off
start zandronum.exe -file brutalv21.pk3
But I downloaded zandronum for Linux. What is the equivalent in Bash?
The syntax is simple:
./filename -Arguments
So, you have to write:
./zandronum -file brutalv21.pk3
windows programs won't just run under linux you'll need wine to run them. as far as I've heard ubuntu made running windows programs with wine pretty seamless

from R console windows equivalent of wget

Hi I was wondering what the windows equivalent of wget is
I currently have a function in R that has the command
system("wget www.random.url.com/file")
to download a file from the internet from a mac/unix machine that is running R...what would the equivalent be for R in windows?
Look at download.file to download files to your computer. This works on all operating systems, including Linux, Mac, and Windows.
powershell -command "iwr -outf abc.zip http://example.com/xyz.zip"

What file explorer can I use in Cygwin with UNIX like paths?

I'm fed up with using Windows Explorer as my file browser as I use
Cygwin bash as my primary command line environment.
Windows Explorer shows the full path in the address bar.
Usually, I copy that, pasting it to the cygwin command prompt as in
cygpath ""
I then copy paste the output of cygpath so I can
cd to it. I've also set up cpath "Bash Shell Here"
but this only works on right clicking directories.
I've used WinSCP via SSH.
ie. Start an SSH daemon in cygwin and connect to it via WinSCP.
What file explorer can I use in Cygwin with UNIX like paths?
Is there a cygwin X Windows file explorer?
Have you tried Midnight Commander (mc)? It's in the Cygwin package repository.
If you surround the path from Windows Explorer with single or double quotes, there is no need to use the cygpath command.
In regard to your quest for a compatible file manager, I've heard that KDE's Konqueror runs on Windows.

Resources