Contents
What to do when a file starts with a dash?
Any commands can use the tips when handling a filename starting with a dash ( – or — ). The syntax is as follows: We use “ — ” to make Linux and Unix command stop parsing shell command line options. Now, let us see some examples.
Is there a way to hide the dash in a command?
You can “hide” the dash from the command by starting the filename with ./ (dot slash). For example, try to remove a file named “ -filename.txt ” using rm command: The — is technically known as delimiting the options list.
Why does Bash split files with spaces in names?
By default, the shell splits the output of a command on spaces, tabs, and newlines Filenames could contain wildcard characters which would get expanded What if there is a directory whose name ends in *.csv?
How are filenames and pathnames handled in shell?
Lots of code in all languages (not just shell), and at least some GUI toolkits, do not handle all permitted filenames and pathnames correctly. Some GUI toolkits (e.g., file-pickers) presume that filenames are always in UTF-8 and never contain control characters, even though neither are necessarily true.
How do I rename a file with a dash?
Typing this command with the forward slash in front of the dash will rename the file in the current directory and cause Linux or Unix to not notice the dash. The forward slash is an escape sequence character that treats the dash only as text and not as part of the command.
How to create and read dashed filename in Linux?
Normally we use touch to create an empty file. But if you try to create a file starting with dash ( -) or just a dashed filename ( -) # touch -file touch: invalid option — ‘i’ Try ‘touch –help’ for more information. # touch ./- How to open and read dashed filename?
How to RM or MV a file that begins with a dash?
For this mv command to work you must type the below command. Typing this command with the forward slash in front of the dash will rename the file in the current directory and cause Linux or Unix to not notice the dash. The forward slash is an escape sequence character that treats the dash only as text and not as part of the command.