![]() ![]() ![]() So if you have a filename which contains a word which happens to be a glob that matches other filenames in the current directory, that word will disappear and all those matching filenames will appear in its stead! mv `ls` /foo # Exact same badness as the ''for'' thing. Even worse, you're asking bask to take each of those mutilated filename words and then treat them as globs that may match filenames in the current directory. ![]() Which basically means, you're iterating over words, not over filenames. And $(ls) takes the output of ls and cuts it apart into arguments wherever there are spaces, newlines or tabs. They think for magically does what they would like it to do when they do something like: for file in `ls` # Never do this!įor file in $(ls) # Exactly the same thing.įor is a bash builtin that iterates over arguments. You can also use ls with grep, and use grep 's pattern matching capabilities. To list files that have '.c' extensions, use this format: ls. The secondary source of badness of parsing ls comes from the broken way in which half the world uses bash. To list any files or directories that have names starting with 'ip' use this format: ls ip. For all you know, the entire ls output could be one single filename! The main source of badness of parsing ls is that ls dumps all filenames into a single string of output, and there is no way to tell the filenames apart from there. Instead, you should use either globs or find, depending on what exactly you're trying to achieve: mv * /foo Parsing ls is almost always the wrong thing to do, and it is bugged in many ways.įor a detailed document on the badness of parsing ls, which you should really go read, check out: It is not a tool you should use to enumerate them and pass them to another tool for using it there. Any suggestion how to do this My over-all goal is to view the modification dates of all files in the current directory which contain 'file' in their filenames. This doesnt work, but ideally, Id be able to type this: ls -alh grep 'file' less. Ls is a tool used to DISPLAY some statistics about filenames in a directory. Id like to grep the output of ls and pipe it into less so I can scroll through the output. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |