To rename a file with a dashed filename, you can use the mv command as shown.įor example, to rename a file named “ -abc.txt” to “ -a.txt“, you would use: $ mv -abc.txt -a.txt You may replace nano with any other editor of your choice, for example, use vim editor as shown: $ vim -abc.txt Here’s an example using the nano text editor: $ nano -abc.txt To edit a file with a dashed filename, you can use various text editors available. rw-rw-r- tecmint tecmint 0 B Tue Jun 20 10:32:43 2023 -abc.txt Create Dashed File in Linux Edit Dashed File in Linux You may verify the file thus created by both the above ways by running commands ls or ls -l for long listing. There are two ways to resolve this error as: $ touch -abc.txt To resolve such an error, we have to tell the bash shell not to interpret anything after the special character (here dash), as an option. ![]() The reason for the above error is that the shell interprets anything after a dash (-), as an option, and obviously, there is no such option, hence the error. Sample Output: touch: invalid option - 'b' To work with dashed filenames in Linux, first, create a file that starts with a dash (-), say -abx.txt using the touch command. These filenames can sometimes cause issues when working with them because the leading dash can be misinterpreted as an option or flagged by command-line utilities. In Linux, filenames that begin with a dash ("-") are often called “ dashed filenames” or “ hyphenated filenames“. Also speaking technically every thing be it a folder, driver, or anything else is treated as a file in Linux. I agree with you, that such file names are not common still your shell should not break/give up when you have to deal with any such file names. ![]() One of the most obvious questions here is – who on earth create/deal with files/folder name having a Hash (#), a semi-colon ( ), a dash (-) or any other special character. Special Characters in Filenames in LinuxĮxamples of the most common file names are: abc.txtĮxamples of numeric file names are: 121.txtĮxamples of Alpha-Numeric file names are: eg84235.txtĮxamples of file names that have special character and is not very common: #232.txt.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |