In particular, it has os.walk() module which allows us to perform the same action as above - traverse directory tree and obtain list of files that contain desired string. Python is another scripting language that is used very widely in Ubuntu world. Once identified such files are copied into a new directory. The command applies to log files whose names contain a date, as in filename-YYYYMMDD.gz. In the script below, I ask a user to input a date range and apply that range to filter the result of a find command. With a small script, you can traverse directory tree, push files that contain the desired string into array, and then print it like so: #!/usr/bin/env perlĪnd how it works: $. Finding files based on the date contained in their filenames. Perl has Find module, which allows to perform recursive traversal of directory tree, and via subroutine perform specific action on them. **/* expansion is a file and whether it contains the desired text: bash-4.3$ for f in. All we need to do is test for whether item in the. bashīash has a very nice globstar shell option, which allows for recursive traversal of the directory tree. Grep is a very powerful tool and accepts various command line arguments. Its name comes from the ed command g/re/p. While find command is simplest way to recursively traverse the directory tree, there are other ways and in particular the two scripting languages that come with Ubuntu by default already have the ability to do so. The command you should be using, in this case, is grep. If you want to enter more than one matching filename on the same command line, press F10 when each desired name appears. grep is a command-line utility for searching plain-text data sets for lines that match a regular expression.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |