DevOps - Kote

Remove old files in bash using ‘find’

How to quickly remove old files or likely old log files using bash? Just a few lines in bash can solve it.
Firstly, list all files older than 7 days for required directory:

find /home/my-user/my-logs -type f -mtime +7

After that, delete all those files:

find /home/my-user/my-logs -type f -mtime +7 -delete

Here are the man page for the find command in arch manual page.

Choosing the best editor for log search

Logs, logs, logs… they are everywhere! While scanning another endless log file, I wondered if there is any difference in the speed and performance of popular text editors when working with large log files. It turns out there is! Let’s compare Notepad, Notepad++, TextPad, and Atom in the speed of text search in log files.

Let’s focus on the following:

  • Startup time
  • Memory consumption at startup
  • Time to open an editor and a file (100 MB and 1 GB)
  • The amount of RAM used
  • Searchin for a line of text
  • Regular expression search

Continue reading “Choosing the best editor for log search”

Working with SSH keys for remote sessions in Linux

SSH keys can be used as an excellent choice for authenticating remote hosts. Using keys instead of simple usernames and passwords have many advantages, however, what is more, essential for me to – use an ssh key helps establish a connection faster and more secure. Let’s review how to create, share and use keys. Continue reading “Working with SSH keys for remote sessions in Linux”

HSTR (HiSToRy) – Advanced console history search

HSTR or HH is a great tool that speeds up console usage due to the intelligent search for recent and favorite commands. Before that, I used to have a few hacks like running grep for history ($ history | grep {my-search-request}), but with a new HH help, I feel like I can focus on tasks and not worry about recent commands entered as they can be accessed fast and convenient.

Continue reading “HSTR (HiSToRy) – Advanced console history search”

Replace CRLF to LF in bash script

Some of my bash scripts were not running with the following error:

$ ./test-script.sh
-bash: ./test-script.sh: /bin/bash^M: bad interpreter: No such file or directory

After some googling, it turned out that on Linux host script files should have a specific line break(LF), and using default Windows (CRLF) is not supported.

How to fix:

Continue reading “Replace CRLF to LF in bash script”