Searching for text in directories

To find which pure text files contains a given text from the command line, this is the proper command:

grep -ilr "pattern" directory

The -i option makes the search case-insensitive, -r searches the pattern recursively (that is, in the subdirectories that the actual directory might contain), and -l shows the file list where the pattern occurs.

Thanks to Juan Luis Belmonte for the tip (credit where credit is due).

Posted in Personal technotes. Comments Off on Searching for text in directories

Backing up all user data in Linux

One of the most I like most in Linux is the strong separation among user data and system data. This makes installing new versions, or moving data from different hard disks (and other sensitive operations that require all your data).

To copy all user data you need to type:

tar -cvpf compressed-file.tar /home/

This creates (-c) a file (-f) named compressed-file.tar retaining file and folder permissions and storing there all data from the /home/ directory.

To extract this you would only need to type:

tar -xf compressed-file.tar

The -x option specifies the extraction from -f (file).

To restore the data, the operation should be done at the root directory (since files will be extracted with full-path directories).

Posted in Personal technotes. Comments Off on Backing up all user data in Linux