#2166
[Bash] How-To
Create a tar.gz file for each file :
for i in *.dbf; do tar -czf $i.tar.gz $i; done
Add datetime in bash history :
echo 'export HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bash_profile
To replace the first occurrence of a pattern with a given string, use ${parameter/pattern/string}:
#!/bin/bash firstString="I love Suzi and Marry" secondString="Sara" echo "${firstString/Suzi/$secondString}" # prints 'I love Sara and Marry'
To replace all occurrences, use ${parameter//pattern/string}:
message='The secret code is 12345' echo "${message//[0-9]/X}" # prints 'The secret code is XXXXX'
Show path in bash prompt
Add following line in .bashrc
export PS1="\\u@\\h:\\w\\$ "
Check keyboard input and call associated function:
Script used to ask confirmation before stopping a tomcat instance.
Information like reason, username, datetime are stored in a logfile.
#!/bin/bash function stopApp(){ read -p "You are requesting a stop of the application, thanks to provide an explanation : " explanation echo `date` "- $USER - " `who am i | awk '{print $1}'` " - Stoping Tomcat... (Reason : $explanation)" >> log.log ./shutdown.sh } while true; do read -p "Do you want to stop the application ? (Y/N) : " yn case $yn in [Yy]* ) stopApp; break;; [Nn]* ) exit;; * ) echo "Please answer yes or no.";; esac done
trim leading and trailing whitespace :
awk '{$1=$1};1' #Eaxmple : ip a | grep inet | grep -v "127.0.0.1" | grep -v "inet6" | awk '{$1=$1};1'
Setup FileZilla Server Passive Ports on Windows Server 2012 — (B)logs of Johan Dörper Using Zabbix API for Custom Reports – Arturo Baldo
Zip a folder :
Check free inodes :
This will take time, but can locate the directory with the most files
Retry function :
Check Defunct process :
Kill defunct process (based on parend ID)
Substring by index (1-based)
Uppercase :
Lowercase:
Browse subdir
Array :
Add element to an arrat
Loop on array
Print array
sed :
Remove duplicate from a file :
Test zip/jar integrity
see output of unattached process :
(tail is not working properly)
list all mount points:
log with color
Yellow
Using env variable in sed: