Lateo.net - Flux RSS en pagaille (pour en ajouter : @ moi)

🔒
❌ À propos de FreshRSS
Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hiernixCraft

How to get and extract filename extension in Bash

Par : Vivek Gite
See all GNU/Linux related FAQ

I have a valuable tip for you on extracting the filename and extension in Bash when using Linux, macOS, FreeBSD, or Unix-like systems. It's quick and easy to follow.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to get and extract filename extension in Bash appeared first on nixCraft.

How to check for ssh connectivity in a shell script

Par : Vivek Gite
See all UNIX related articles/faq

Let us see how to check for ssh connectivity in a shell script running under macOS, FreeBSD, or Linux/Unix desktop using BatchMode=yes and ConnectTimeout=$VALUE options. This simple trick helps write a wrapper script that does other things, such as making a backup or running external command agents such as Salt or Ansible to do other tasks.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to check for ssh connectivity in a shell script appeared first on nixCraft.

Bash see if an input number is an integer or not

Par : Vivek Gite
See all Bash/Shell scripting related FAQ

While working on the bash shell script wrapper, I needed to ensure that I only passed an integer in the Bash script under Linux and Unix-like systems. Here is how to check if a number is an integer in Bash Linux or Unix script or at the command-line interface (CLI)

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post Bash see if an input number is an integer or not appeared first on nixCraft.

How to convert JSON to CSV using Linux / Unix shell

Par : Vivek Gite
See all Bash/Shell scripting related FAQ

Today I will talk about a common problem faced by many Linux or Unix sysadmins and developers. Typically modern apps and security devices heavily depend upon APIs and lists that feed data in JSON format. For example, a list of spamming or VPN CIDRs or a good list of verified bots' IP CIDRs is in JSON format. If they accept JSON format, you can take this list and upload it to your router or WAF. Unfortunately, not all devices accept JSON format. Hence, we can take JSON format and convert it to CSV format per our needs.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to convert JSON to CSV using Linux / Unix shell appeared first on nixCraft.

How to trim leading and trailing white space in bash

Par : Vivek Gite
See all GNU/Linux related FAQ

So I have this specific use case where I get data in a comma-separated values (CSV) file. I pick up the company name, address, telephone, email, and some other data from that file. Once data is collected, I create a final pdf using a simple script. Unfortunately, data comes with unwanted leading and trailing white spaces in each field. So my final pdf file gets messed up because of those white space. Let us see how to trim leading and trailing white space for a string in Bash running on Linux or Unix machines.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to trim leading and trailing white space in bash appeared first on nixCraft.

How to find and replace ALL IP addresses with a new one

Par : Vivek Gite
See all GNU/Linux related FAQ

At a certain point, I needed to change the VLAN IP address such as 172.0.0.2 with 172.0.0.1 for ease of use. As you know, Linux and Unix-like operating system stores all IP addresses and config in plain text files. This page explains my little adventure where I had to find and find and replace ALL IP addresses with a new one on Linux.

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to find and replace ALL IP addresses with a new one appeared first on nixCraft.

How to repeat a character ‘n’ times in Bash

Par : Vivek Gite
See all UNIX related articles/faq

Let us say you want to repeat a character such as '-' OR '=' multiple times while writing bash script. Please note that I needed a quick script to work on Linux, macOS, and FreeBSD server to repeat a string/character n times. One simple way to to repeat a string or character n times is simple use the echo command/printf command as follows:

echo '------------------------------------'
printf '%s\n' '------------------------------------'

Love this? sudo share_on: Twitter - Facebook - LinkedIn - Whatsapp - Reddit

The post How to repeat a character ‘n’ times in Bash appeared first on nixCraft.

How to check if file does not exist in Bash

Par : Vivek Gite
See all GNU/Linux related FAQ

How can I check if a file does not exist in a Bash script?

The post How to check if file does not exist in Bash appeared first on nixCraft.

How to check if bash variable defined in script

Par : Vivek Gite

I need to set a bash environment variable called PURGEIMAGE and take specific actions in my script. For example, if PURGEIMAGE set, then purge images from CDN else just URL. I am going to call my script as PURGEIMAGE=yes ./purgecache.sh url1 url2. So how do I know if a bash variable set at the CLI and used in my bash script running on Linux or Unix-like systems?

The post How to check if bash variable defined in script appeared first on nixCraft.

How to force awk not to print a newline

Par : Vivek Gite

I have two columns (fields) in my text file. I am trying to insert '|
FOO This is a description
BAR Another description for bar
TEXT Another description for TEXT

So I ran awk '{ print $1 "|"; $1=""; print}' input > output but print command is adding a new line:
FOO|
This is a description
BAR|
Another description for bar
TEXT|
Another description for TEXT

Is there any way to tell awk not to print a newline and create the file? Here is what I want so that I can create final HTML table based upon '|'
FOO|This is a description
BAR|Another description for bar
TEXT|Another description for TEXT

The post How to force awk not to print a newline appeared first on nixCraft.

How to install ShellCheck on FreeBSD – A shell script static analysis tool

Par : Vivek Gite

shellcheck demo on FreeBSD

ShellCheck is easy to use, free, and open-source static analysis tool that automatically finds bugs in your shell scripts. If you write shell scripts for automation or containers, you need this tool. Let us see how to install and use ShellCheck on the FreeBSD development Unix server.

The post How to install ShellCheck on FreeBSD – A shell script static analysis tool appeared first on nixCraft.

How to declare Boolean variables in bash and use them in a shell script

Par : Vivek Gite

I need to define a bash variable called failed and set the value to False. When my script is called from a cron job, specific tasks might fail, and then I need to flip failed to True. Based upon $failed, I need to send an email alert that my cron job has failed. So how can I declare and use Boolean variables in a shell script running on a Linux server?

The post How to declare Boolean variables in bash and use them in a shell script appeared first on nixCraft.

How to convert pdf to image on Linux command line

Par : Vivek Gite

I have many PDF files, and I need to convert them to a png file format, add a border to those images, and convert back all those images to pdf format. How can I convert pdf to image format on Linux and vice versa using the CLI?

The post How to convert pdf to image on Linux command line appeared first on nixCraft.

How to check TLS/SSL certificate expiration date from command-line

Par : Vivek Gite

How do I check the TLS/SSL certificate expiration date from my Linux or Unix shell prompt? How can I find the TLS certificate expiry date from Linux and Unix shell scripts?

The post How to check TLS/SSL certificate expiration date from command-line appeared first on nixCraft.

How to write the output into the file in Linux

Par : Vivek Gite

How do I write the output into the file in Linux bash shell? Can you explain I/O redirection for both bash and POSIX shell to write data to the file under Unix or Linux?

The post How to write the output into the file in Linux appeared first on nixCraft.

How to add days to date and get new date on Linux

Par : Vivek Gite

I brought eggs from the market, and it says best before 20 days from the date of packing. Say my egg box was packed on 29/July/2020. How do I add days to date using Linux CLI? I want to find out date 29/July/2020 + 20days using the CLI, and how do I do it?

The post How to add days to date and get new date on Linux appeared first on nixCraft.

Curl Shell Script To Purge Cache From Stackpath CDN

Par : Vivek Gite
A content delivery network or content distribution network (CDN) is a system of servers containing copies of data, placed at various points in a network so as to maximize bandwidth for access to the data from clients throughout the network. Please note that the following script will only work with Stackpath CDN. You need to get API access keys using stackpath portal.

How to find ulimit for user on Linux

Par : Vivek Gite

How can I find the correct ulimit values for a user account or process on Linux systems?

The post How to find ulimit for user on Linux appeared first on nixCraft.

How to extract tar.xz files in Linux and unzip all files

Par : Vivek Gite


How do I extract tar.xz files in Linux? Can you tell me command to unzip linux-5.6.13.tar.xz file? How can I uncompressing (or decompressing) all files in the current directory?

The post How to extract tar.xz files in Linux and unzip all files appeared first on nixCraft.

Nginx restore real IP address when behind a reverse proxy

Par : Vivek Gite

Nginx restore real IP address when nginx server is behind a reverse proxy

My Nginx web server is behind a reverse proxy server. How do I restore the original and real IP address of my client/visitors when behind a reverse proxy server such as AWS Cloudfront, Fastly, Cloudflare CDN/WAF?

The post Nginx restore real IP address when behind a reverse proxy appeared first on nixCraft.

How to sed remove last character from each line

Par : Vivek Gite

I need to remove the last character from a line and shell variable such as "${_allowed_ips}". For example, each line is as follows in my file:
foo,
bar,
demo,

I need output as follows:
foo
bar
demo
.
How can I use sed to delete the last character?

The post How to sed remove last character from each line appeared first on nixCraft.

How to save terminal output to a file under Linux/Unix

Par : Vivek Gite

How do I save the terminal output to a file when using BASH/KSH/CSH/TCSH under Linux, macOS, *BSD or Unix-like operating systems?

The post How to save terminal output to a file under Linux/Unix appeared first on nixCraft.

Linux Quiz

Par : Vivek Gite

Let us test your basic knowledge of Linux systems, including commands.

The post Linux Quiz appeared first on nixCraft.

Explain DEBIAN_FRONTEND apt-get variable for Ubuntu / Debian

Par : Vivek Gite

Can you explain DEBIAN_FRONTEND apt or apt-get variable? How and why I need to use this in Docker or shell scripts under a Debian and Ubuntu Linux?

The post Explain DEBIAN_FRONTEND apt-get variable for Ubuntu / Debian appeared first on nixCraft.

How to add bash auto completion in CentOS 8 Linux

Par : Vivek Gite

I set up a new cloud server, but my auto-completion of bash shell commands are not working. How do I enable autocomplete feature in CentOS 8 (CentOS Enterprise Linux 8)? How do I write simple bash completion code in CentOS 8?

The post How to add bash auto completion in CentOS 8 Linux appeared first on nixCraft.

Linux shell script to reduce PDF file size

Par : Vivek Gite
Here is a handy and useful Linux and Unix shell script that reduce PDF file size using Ghostscript. No need to upload your PDF file to the shady third-party website. Just do it from the terminal. I tested it with both CentOS and Ubuntu/Debian Linux.

How to return pid of a last command in Linux / Unix

Par : Vivek Gite

I need to find and return the PID of the last command executed in Linux. How do I return the PID of command in Linux?

The post How to return pid of a last command in Linux / Unix appeared first on nixCraft.

Bash get filename from given path on Linux or Unix

Par : Vivek Gite

How do I extract filename and extension in the Bash shell script from the given path? How can I get filename from the path under the bash shell?

The post Bash get filename from given path on Linux or Unix appeared first on nixCraft.

How to find a website’s DNS (name server) address

Par : Vivek Gite

How can I find a website's DNS address? How do I check the current DNS servers of a domain or website using a Linux or macOS command line option? How do I find DNS address of a website using bash?

The post How to find a website’s DNS (name server) address appeared first on nixCraft.

How to find Public IP address AWS EC2 or Lightsail VM

Par : Vivek Gite

I need to get public IPv4 address on current EC2 or Lightsail VM Linux/Unix instance. How do I find Public IP address AWS EC2 or Lightsail VM?

The post How to find Public IP address AWS EC2 or Lightsail VM appeared first on nixCraft.

Change default shell to bash on Macos Catalina

Par : Vivek Gite

I noticed that my default shell set to zsh on Macos Catalina. How do I change my default shell to bash on Macos Catalina using the command line or GUI options?

The post Change default shell to bash on Macos Catalina appeared first on nixCraft.

Linux run a command with a time limit (timeout)

Par : Vivek Gite

I want to start command called foo, and kill it if still running after given DURATION in seconds. How do I run a command a time Limit on Linux? How do I run a Linux command, and have it timeout (abort) after N seconds?

The post Linux run a command with a time limit (timeout) appeared first on nixCraft.

How do I force delete a directory in Linux?

Par : Vivek Gite

I am trying to delete a directory in Linux using the rmdir dir1 command. But, I am getting an error that read as follows:
rmdir: failed to remove `dir1': Directory not empty
How do I force remove and delete a directory in Linux?

The post How do I force delete a directory in Linux? appeared first on nixCraft.

Check if a directory exists in Linux or Unix shell

Par : Vivek Gite

I need to check if a directory exists or not, within a shell script running on Linux or Unix-like system? How do I check if a directory exists in a shell script?

The post Check if a directory exists in Linux or Unix shell appeared first on nixCraft.

How to rename multiple folders in Linux using command line

Par : Vivek Gite

I am new to Linux programming and bash shell commands. I have a folder structure as dir1, dir2, dir3 and I would like to rename it as dir001, dir002, dir003. How do you rename multiple folders in Linux?

The post How to rename multiple folders in Linux using command line appeared first on nixCraft.

How to find Intel NUC BIOS version and model on Linux

Par : Vivek Gite

I installed Linux on Intel NUC. I need to find Intel NUC BIOS version. How do I find out BIOS version, date, and model name of my Intel NUC using Linux command-line options?

The post How to find Intel NUC BIOS version and model on Linux appeared first on nixCraft.

How to hide files and directories in Linux

Par : Vivek Gite

I am a new Linux user. How do I hide files and directories in Linux operating systems using the command line interface?

The post How to hide files and directories in Linux appeared first on nixCraft.

Bash check if string starts with character such as #

Par : Vivek Gite

My bash shell script read a config file line-by-line using a bash while loop. I need to check if a string stored in $var starts with some value such as # character. If so I need to ignore that value and read the next line from my config file. How do I check if variable begins with # in bash shell scripting running on a Linux or Unix-like operating systems?

The post Bash check if string starts with character such as # appeared first on nixCraft.

Bash get exit code of command on a Linux / Unix

Par : Vivek Gite

I am a new Linux system user. How do I get the exit code of a command? How do I get the exit code of Linux or Unix shell command and store it into a shell variable?

The post Bash get exit code of command on a Linux / Unix appeared first on nixCraft.

Bash read file names from a text file and take action

Par : Vivek Gite

I need to read a list of file names from a text file named input.txt and take action each file name. How do I read file names from a text file and say run /bin/foo command on each file? How do I read filenames from a text file and take certain action on those files?

The post Bash read file names from a text file and take action appeared first on nixCraft.

How to add bash auto completion in RHEL 8 (Red Hat Linux)

Par : Vivek Gite

I set up a new RHEL 8 VM from cloud images, but my auto-completion of bash shell commands are not working. How do I enable autocomplete feature in RHEL 8 (Red Hat Enterprise Linux 8)? How do I write simple bash completion code in RHEL 8?

The post How to add bash auto completion in RHEL 8 (Red Hat Linux) appeared first on nixCraft.

❌