Match a pattern and delete n lines after it

Suppose you have a file named file.txt with following content. Delete all 2 lines [including pattern itself]after the pattern match “Class”.

I got this trick from SERVERFAULT.COM 🙂

Situation:

Suppose you have a file named file.txt with following content
Continue reading “Match a pattern and delete n lines after it”

bash: /bin/rm: Argument list too long

bash: /bin/rm: Argument list too long. If you’re trying to delete files inside a directory and the following command is not working:

If you’re trying to delete files inside a directory and the following command is not working:

In this case you can delete all files using find with appropriate switches:

If you want to delete files in verbose mode:

rsync – a fast, versatile, remote (and local) file-copying tool

Suppose you have a load of files and folders which don’t want to backup. In this case rsync have option, define all the files and folders which want to exclude in a single file and make rsync to read from it.
Copying a file from one location to another(under same file system hierarchy)
Copying a file from one machine another remote machine
Copying all files except one
Delete files from the destination folder that are no longer required (i.e. they have been deleted from the folder being backed up)

Rsync is a fast and extraordinarily versatile file copying tool. It can copy locally, to/from another host over any remote shell, or to/from a remote rsync daemon. It offers a large number of options that control every aspect of its behavior and permit very flexible specification of the set of files to be copied. It is famous for its delta-transfer algorithm, which reduces the amount of data sent over the network by sending only the differences between the source files and the existing files in the destination. Rsync is widely used for backups and mirroring and as an improved copy command for everyday use.

Some of the additional features of rsync are:

  • support for copying links, devices, owners, groups, and permissions.
  • exclude and exclude-from options.
  • can use any transparent remote shell, including ssh or rsh.
  • does not require super-user privileges.
  • support for anonymous or authenticated rsync daemons (ideal for mirroring).

I think it is better to study rsync command through examples.
Continue reading “rsync – a fast, versatile, remote (and local) file-copying tool”

Checking SSL cert’s validity and other details

ï»żOpenSSL is a cryptography toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) network protocols and related cryptography standards required by them. The openssl program is a command line tool for using the various cryptography functions of OpenSSL’s crypto library from the shell

1. Get complete available details of an SSL certificate

2. Who issued the certificate?
Continue reading “Checking SSL cert’s validity and other details”

fdupes, a tool for finding duplicates :)

I came to know about this tool, fdupes, from “Tips and Tricks” section of Linux For You Magazine (August 2010). Actually I have a plan to write such a script. Fortunately or unfortunately there is already such a tool and it is more than enough for my purpose. Its a really an interesting tool which will search the given path for duplicate files. Such files are found by comparing file sizes and MD5 signatures, followed by a byte-by-byte comparison of files.

I came to know about this tool, fdupes, from “Tips and Tricks” section of Linux For You Magazine (August 2010). Actually I have a plan to write such a script for finding duplicate files. Fortunately or unfortunately there is already such a tool and it is more than enough for my purpose. Its a really an interesting tool which will search the given path for duplicate files. Such files are found by comparing file sizes and MD5 signatures, followed by a byte-by-byte comparison of files.


Continue reading “fdupes, a tool for finding duplicates :)”

Passing shell variables to awk program

For an administrator awk is very important and it will help him in many ways. One day, I get into trouble for passing shell variables inside awk. After some GOOGLING I got the solutions.

You can follow any of the following 2 methods:

Method : 1

Limitations of this method:

a. Shell variables assigned using this method are not available in the BEGIN section

b. If variables are assigned after a filename, they will not be available when processing that filename

Method : 2

Delete files from hard disk without leaving even a single option to recover it.

Ordinarily when you remove a file, the data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused. On a busy system with a nearly-full drive, space can get reused in a few seconds.

Ordinarily when you remove a file, the data is not actually destroyed. Only the index listing where the file is stored is destroyed, and the storage is made available for reuse. There are undelete utilities that will attempt to reconstruct the index and can bring the file back if the parts were not reused. On a busy system with a nearly-full drive, space can get reused in a few seconds. But there is no way to know for sure. If you have sensitive data, you may want to be sure that recovery is not possible by actually overwriting the file with non-sensitive data. However, even after doing that, it is possible to take the disk back to a laboratory and use a lot of sensitive (and expensive) equipment to look for the faint “echoes” of the original data underneath the overwritten data. If the data has only been overwritten once, it’s not even that hard.


Continue reading “Delete files from hard disk without leaving even a single option to recover it.”

Troubleshooting your Application

Many times I have come across seemingly hopeless situations where a program when compiled and installed in GNU/Linux just fails to run. In such situations after I have tried every trick in the book like searching on the net and posting questions to Linux forums, and still failed to resolve the problem, I turn to the last resort which is trace the output of the misbehaving program. Tracing the output of a program throws up a lot of data which is not usually available when the program is run normally. And in many instances, sifting through this volume of data has proved fruitful in pin pointing the cause of error.

Many times I have come across seemingly hopeless situations where a program when compiled and installed in GNU/Linux just fails to run. In such situations after I have tried every trick in the book like searching on the net and posting questions to Linux forums, and still failed to resolve the problem, I turn to the last resort which is trace the output of the misbehaving program. Tracing the output of a program throws up a lot of data which is not usually available when the program is run normally. And in many instances, sifting through this volume of data has proved fruitful in pin pointing the cause of error.
Continue reading “Troubleshooting your Application”

Dynamically changing the values of kernel parameters

There are lot of kernel parameters and those parameters can be viewed from /proc/sys/ directory. Modification of values of these parameters will persit only until the next reboot of the system.

We can modify these kernel parameter values manually. i.e. by echoing new values to files in /proc/sys/ [Each parameters have a file in /proc/sys/ directory].

There are lot of kernel parameters and those parameters can be viewed from /proc/sys/ directory. Modification of values of these parameters will persit only until the next reboot of the system.

We can modify these kernel parameter values manually. i.e. by echoing new values to files in /proc/sys/ [Each parameters have a file in /proc/sys/ directory].


Continue reading “Dynamically changing the values of kernel parameters”

dmidecode, tool for retrieving BIOS information

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision.

Thanks  to  this  table, you can retrieve this information without having to probe for the actual hardware.  While this is a good point in terms of report speed and safe‐ness, this also makes the presented information possibly unreliable. The DMI table doesn’t only describe what the system is currently made of, it also can report the possible evolutions (such  as  the  fastest  supported CPU or the maximal amount of memory supported). SMBIOS  stands  for System Management BIOS, while DMI stands for Desktop Management Interface. Both standards are tightly related and developed by the DMTF (Desktop Management Task Force).dmidecode has many options which all are well documented in its man page.

An example for dmidecode output: Continue reading “dmidecode, tool for retrieving BIOS information”