Given all the ways that you can browse and select content from compressed files, it might be a good time to exercise your "overcleverness" and see how helpful the methods described in this post might be. The files will remain compressed on your disk, but you'll be able to notice the size changes. Using vi or vim, you can actually edit some compressed files ( bz2, gz and xz files) to add, change, or remove content. To search for specific text in compressed files, you can use commands like these: $ bzgrep overclever words.bz2įor any of these commands, you should see these words that they pull from the compressed word files: overclever Searching for text in other types of compressed files There doesn't seem to be a grep-like command for 7z files, but commands like this work very well. Something I like a lot for this is ZTreeWin running in WINE on Linux - you can do a lot with it.
is that a sequence can be difficult to find if it wraps a line. You need to use the following command: grep -rnw /path/to/somewhere/ -e pattern. A problem with using strings is that you dont see surrounding non printables and you have to be careful with the minimum string length. It is designed to find the files containing the necessary text according to patterns in the entire data streams. $ 7z x -so words.7z | grep clever | columnĬlever cleverest cleverly overcleverly unclevernessĬleverality clever-handed cleverness overclevernessĬlever-clever cleverish clevernesses uncleverĬleverer cleverishly overclever uncleverly The best way of finding files that contain a specific text is by using the grep command. The -so option tells the command to write data to standard out. However, a command like that below leaves the compressed file intact but also extracts the contents in the process. The 7z command allows you to view files included in the archive, but searching their contents requires an extraction (-x) option. $ less words.bz2 $ less words.gz $ less words.xz You can browse some types of compressed files ( bz2, gz and xz) using the less command. You can also pipe the output to commands like more or grep, or simply watch it scroll rapidly down your screen. To view the entire content of a compressed file while leaving the compressed file intact, you can use any of these commands:įor example: $ bzcat words.bz2 | head -5 $ 7z x -so words.7z | head -5
The resultant files then looked like this: $ ls -l
The -k options used with the bzip2, gzip, and xz commands kept these commands from removing the original file, which they would by default.
#LINUX SEARCH FOR TEXT IN FILES HOW TO#
$ zip words.zip words How to use the grep command on Linux Iįirst, to show you how this works, I compressed the words file on one of my Linux systems (/usr/share/dict/words) using these commands: $ cp /usr/share/dict/words. Depending on the format of the files, you can choose to view entire files, extract specific text, navigate through file contents searching for content of interest, and sometimes even edit content. There are quite a few ways to search through compressed text files on Linux systems without having to uncompress them first.