![]() ![]() Obvious 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. #abc.txtĪnd verify the file just created as: $ ls -l To resolve such error, you may ask BASH not to interpret # as comment. So the command touch has been passed without any file Operand, and hence is the error. The reason for above error, that Bash is interpreting #abc.txt a comment and hence ignoring. Sample Output touch: missing file operand Anything after a # is interpreted as comment and hence neglected by BASH. The symbol # has a very different meaning in BASH. The same rule as discussed above follows for the name of the folder having any number of hypen and their occurrence, except the fact that for deleting the folder you have to use ‘ rm -rf‘ as: $ rm -rf -abcĭealing with files having HASH (#) in the name The same rule as discussed above follows for any number of hypen in the name of the file and their occurrence. If you have lots of files in a folder the name of which contains dash, and you want to delete all of them at once, do as: $ rm. ![]() Similarly to move such file you have to do: $ mv -abc.txt -a.txtĪnd to Delete this file, you have to do: $ rm -abc.txt Note: You may replace nano with any other editor of your choice say vim as: $ vim -abc.txt To edit the above file you may do: $ nano -abc.txt 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 error, we have to tell the Bash shell (yup this and most of the other examples in the article is for BASH) not to interpret anything after special character (here dash), as option. The reason for above error, that shell interprets anything after a dash (-), as option, and obviously there is no such option, hence is the error. Sample Output touch: invalid option - 'b' Dealing with file that has dash (-) in it’s nameĬreate a file that starts with a dash (-), say -abx.txt. Also speaking technically every thing be it folder, driver or anything else is treated as file in Linux. I Agree to 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 question here is – who on earth create/deal with files/folders name having a Hash (#), a semi-colon ( ), a dash (-) or any other special character. The asterisk (*) is a wildcard character that matches any sequence of characters.Examples of file names that has special character and is not very common: #232.txt txt extension $ find -type f -name "*.txt" To find files with a specific name pattern - for example all text files with. The option ‘-type -f’ is used for finding regular files (or can use ‘-type d’ if you want to search only directories). Note: To restrict the search to a specific directory use find /path -type f -name string. Finding File by nameįor example, to find files with the name “meta.db" in the current working directory and subdirectories: $ find -type f -name "meta.db" It provides an interactive and intuitive way to search for files. It's worth mentioning fzf (fuzzy finder tool) and fd which are two popular and powerful alternatives to find. ![]() Expressions are used to further refine the search based on various criteria. ![]() Defines additional conditions or actions such as "-and", "-or" or "-not" for the search.- pass specific requirements (e.g., -type f for regular files, -type d for directories).- Gives a start point and performs a recursive search.However, there are other commands and apps available in Linux that can also be used to search for files: When you look for searching files, find is the built-in and primary command for searching files in Linux. In this guide, we learn different ways to find files in Linux. Based on your preference you can choose between CLI or GUI for file search. To find Files in Linux you can either use inbuilt command line tools, GUI file managers, or some modern apps. ![]()
0 Comments
Leave a Reply. |