Skip to main content

Posts

Showing posts with the label Bash Linux Noob

Linux find empty directories and files

 How to find or identify empty directories or files in Linux? It can be done easily with find command itself. Here's the syntax and how to test. mkdir test_empty cd test_empty create some dummy directories: mkdir {dummydir1,dummydir2,dummydir3} then create some empty files: touch {file1empty,file2empty,file3empty} To find empty directories: find . -type d -empty To find empty files: find . -type f -empty All directories and files will be shown since they are empty. Add some text to the file: echo "Test" > file1empty Run again the command: find . -type f -empty file1empty will not be on the list since the file has some text. Move the file1empty to dummydir1. mv file1empty dummydir1 Run the command to find empty directories: find . -type d -empty dummydir1 will not be displayed since file1empty is inside of it. How to remove or delete empty directories or files? In production or any environment, make sure you know what you are doing. In a testing environment, it can be d...

Linux find up interfaces

If a Linux box VM, WSL or a physical server is unable to connect to Network, one possible issue is the network interface is not UP. Typing:   ip address show   Or:   ip a s  The output will show which interfaces are UP. If the output shows like:  eth0: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 UP after multicast means that the interface is not disabled on the OS or administratively enabled LOWER_UP means that a cable is connected  and is able and is able to find an active switch port  Running this command below: tcpdump -D The output will also show that the interface is Up, Running and connected. Example: 1. eth0 [Up, Running, Connected] Basic commands that will help to save the day if ever there is some network or connectivity issues. zenity, dialog, can also be used to generate GUI boxes. However, whiptail still the best for minimal footprint and might come as a default for Server Distros OS. That's...

HAProxy cannot bind port not listening

HAProxy is an open-software used as a high-performance load balancer and reverse proxy for TCP. To check whether the proxy config before reloading or restarting the HAProxy service can be done via this command:  haproxy -c -f /etc/haproxy/haproxy.cfg It will show 'configuration file is valid' if everything is okay or the config file syntax is valid. However, the command cannot check whether it can bind the port, or bind the socket. Example, typing: systemctl reload haproxy to reload the new config file. And to check whether the reload is successful or not status of the service can be checked. Typing, systemctl status haproxy to check the status and if it shows Reload: failed then binding issues or other errors causes reloading to fail. Or some alert is shown as Binding like /etc/haproxy/haproxy.cfg cannot bind socket or cannot assign requested address for 192.168.x.x. IP Technically, the error is already giving some hints that the IP on the HAProxy config file cannot be used fo...

PowerShell/Bash Linux get MAC address

Example of PowerShell get MAC address: getmac /s 127.0.0.1 | findstr /I TCPIP Sample output: C4-75-CB-37-BB-BF \Device\Tcpip_{7F29EDBA-C045-4C74-834E-F026BCE8169B} For Linux: ip a | grep -i "link/ether" | awk '{print $1, $2}' Sample output: link/ether 00:15:5d:98:16:36 That's it a quick way, to find MAC address. Ideal for network switch troubleshooting. Pray, hope and don't worry. Always Be Still, God is always in control. Consult God by praying.

Newly built Linux box cannot SSH

Fully functional and brand new built VM, Physical server, Container or any boxes with Linux distro, however, SSH is not working. Newly built Linux boxes with Server OS, the SSH service or remote access to the box won't start functioning even though the server is up and running. For the SSH to start it needs to have the required SSH keys for the service to start. The solution is to run this command: ssh-keygen -A After typing the command, try systemctl start ssh or systemctl start sahd Also check the status by: systemctl status ssh / systemctl status sshd And also good idea to start SSH once the system is restarted. Type: systemctl enable ssh / systemctl enable sshd Once the service or status of the SSH is confirmed running, then the system or device can connect remotely or other devices can connect to the local system as well. That's it, till next time. Enjoy exploring the Linux World! Prayer connect us to God, line is never congested! Have Faith and Trust Jesus, He always do g...