Searching a text in a file on Linux

Posted on

This is an article which is used for describing about how to search a text in a file on Linux operating system distribution. If there is a need to find a certain pattern of text from a certain location where there are piles of files and folders and it is being suspected or assumed contain that certain pattern of text, this is the command pattern which can be executed to find one :

find [searching-location-path] -type [type-of-attribute] -exec grep -H 'word' {} \;

Description :
find : It is a command search a files in a directory hierarchy, based on the reference given in its manual page
[searching-location-path] : The path given as an initial start to search from
-type : A parameter which is used to define the attribute of searching or the type of attribute where the searching process is going to be applied
[type-of-attribute] : It can be 'f' for files and 'd' for directory. 
-exec : A parameter which is used to define the command passed 
grep -H 'word' {} \; : The command passed which in this case to find the text pattern 'word' with the -H parameter for printing the file for every matching search.  

This is the example of the above command pattern :

user@hostname:/var/www/html/laravel-project# find . -type f -exec grep -H 'cipher' {} \;

The example of the command above is being executed to find a word or a text ‘cipher’ in the current folder through all the files exist in that folder.

Below is the output of the above command executed in the command line interface :

user@hostname:/var/www/html/laravel-project# find . -type f -exec grep -H 'cipher' {} \;
./config/app.php:    'cipher' => 'AES-256-CBC',
./storage/logs/laravel.log:[2017-02-04 12:03:34] local.ERROR: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. in /var/www/html/laravel-project/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:43
./storage/logs/laravel.log:[2017-02-04 12:03:34] local.ERROR: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. in /var/www/html/laravel-project/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:43
./vendor/swiftmailer/swiftmailer/doc/messages.rst:The used encryption cipher can be set as the second parameter of setEncryptCertificate()
./vendor/swiftmailer/swiftmailer/doc/messages.rst:See http://php.net/manual/openssl.ciphers for a list of supported ciphers.
./vendor/swiftmailer/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php:     * @link http://nl3.php.net/manual/en/openssl.ciphers.php
./vendor/swiftmailer/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php:     * @param int          $cipher
./vendor/swiftmailer/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php:    public function setEncryptCertificate($recipientCerts, $cipher = null)
./vendor/swiftmailer/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php:        if (null !== $cipher) {
./vendor/swiftmailer/swiftmailer/lib/classes/Swift/Signers/SMimeSigner.php:            $this->encryptCipher = $cipher;
./vendor/laravel/framework/src/Illuminate/Foundation/Console/KeyGenerateCommand.php:            $this->laravel['config']['app.cipher'] == 'AES-128-CBC' ? 16 : 32
./vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php:            return new Encrypter($key, $config['cipher']);
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:    protected $cipher;
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:     * @param  string  $cipher
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:    public function __construct($key, $cipher = 'AES-128-CBC')
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:        if (static::supported($key, $cipher)) {
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:            $this->cipher = $cipher;
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:            throw new RuntimeException('The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.');
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:     * Determine if the given key and cipher combination is valid.
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:     * @param  string  $cipher
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:    public static function supported($key, $cipher)
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:        return ($cipher === 'AES-128-CBC' && $length === 16) || ($cipher === 'AES-256-CBC' && $length === 32);
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:        $value = \openssl_encrypt(serialize($value), $this->cipher, $this->key, 0, $iv);
./vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:        $decrypted = \openssl_decrypt($payload['value'], $this->cipher, $this->key, 0, $iv);
user@hostname:/var/www/html/laravel-project# 

The above are results for every files found which have the word ‘cipher’ inside of it.

One thought on “Searching a text in a file on Linux

Leave a Reply