Skip to main content

Posts

Linux vim/vi switch from 1st line to the last line

Recent posts

How to move files in Linux using ls?

Moving files to organize or to simply archive is part of a sysadmin life. In Linux, ls -1 (number one not small letter L) command means list the files but only show the filenames. The output of ls -1 can be utilized as an input to mv to move the files, since mv requires a filename to be move plus a destination where to move the files. Here's a simple command to do it with a few parameters of course:          ls -1 | xargs -d '\n' -I {} mv -- {} /path/to/destination/ Above move whatever files it can find on the path; where the command is run and it's a command that will also move files even though it has space or tab on the filename of the files. Below is a revised command to move all .txt files on the current directory or on the path where the command is executed.          ls -1 *.txt | xargs -d '\n' -I {} mv -- {} ./archive_folder/ The mv --, the -- is a safety precaution or a mechanism in order not to misinterpret any filenames wi...

Linux Top check a single process

Monitor a single process in Linux, to check if the process is the culprit,.or just simply monitor the resources consume by the process in real time. This can be done easily using Linux, top and pgrep commands Example: Check MySQL daemon. Open terminal and type this:    top -p $(pgrep -f mysqld )  It will display top with only mysqld displayed on the screen. That's it you can monitor the process, observe what it's doing. Till next time, enjoy exploring the command line, Happy Linuxing... Prayer is free, brings comfort to your life. Trust Jesus He will guide you to righteousness. https://soulrefresh.netlify.app

Linux quickly check MAC or IP

How to view or check MAC address or IP address in Linux VM or Server? On the the Terminal or CLI, to view MAC address: Type: ip -4 neigh show  This will show all IPV4 addresses plus the MAC address linked to the IP and will also show the status whether it's Reachable or Stale. Or just simple type: ip neigh The legacy command is: arp -an To check for IP via CLi, one way is to type: ip r It will show the IP and whether there is an assigned gateway. To view all IP addresses assigned to an interface is to type: ip addr show Checking MAC addresses is quite important especially if there's some network flapping issues, since MAC address is at Layer 2 on the OSI model, if it's not working properly then all other layers will be affected. Of course, IP is also important or else it can't connect to the network, or reach the internet That's it till next time. Keep learning. Always Pray no matter what circumstances is happening in your life, being connected to Jesus all the time...

View files in Linux from old to latest aka chronological order

Viewing files in Linux terminal from old to latest, is one of the common tasks a Linux sysadmin will do. And this can be done simply with the good ls command. Plus add a few parameters to make the output more readable and friendly. ls -lhtra this command will view all the files, hidden or not hidden from old to latest Example image below, shows all files; arrange in chronological order. ls -1  the command is ls - plus the number one not the small letter "L"; this is quite useful if need to get the filenames only on a specific directory and feed to xargs command or as an input on any bash script for further processing. Example, typing ls - 1 will output only the filenames on a specific directory. That's it till next time. Enjoy Linux and keep learning. Keep praying and stay open to God's messages. Fiat Voluntas Tua | Catholic Prayers & Quotes

Viewing files with line numbers in Linux terminal

 Reading files is basic and a must when working on the terminal in Linux or command line. There are a lot of ways to do this, a simple task but quite a few ways to accomplish it. Nano, vi/vim the most common editor in Linux that is part of the package in most Linux flavors if not all. In nano editor, while the file is open pressing "alt + n", will display the line numbering on the left side of the screen. Example image: In vi or vim, opening the file and typing the command: "set nu" or "set number" will also view the lines on the left side of the screen. Example image:   Or from the command line itself using "cat -n any_file_name.txt" will also view line numbers the -n is a parameter on cat to view or include the line numbers when displaying the file. Example image: less -N, command will also produce same result. Or just use nl , "man nl" shows:  NAME        nl - number lines of files It comes pre-installed in almost any Linux flavors,...

Display GUI Boxes for Linux bash script

 Displaying GUI Boxes in Linux Bash scripts can be done easily using whiptail. In Windows OS, msgbox, inptubox is quite helpful on VBA, Visual Basic and even in .NET world. Displaying Graphical boxes in Linux bash scripting is quite simple to do. To navigate on this GUI boxes, used "Tabs","Arrow Keys" and "Space Bar" as enter key. Here's a simple example of Whiptail that display GUI Boxes and ping the sites that are selected. #!/bin/bash # Step 1: Checkbox URL menu CHOICES=$(whiptail --title "Checkbox Ping URLs Example" \   --checklist "Select one or more options:" 15 50 5 \   "ping -c 2 bing.com;" "Ping bing" OFF \   "ping -c 2 duckduckgo.com;" "Ping ddg" OFF \   "ping -c 2 search.com;" "Ping search" OFF \   "ping -c 2 google.com" "Ping google" OFF \   3>&1 1>&2 2>&3) # Exit gracefully if nothing was selected or user pressed Cancel ...

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...