Cockpit est une interface web d’administration pour Linux, maintenue par Red Hat et disponible dans Ubuntu : état du système, services systemd, journaux, stockage, réseau, comptes, mises à jour, terminal intégré. Avec le module cockpit-machines, on y ajoute la gestion des machines virtuelles KVM/libvirt : démarrage, console, snapshots.
Lire la suite…
Pour parcourir les dossiers du serveur depuis le Finder ou l’Explorateur de fichiers, sans client spécial, Samba (protocole SMB) est le standard. Ce tutoriel crée deux types de partages : un partage « d’administration » (pour vous) et un partage dédié à une application (sauvegardes d’une application, par exemple).
Lire la suite…
SearXNG est un métamoteur : il interroge à votre place Google, Bing, DuckDuckGo, Qwant, Wikipédia et des dizaines d’autres sources, puis vous renvoie les résultats agrégés sans cookie, sans profil et sans transmettre votre adresse IP aux moteurs. Hébergé chez vous, vous maîtrisez la configuration et les journaux.
Lire la suite…
How to check file size in unix using wc command
The wc command shows the number of lines, words, and bytes contained in file. The syntax is as follows to get the file size:
wc -c /path/to/file
wc -c /etc/passwd
Sample outputs:
5253 /etc/passwd
You can easily extract the first field either using the cut or awk command:
wc -c /etc/passwd | awk '{print $1}'
Sample outputs:
5253
OR assign this size to a bash variable:
myfilesize=$(wc -c "/etc/passwd" | awk '{print $1}')
printf "%d\n" $myfilesize
echo "$myfilesize"
|
How to get the size of a file in a bash script using stat command
The stat command shows information about the file. The syntax is as follows to get the file size on GNU/Linux stat:
stat -c %s "/etc/passwd"
OR
stat --format=%s "/etc/passwd"
To assign this size to a bash variable:
myfilesize=$(stat --format=%s "/etc/passwd")
echo "$myfilesize"
## or ##
myFileSizeCheck=$(stat -c %s "/etc/resolv.conf")
printf "My file size = %d\n" $myFileSizeCheck
|
The syntax is as follows to get the file size on BSD/MacOS stat:
stat -f %z "/etc/passwd"
Please note that if the file is symlink you will get size of that link only with the stat command.
du command example
The syntax is
du --apparent-size --block-size=1 "/etc/passwd"
fileName="/etc/hosts"
mfs=$(du --apparent-size --block-size=1 "$fileName" | awk '{ print $1}')
echo "$fileName size = ${mfs}"
|
Sample outputs from above commands:
Fig.01: How to check size of a file using a bash/ksh/zsh/sh/tcsh shell?
Find command example
The syntax is:
find "/etc/passwd" -printf "%s"
find "/etc/passwd" -printf "%s\n"
fileName="/etc/hosts"
mysize=$(find "$fileName" -printf "%s")
printf "File %s size = %d\n" $fileName $mysize
echo "${fileName} size is ${mysize} bytes."
|
How can I extract or fetch a domain name from a URL string (e.g. https://www.cyberciti.biz/index.php) using bash shell scripting under Linux or Unix-like operating system?
You can use standard Unix commands such as sed, awk, grep, Perl, Python and more to get domain name from URL. No need to write regex. It is pretty simple.
Let use see various commands and option to grab the domain part from given variable under Linux or Unix-like system.
Get domain name from full URL
Say your url name is stored in a bash shell variable such as $x:
x='https://www.dbsysnet.com/'
You can use the awk as follows:
echo "$x" | awk -F/ '{print $3}'
### OR ###
awk -F/ '{print $3}' <<<$x
Sample outputs:
www.dbsysnet.com
Extract domain name from URL using sed
Here is a sample sed command:
url="https://www.dbsysnet.com"
echo "$url" | sed -e 's|^[^/]*//||' -e 's|/.*$||'
Extract domain name from URL using bash shell parameter substitution
Another option is to use bash shell parameter substitution:
# My shell variable
f="https://www.cyberciti.biz/faq/copy-command/"
## Remove protocol part of url ##
f="${f#http://}"
f="${f#https://}"
f="${f#ftp://}"
f="${f#scp://}"
f="${f#scp://}"
f="${f#sftp://}"
## Remove username and/or username:password part of URL ##
f="${f#*:*@}"
f="${f#*@}"
## Remove rest of urls ##
f=${f%%/*}
## Show domain name only ##
echo "$f"
|
Shell script example
A shell script to purge urls from Cloudflare by matching domain name part:
#!/bin/bash
zone_id=""
api_key=""
urls="$@"
bon=$(tput bold)
boff=$(tput sgr0)
c=1
[ "$urls" == "" ] && { echo "Usage: $0 url"; exit 1; }
clear
echo "Purging..."
echo
for u in $urls
do
echo -n "${bon}${c}${boff}.${u}: "
## Get domain name ##
d="$(echo $u | awk -F/ '{ print $3}')"
## Set API_KEY, Email_ID, and ZONE_ID as per domain ##
case $d in
www.cyberciti.biz) zone_id="ID_1"; api_key="MY_KEY_1"; email_id="[email protected]";;
theos.in) zone_id="ID_2"; api_key="MY_KEY_2"; email_id="[email protected]";;
*) echo "Domain not configured."; continue;;
esac
## Do it ##
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/${zone_id}/purge_cache" \
-H "X-Auth-Email: ${email_id}" \
-H "X-Auth-Key: ${api_key}" \
-H "Content-Type: application/json" \
--data "{\"files\":[\"${u}\"]}"
echo
(( c++ ))
done
echo
|