Skip to main content

Posts

Showing posts from October, 2022

Find command: How to find and delete 0 bytes files in Linux

In Linux, "find" command is a powerful command that we can use not only to find files. I've used it for different requirements, so thought of posting some of the convenient usages of find commands in a series of posts. For some application issue, I've got one of my directories in Ubuntu system swarmed with empty files with 0 bytes. Some of the files got data in them but some of them were empty. I just wanted to delete the empty files and it wasn't possible to identify them by file names or dates. So find command comes to rescue. find . -size 0 -type f  If I needed to isolate the files by file extension, we can use something like this. find . -size 0 -type f -name "*.tar" You can get the file count by piping it to wc command. find . -size 0 -type f -name "*.tar" | wc -l The awesome thing about the find command is you can use it for deleting files just by adding the -delete flag to the command. find . -size 0 -type f -name "*.tar" -dele

First few commands to run on an unknown Linux server

 If you get to troubleshoot some unknown Linux server, running these few commands will be useful. 1. Check who's logged in w This is a cool one-letter command to see who else logged into the server. It will list the usernames and even you can find the IP and the connection type. In the following example, I've logged in as the "user". If you see, some other users, watch out for unauthorized access. 2. Identify the OS There are different commands to identify what kind of Linux distribution that you are dealing with. Knowing this is crucial to decide what commands to use later. cat /etc/os-release Usually, in Linux distributions, you have a file /etc/os-release . Basically, you can see everything you need to know about the OS in this file.  3. See running processes top This basically lists the processes running with the CPU and memory consumption. With this, we can get an idea about what kind of apps running on the server and if any of them uses too much CPU or memory. 4

Hosting a single page app with Nginx without 404 errors

 If you write a single-page app where the routing is handled on its own, it works perfectly on your local host with the dev server. For an instance, if there is a route in your app for login such as "/login", if you try this in the localhost it will work without any issues.  If you host this with an Nginx server as a static web app, using the direct route in the URL will end up with 404. There is an easy fix for this updating the Nginx configurations.  Nginx default static site configuration is located in " /etc/nginx/conf.d/default.conf ". This may differ based on your installation and OS. However, the configurations are pretty much the same. You can add the following line to the configuration  try_files $uri $uri/ /index.html?q= $uri&$args ; This makes the Nginx look for files in the file path, and if found then serve it. Or else, route the request to the index.html.  In our example, it will look for a file called login in the static directory, since we don