How do I deal with a filename that starts with the hyphen (-) character?
You can refer to it either using ./-filename
or some command will allow you to put it after double dash:
rm -- -filename
How to remove a file beginning with a dash (in Unix like mode)
Use a double hyphen (--
) to stop flag parsing:
rm -- -\ -l
Alternatively, you can even use tab completion:
rm -- \- # Then press TAB immediately after typing the final -
This assumes that's the only file with a leading hyphen in the directory. Bash is smart enough to automatically escape the space in the middle of the file name.
if single-character filename exists within a string enclosed in [ ] entire string gets replaced with the character
It is not a bug.
Characters in square brackets is the part of glob matching. Try:
cd /
echo [abcd]*
And if there is no files matched to the given mask then the mask printed as is.
So you need to quote your values:
mkdir /tmp/temp123
cd /tmp/temp123
echo "[123abc]"
touch a
echo "[123abc]"
How to open a - dashed filename using terminal?
This type of approach has a lot of misunderstanding because using - as an argument refers to STDIN/STDOUT i.e dev/stdin or dev/stdout .So if you want to open this type of file you have to specify the full location of the file such as ./- .For eg. , if you want to see what is in that file use cat ./-
Using dash character in main source file name
In short - if you do not give the module a name, the D compiler will use the file-name (without extension) as module-name.
So, if you name your D source file hello-world.d
, and it does not have something like module hello_world;
at the top of the source-file, the compiler will actually try to insert and compile module hello-world;
and that will fail because hello-world
is not a valid identifier.
If the file name was hworld.d
for an example, then the compiler will actually compile a module with auto-generated name hworld
.
Including a hyphen in a regex character bracket?
Escaping using \-
should be fine, but you can also try putting it at the beginning or the end of the character class. This should work for you:
/^[a-zA-Z0-9._-]+$/
How can I grep for a string that begins with a dash/hyphen?
Use:
grep -- -X
Documentation
Related: What does a bare double dash mean? (thanks to nutty about natty).
Delete dir with hyphen in name
You could do:
rm ./-p
And depending on the rm
used:
rm -- -p
Related Topics
Glibc Scanf Segmentation Faults When Called from a Function That Doesn't Align Rsp
Sed In-Place Flag That Works Both on MAC (Bsd) and Linux
How to Prevent a Background Process from Being Stopped After Closing Ssh Client in Linux
What Does Set -E Mean in a Bash Script
How to Pass Command Output as Multiple Arguments to Another Command
How to Change Permissions For a Folder and Its Subfolders/Files
How Does "Cat ≪≪ Eof" Work in Bash
Get Exit Code of a Background Process
Linux Blocking Vs. Non Blocking Serial Read
How to Generate a Core Dump in Linux on a Segmentation Fault
How to Search For a Multiline Pattern in a File
Bash Script Prints "Command Not Found" on Empty Lines
What Happens to an Open File Handle on Linux If the Pointed File Gets Moved or Deleted
How to Redirect Output to a File and Stdout
How to Test If a Variable Is a Number in Bash
How to Detect Invalid Utf8 Unicode/Binary in a Text File