Sometimes you might have use cases, when specific command or script should be run no longer than given amount of time. In those cases you should run commands with timeout.
Continue readingread log files in portions by bytes
You may want to read log files for newly appended data. You could do it by knowing how many lines you read before and how many lines you have “now”. But when you have large log files, this approach will become very slow. Try to run “wc -l” on file which has tens of millions of lines and you’ll see how slowly it counts. And you would have to do something like that each time you are reading new portion of data. What to do? Read log in bytes instead. Here is how.
Continue readingdetect corrupted images
If you have a need to detect corrupted images, you can easily do it with command line utility “identify“.
Continue readinggrep to output only needed capturing group
Say you have some text and some pattern that you want to provide for grep. Everything is easy, until you want to extract only the pattern-matching part, not the whole line that has the match. What to do? You can “grep” and use pipe for further processing, like sed or awk. But did you know that you can grep only capturing group output without using anything else? We will be using “grep -P” (Perl Compatible Regular Expressions – PCRE) for that.
Continue readingfew useful commands while searching for files / patterns in files
Searching for files or patterns in files occurs quite frequently when dealing with CLI daily. Search for files in Linux is one of the essential skills to have while administrating servers. Here are few useful commands for fast implementation of such tasks.
Continue readingrun cron jobs more frequently than once per minute
Sometimes you might encounter situations when you need to run cron jobs more frequently than least possible option provided by crontab (1 minute). Although you should consider converting such tasks into daemons, in some cases it might really be enough to just solve it “quick and dirty” way. Here is how.
Continue readingskip non-printable characters with “strings”
Have you ever seen something like this, when you needed to skip non printable characters in order to see file contents?
[root@linux ~]# less test
"test" may be a binary file. See it anyway?
[root@linux ~]#
Continue reading shorthand if – else in bash
For some simple if-else conditions you may want to avoid having whole if; then; else; fi type of code. Instead, you can do it all in one bash if shorthand line. Here is how.
Continue readingprint all combinations from given range recursively
Sometimes you may encounter situations, when you wish to display all possible combinations of characters from given charset (e.g. some brute-force task). For example, print “a … zzz”, i.e. range is “a … z” and maximum length is 3. You can easily do this in bash (print recursively).
Continue reading“Hello World” in bash
Let’s suppose that you have just opened Linux terminal for the first time in your life. Your wish is to write nothing but bash “hello world” type of thing. As this command is one-liner, you can simply do this:
Continue reading