Sometimes we all makes mistakes. And it’s good if this is just typo in command name and we don’t erase important data. So, if it was just a typo Bash gives to us easy way to fix it! Takes the last command, replaces string1 with string2 and executes it. ^string1^string2 For example: $ ehco fooContinue Reading
Category: Tips&Tricks
How to get top 10 commands
It’s more like a joke / just for jun task. But it also perfectly shows one of the Unix principle: Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new “features”. Actually even two principles; Write programs to handle text streams, because thatContinue Reading
How to copy from a terminal to the Linux or MacOS system clipboard
When you use a clipboard of your desktop environment (DE), you may think, that it’s some global buffer. But it’s not it works inside DE. For example, come terminal utils use their own buffers – vim has its own buffers for working inside the editor. But we have commands which you can use to copyContinue Reading
Matrix and rainbow for your terminal
This is not useful commands, but they are funny. Can we do silly things sometimes? Let’s start from coloring our terminal (you can read how it works here: “How to highlight your output in Bash“). We’ll use util: lolcat Concatenate FILE(s), or standard input, to standard output. With no FILE, or when FILE is -,Continue Reading
How to count words with grep
Grep command in Unix/Linux is the short form of ‘global search for the regular expression’. The grep command is a filter that is used to search for lines matching a specified pattern and print the matching lines to standard output. Piping to wc util is slow: ~ $ time grep and tmp/a/longfile.txt | wc -l2811real 0m0.097s userContinue Reading
How to backup all databases in MySQL / MariaDB
MySQL is an open source relational database management system. MariaDB is a fork of MySQL. Backup all databases to a local file: mysqldump –all-database -uroot -p > backup.sql Since the dump files are just SQL commands, you can restore the database backup to a file. And execute them by telling mysql to run the commandsContinue Reading
How to mount a remote directory to a local file system
SSH (Secure Shell) is a protocol to providing an encrypted channel for logging into another computer over a network and work there. First of all we need to install sshfs (see also “How to transfer a file from local path to SSH server“). SSHFS (SSH Filesystem) is a filesystem client to mount and interact with directoriesContinue Reading
How to use Let’s Encrypt for NGINX on Ubuntu
Let’s Encrypt is an SSL certificate authority managed by the Internet Security Research Group. Web server NGINX is a free, open-source, high-performance HTTP server. You can use HTTPS (an extension of HTTP with SSL / TLS encryption) on your website to secure connection. Install packages: apt updateapt install -y \ python-software-properties software-properties-common add-apt-repository ppa:certbot/certbot apt update aptContinue Reading
How to count number of files in directory (Bash)
This recipe based on ls output format. When you list a directory, you see file types in the first column. “-” – for a plain file, “d” is for a directory. You can learn more about files in Unix in this article: “File and directory permissions in Linux / FreeBSD / MasOS“. Also we useContinue Reading
How to show today’s files only in Linux
ls command has many abilities. Mostly we use it to show a list of files in current directory. We can even define style for output. For example ls -al –time-style=+%D – shows to us same ls -la list of files, but time column will be in different format. So, if we grep it by timeContinue Reading