Also, it's an old habit from the days when you only got 8 chars to say it. Most techies I've worked with use the 3-fingers-on-one-hand-2-on-the-other method, and they like to use short variable name, don't like to comment, and in general cannot be counted on to help with the user doc. Maybe because, unlike most programmers, I can type with ten figures at a normal writing speed - few people need more than 40 words per minute to type as fast as they can compose. I'm a big fan of English language file names, that is, not something like RSFunc97Stat.txt. It doesn't crap out as soon as it hits the space. Now if your file name is /home/he/Documents/00 - Writing/02 The Rapture of the Maiden/0 - Text/25th/Rapture, pt 1-4, ch 01-20 old.txt, I use the C-shell, as I was a berkeley/Sun user at the Lab, but the same ideas apply in bash. To get it to work on anyįile system, EG NTFS, you need to quote the $PWD. Garbage if you have actual file names, not Unix-style file The problem is $PWD, which results in useless Is there a faster way to do what I am trying to do than to use find? However, it is a ton to type, and it is certainly not as fast as using ls with grep. This will give me a nice format (It also includes the user, group, size, and last date of access, which are helpful). If I just use find without ls or grep, then it goes faster, but it is a bunch to type: find $PWD/ -type f -name file.name -printf '%M %u %g %s\t%a\t%p\r\n' I can use ls integrated with find and grep to get the output in exactly the format that I want, and I could use something like this: ls -ault `find $PWD/ -type f` | grep file.nameīut this is extremely slow, I'm guessing because two commands are actually running. I would prefer to use ls because it is the fastest, and I would type: ls -alR $PWD/īut this doesn't show the file's path, so if I grep'ed the output, then I would see file permissions, but not the directory from which it originated. I want to do this so that I can grep out what I want, so that when I run the command, I can get just the matching files, their permissions, and their full paths, like: | grep file.name Now that you know better, you won’t make the mistake I did (and probably have done several times earlier without knowing better!).I have done a bit of searching online, and I am trying to find a way to recursively list all files with their absolute path and with their permissions. Grep would then think (since the shell interpreted your input first hand) you would only be interested in the files listed in the current directory. I haven’t confirmed my theory on this yet, but my assumption is that “*.ufo” is interpreted by the shell first and then passed on to grep. Note that the file search pattern has been modified from “*.ufo” to “*”. In order to search through all the subdirectories as well, you need to use the following command: grep -r "The lecture was then essentially" * -include=*.ufo Instead, it will search through all files in the *current* directory! Now, if we want to find out which files that contain a specific search term, in the current directory and all subdirectories, the intuitive approach would be to run the following command: grep -r "The lecture was then essentially" *.ufoĭon’t you agree? However, grep will not provide the desired response if you run this command! For my own amusement, I used the ufo archives from, located at. Beforehand, I knew to a certain degree what the result would be, but grep was unable to find what I was looking for! Let me illustrate by example:įor this test we will use a random set of text files found on the internet. I got really surprised the other day when I had to do a recursive search on files with a specific suffix, like *.txt. Grep will recurse through the current directory and all subdirectories for instances of “search term”. If you however need to search through the current folder (which also happens to contain multiple subfolders), and you want to do a recursive search through all the subfolders, you would on a Linux system normally write the following: grep -r "search term" *Īnd you will then get the desired response. This will search through all files in the current folder and report where instances of “search term” are found. In its simplest form, you normally run: grep "search term" * It’s easy to learn, and it has multiple additional functionaltity (like regular expression search patterns) for finding that particular needle in the haystack you are looking for. If all else fails, or I am unable to install Cygwin for some reason, I turn to the the built-in Windows command line tools find and findstr for emergencies. If I happen to be on a Windows computer, I normally install Cygwin that allows me to use the same tool. Whenever I need to search through multiple files after a specific term, I usually turn to GNU grep.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |