curl output file replacing path seperator with underscore when writing the file - batch-file

I'm trying to create a fairly simple batch file to download a file from our ftp site and store it in a specific directory. I would like to be able to put the batch file in the path so I can call it from anywhere. Currently I have a line like the following:
curl -v -u %FTP_USER%:%FTP_PASS% -Q "TYPE I" -o %OUTPUT_PATH% "ftp://%FTP_HOST%/%JAR_FILE_NAME%"
What I've discovered is that no matter the value of the output path, the file is always written in the current directory, and any path seperators are converted to underscores in the file name. This happens no matter if I use a '\' or '/' and if I try to escape it with double slashes I just end up with two underscores. Quotes around things don't seem to help either.
My question is does the -o option allow for outputting to a folder other than current working dir? I guess I can have the next step in the script to be "move the file to its destination", but that seems really kludgey.

This sounds exactly like a regression (reported here) we unfortunately brought in curl 7.47.0. We hope to release an updated, fixed, version soon and in the mean time you can probably consider downgrading to an earlier version to work-around this annoying issue.

Related

Rename Multiple files in a Unix Directory by removing characters

I would like to rename Multiple files in a Unix Directory using Ksh Command.
Eg ATT8-2011-10-01 00:00:00-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF
needs to be renamed as
ATT8-2011-10-01-MSA-IMM-SINGLE_AND_FAMILY_COVERAGE-DED-$2000-X114817.PDF
Basically the time portion which is always 00:00:00 needs to be stripped off and the space between the date and the next hyphen symbol (-) needs to be compressed.
Any ideas as to how to this ? Assuming they are about 3000 files in the directory.
On some systems, there is a Perl-based rename command (sometimes called prename) and you'd write:
rename 's/ 00:00:00//' *" 00:00:00-"*
If you don't have that, find it. If you can't find it, then you have more work to do. However, the work is searching on SO. For example, Underscore in rename command (Perl and Unix shell) has a link to one version of the prename (Perl rename) command.

Find multiple files from the command line

Description:
I am searching a very large server for files that is on a different server. right now I open command prompt and type
DIR [FILE NAME] /S/4
This returns the server location of the file with some other stuff that is not really needed.
Question:
I have a lot of files to search and one by one input into the above command could take forever. Is there a way I could input all of the names of all the files and only search once and the search results would only need to show file name and location?
First, I hope you don't mean DOS, but rather Windows cmd or batch.
You can certainly write a script that will run your DIR command once per file being sought.
But what you most likely want instead is to search once and print the path of each file found. For this you can use PowerShell's FindChildItem or the improved one posted here: http://windows-powershell-scripts.blogspot.in/2009/08/unix-linux-find-equivalent-in.html
It will be something like:
Find-ChildItem -Name "firstfile.txt|secondfile.txt|..."
Another approach is to install msys or cygwin or another Linux tools environment for Windows and use the Linux find command.

Ubuntu - "mv" command renames file to empty file name

I have a simple script to move files between directories. Basically, it is:
mv /dir/* /dir/proc/
saved into a shell script "mvproc.sh".
For some reason, when I run the script (sh mvproc.sh) the file indeed gets moved, but it does not retain the filename and instead gets just an empty filename. When I run the same command at the bash prompt, it works fine however.
This script used to work fine on Debian but we had a hard drive failure and I am now migrating everything over to a Ubuntu machine.
Any idea why this is happening? It seems so simple yet I cannot figure it out.
Many thanks.
edit...
I think I found the solution. For some reason it was putting in carriage returns and maybe line breaks or something that I could not see while editing the sh script in either Notepad++ or even gedit. To solve this, when I open the scripts in gedit, I do a Save As, and select Unix/Linux in the drop down menu towards the bottom. This hopefully gets rid of the weird carriage returns even though I could not see them.
Hopefully this helps some poor soul like me in the future pulling their hair out over this!
Thanks!
Try: mv /dir/file /dir/proc/file
You are indeed moving the file, but aren't specifying a destination name. Other usages of mv:
Move and rename: mv /dir/filename /dir/proc/newfilename
Rename: mv /dir/filename /dir/newfilename

How to remove specific characters from a file name?

I have bunch of files that need to have a (.) dot removed from the file-name. Eg. "Mr.-John-Smith.jpg" to "Mr-John-Smith.jpg". I don't have real experience with programming and know only html/css and a little javascript. I found another identical question here on stackoverflow, but what I gathered it was fixed on linux system and BASH was used.
Anyways, if anyone could provide me a tutorial on which program to use for this and what code to execute in that program to make it happen I'd be grateful.
if you are using a windows environment (which i guess you do)
you can download this free utility to mass change file names !
main page :
http://www.bulkrenameutility.co.uk/Main_Intro.php
download page :
http://www.bulkrenameutility.co.uk/Download.php
its easy to use
enjoy
If your file names in a file...
1- Open Microsoft Word or any text editor. Press ctrl+h and then search "." without quotes then replace it with blank character.
2- It will remove all dots, again bring "." to your file extention such as .jpg , .png searh your file extention for example "jpg" and replace it with ".jpg"
It will works %100, i am using this method everytime.
if they are not in a file and if you want do somethings in your operation systems' file system
Try this program. It is very useful for this operation;
Download
To remove all except the extension dot from all files in a directory, you can use PowerShell that comes with newer versions of Windows, and can be downloaded for older versions;
Line breaks inserted for readability, this should go on one line;
PS> dir | rename-item -newname {
[System.IO.Path]::GetFileNameWithoutExtension($_.name).Replace(".","") +
[System.IO.Path]::GetExtension($_.name); }
What it does is to take the file name without an extension and remove all dots in it, and then add back the extension. It then renames the file to the resulting name.
This will change for example do.it.now to doit.now, or in your case, Mr.-John-Smith.jpg to Mr-John-Smith.jpg.

How do I view or rename a file with missing extension?

I have a strange file in my file system without the extension part. The filename is "15.". The weird thing is that it is not one of those without the dot part (like just "15"), but the one with the dot but no extension ("15.") -- it is literally an illegal filename in windows, and not sure how did it get created in the first place.
I know it is a text file and it is about 15KB in size; however, due to the weirdness in name, I can't open it with any application -- I've tried to open in notepad, wordpad, etc., have tried the 'type' command to spit it out on commans shell, tried to shell-open enclosing filename in quotes, and so on -- all methods result in a 'file not found' error except the notepad, which says '15.txt' is not found.
Due to the nature of the issue and the way search engines optimize the search, it is extemely hard to search for an answer in any of the search engines online. So, I just wanted to put this question out there and see if anybody had to deal with a similar issue and have found any way to rename the file or even to change the extension.
Filenames that are valid in NTFS but cannot be used from Windows can be created when accesing disks or shares from other operating systems like Linux.
If you don't have a Linux installation at hand, then get hold of a "live" CD, boot Linux, and change the filename.
That may sound like a hassle, but Windows-only solutions (moving stuff around, deleting the directory) are even worse.
Use REN: http://ss64.com/nt/ren.html
It is a command prompt command (run > cmd > cd wherever > ren 15. 15.txt )

Resources