

To copy a hash file, you can use the cp command as shown. To rename a hash file, you can use the mv command as shown. Verify Hash Files in Linux Rename or Copy Hash File in Linux #bc.txtįinally, verify the file just created using the ls command. To execute the above situation successfully we can do, $ touch a.txt. Obviously from the above example it only created file ‘ a‘ and file ‘ #bc‘ has been ignored. What happens when you create two files (say a and #bc) at once: $ touch a.txt #bc.txt Now create a file the name of which contains # anywhere except at the begging. rw-rw-r- tecmint tecmint 0 B Tue Jun 20 11:11:00 2023 #abc.txt Create Hashed File in Linux #abc.txtĪnd verify the file just created as: $ ls -l To resolve such an error, you may ask bash not to interpret # as a comment. So the touch command has been passed without any file operand and hence is the error. The reason for the above error is that bash is interpreting #abc.txt as a comment and hence ignoring it. Sample Output: touch: missing file operand Here’s an example of creating a file with the "#" character in its filename: $ touch #abc.txt If you’re writing a shell script and want to include the "#" character in a filename, it’s advisable to properly escape or quote the filename to avoid any unintended interpretation as a comment.


However, it’s worth mentioning that some special characters, including the "#", have special meanings in certain contexts or when used with specific commands or utilities.įor example, the "#" character is commonly used in shell scripting to indicate comments. You can use the "#" character like any other alphanumeric character in a filename. In Linux, the "#" character is not restricted or reserved for any specific purpose in filenames. The same rule as discussed above follows for the name of the folder having any number of hyphen and their occurrence, except the fact that for deleting the folder you have to use ‘ rm -rf‘ as: $ rm -rf -abc The same rule as discussed above follows for any number of hyphens in the name of the file and their occurrence. If you have lots of files in a folder the name of which contains a dash, and you want to delete all of them at once, do as: $ rm. To delete a file with a dashed filename, you can use the rm command as shown. 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.
