[HOW TO] Remove files with names that contains special characters

I have wrote the script, unluckily it has created an text file with name that contains special character '-' as below:

@cattek Scripts]$ ls
configuration.sh  -P  rsysnc.sh

I don't like it, it shouldn't stay here. I try to delete:
@cattek Scripts]$sudo rm -rf '-P'

Outputs:
rm: missing operand
Try `rm --help` for more information

The rm command failed to delete that. Finally I find a method to delete. I put '--' the first of file name. A '--' signals will disables further option processing by shell. Any arguments after the '--' are treated  as filenames and argument.

@cattek Scripts]#sudo  rm -- '-P'
rm: remove regular file ‘-P’? y
@cattek Scripts]# ls
configuration.sh  rsysnc.sh

I am glad to see.

Thank you for reading this article, please a comment if you are interested.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

0 nhận xét:

Post a Comment