delete a file
2
0
Entering edit mode
2.9 years ago

Hello everyone, I hope you can help me with this issue. I have to delete a file from the server, but every time I try with "rm" the symbol "<" appears instead of the "$" and I have to quit the terminal to be able to work again. Some times it says that the name of the file is too long to be removed or even just modified. What can I do?

The file name is: 'SRR8837339.bam'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''[A'$'\033''['

howto remove delete filedeletion cancel • 2.2k views
ADD COMMENT
2
Entering edit mode

That's pretty mangled.

Long shot, since removing won't work, but can you try renaming the file first? (mv stupidlongname.ext newname.ext). Otherwise you might need to resort to find.

ADD REPLY
2
Entering edit mode

moving it ... good call Joe

you can even try moving it to /dev/null which will actually also "delete" it

ADD REPLY
0
Entering edit mode

Yeah good idea. I guess this will come down to whether the filename is too long for bash (since that has limits on numbers of commandline arguments and I guess maybe string lengths - but I don't know) or is running in to a specific limitation of the rm tool.

The terminal hanging I suspect is just the special characters in the file tricking bash in to thinking there's more to come, but the error saying it can't be moved/modified suggests its rm itself that's choking (and I would guess mv has similar limitation - but that is a total guess).

I've run in to having too many arguments before, but never one that was too long.

ADD REPLY
0
Entering edit mode

I've already tried to rename it, it says the file name is too long to be modified

ADD REPLY
1
Entering edit mode

I'm guessing you made this file with a script (probably something in python). You might be able to add a remove command to the same script to remove it, since then you're not dealing with bash and requiring a bunch of escapes.

ADD REPLY
0
Entering edit mode

If none of the solutions here work then one can try to open up a graphical SFTP window (use MobaXterm for PC or FileZilla on macOS) and then simply highlight the strange name and delete it.

Solution below removes all files starting with that SRR* which may not always be wanted.

ADD REPLY
3
Entering edit mode
2.9 years ago

That's a very unusual name with many non standard character. Perhaps it is what causes the weird behaviour. Have you tried auto-completion/wild cards ? For instance, if this is the only file starting with "SRR8837339.bam" in the directory, you can try:

rm SRR8837339.bam*
ADD COMMENT
0
Entering edit mode

It worked! Thanks a lot!

ADD REPLY
0
Entering edit mode

Thank you all! The issue is solved

ADD REPLY
2
Entering edit mode
2.9 years ago

that is some weird messed-up file name ...

did you try with auto-completing the filename? (use the tab-key to do so) it's very likley that you will have to escape a number of chars in that filename to be able to rm to work .

there is indeed a max length on filenames in linux.

If all fails you can try to 'process' it with find making use of its -delete option ?

ADD COMMENT
0
Entering edit mode

Thank you for the answer! Can you explain me a little bit better the auto-completing? I have never done it and I don't want to mess things up more than they already are

ADD REPLY
0
Entering edit mode

sure, and don't worry to mess things up with auto-complete, that's not really possible.

auto-complete on linux/unix command line is done by hitting the tab-key, you terminal will then automatically expand paths and filenames (as long as they are unique). Additional advantage, apart from avoiding typo's, is that it will also escape as needed all special characters.

https://www.howtogeek.com/195207/use-tab-completion-to-type-commands-faster-on-any-operating-system/

ADD REPLY
0
Entering edit mode

(Also note that if paths aren't unique, you can double press tab and it will list out items matching whatever stub/stem you have input so far.)

ADD REPLY

Login before adding your answer.

Traffic: 1819 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6