Copying and removing Files in Linux.

Copying and removing Files in Linux.

--I am on windows 7, Using Putty I have made an SSH session to an appliance that is linux based OS

there is a file named:

 \\ABCD$test021318.txt

I need to remove it in linux using the command rm , but it does not want to remove it.

-- I also want to pipe a command from the appliance to direct the output to a text file in my c:drive on windows but it does not put it in my PC.

If I run Dir command on the SSH session, I see the file name created there, but not in my PC.

Any Help will be very much appreciated.

Thank you
jskfanAsked:
Who is Participating?
 
nociSoftware EngineerCommented:
found some windows user computer with winscp:  (V 5.7.6 used here) from  http://winscp.net/

Just use WINSCP ....  ( no fancy command line ..) but start it from the explorer... not cmd.
logon the server with SFTP, hostname, port 22, username, password.   and press login:

then a TWO window screen opens.. Left local disk, right ssh connected site.
dragging a file from left to right or right to left will transfer it.
0
 
Travis MartinezSmoke JumperCommented:
Is the file name literally "\\ABCD$test021318.txt"?  That's pretty unusual for a UX system to have a name like that.  Can I assume that the two backslashes are indicating the system or is it really part of the name?

One of the cool things with putty is the command line "plink" will allow you to run remote ssh commands from your command window to the Linux device and output to the local device.

Verify the name above please as well as what you are trying to output and I'll see about getting the plink command to work for you.
0
 
Seth SimmonsSr. Systems AdministratorCommented:
...but it does not want to remove it.

need to explain why
any error message?
a file like that with a $ in it needs to be escaped (with \) so essentially it would be rm -f ABCD\$test021318.txt
1
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Travis MartinezSmoke JumperCommented:
Using plink I can't get the output to a text file.  It interprets the ">" as part of the plink command. **Edit** I had an access/permissions issue.  The output does work using >

However, the command is:

plink -l user_name -pw password host_name command > outfile.txt
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
Try this:

ls -l *test021318*

Does it show you one file? The file you want removed? Yes?

Then do this:

rm *test021318*


Another way. Type "rm \\" (without the quotes) and then the TAB key.

It should show you this:

-rw-r--r--  1 gerwinjansen  staff   0 Feb 13 22:18 \\ABCD$test021318.txt
Gerwins-PC:tmp gerwinjansen$ rm \\\\ABCD\$test021318.txt

Then press ENTER

No luck? Post back the error you get.
0
 
nociSoftware EngineerCommented:
A $ starts a symbol expansion on unix shells (like % does in windows CMD & COMMAND ).
so you need to escape it or us a non expandable string quote (').
A \ is an escape character and takes the next character litteral.
Within a expandable string quoted by (")  symbols are still expanded.
 so either use:   rm  '\\ABCD$test021318.txt'
or escape the $ & \
use:  rm  \\\\ABCD\$test021318.txt

rm -f may not help, as it shows no error if removal fails.

Same for plink...
if > needs to be passed to the command use escape:
plink -l user_name -pw password host_name command \> outfile.txt
or
plink -l user_name -pw password host_name command '>' outfile.txt
0
 
jskfanAuthor Commented:
trying several commands, I am not sure which one removed the file.. Thank you.
regarding, Redirecting the output of the file to C: drive of windows PC from SSH session, how can this be done ?

Thank you
0
 
nociSoftware EngineerCommented:
The easiest way: let the file stay remote and use winscp to fetch the file through a ssh session. (WinSCP support SFTP )

another way is to activate SAMBA on the unix system and integrate that into your windows setup. (Either using Domain authentication or workgroup setup).
But this involves some work.
0
 
jskfanAuthor Commented:
as you can see the top window is WINSCP and its blank, the lower part shows the Test.txt file there. I am not sure why I can see it running the command line, but I cannot see it using WINSCP

win
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
I would use plink for this (see suggestion above) or command line winscp like this:

winscp.com /command "open nbusers@host" "ls -a | grep Test" > c:\folder\output.txt
0
 
nociSoftware EngineerCommented:
if you want to copy files why open the winscp console, you need an SFTP connection.
(I have no windows system so i cannot effectivly help on using WinSCP.

(Using scp one would use a command like:

scp nbusers@host:Test.txt  localtest.txt

should work, maybe winscp commandline mode can help?
0
 
jskfanAuthor Commented:
I was able to connect to  winscp.com /command "open myusername@host"

from there if I type lls , all I get is the files under Winscp folder in windows, it does not list what is inside the appliance nbusers directory
0
 
jskfanAuthor Commented:
I downloaded new WINSCP , and verified it is working fine.
Thank you for your help Guys
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
The answer that is now selected (https://www.experts-exchange.com/questions/29083838/Copying-and-removing-Files-in-Linux.html#a42470513) does not fulfil your requirement:

I also want to pipe a command from the appliance to direct the output to a text file in my c:drive on windows but it does not put it in my PC.
0
 
nociSoftware EngineerCommented:
@Gerwin Jansen: using pipes combined with ssh session to copy files is not exactly the best way to transfer files.

So yes the PIPE part is not used, but it was used to attempt a file transfer, well there are better ways to transfer files across systems.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
@Noci - I know but the question is about removing a remote file and capture logging of that command, it's not about a file transfer :)
0
 
nociSoftware EngineerCommented:
nope 1st Q = how to rm
and ALSO (2nd Q)  to execute "a" command and get that output to remote....
easiest is to remote execute the program and then transfer the results.... there are other  ways, but those are less easy to explain... and my not work exactly as expected depending on platforms.
0
 
Gerwin Jansen, EE MVETopic Advisor Commented:
We're getting a bit offtopic but what you do you mean by "there are other  ways, but those are less easy to explain..."? Do you have some examples in mind?

WinSCP GUI only answers the first question (we agree on that) where the second question 'pipe a command from the appliance to direct the output to a text file' can be answered easiest by using plink or winscp command line. Those are not difficult to explain...
0
 
nociSoftware EngineerCommented:
Yes off topic.. it depends on other requirement like input for remote command, if only stdout or only stderr or both (of different file-handles) are needed, what remote command is used... and maybe translate the command to a remote bash -c "bla bla" with appropriate escapes to survive one, 2 or more expansions before execution.  
Not too hard to solve if you know and understand the REMOTE platform.  And there is a problem with that according to the question.
Otherwise the \\ & $ wouldn't be a problem in the first place.
I have no windows and only sometimes have access to a few when on customer premises. So winscp command-line is foreign to me.
(I just open winscp from the menu and that has never been a problem.)
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.