- She bang line, location of shell
which bash
- Store arguments from bash in array
args=("$@")
- Number of arguments
count=("$#")
- Date
NOW=$(date +"%m-%d-%Y")
- Print a random file
files=(./*); printf "%s\n" "${files[RANDOM % ${#files[@]}]}"
- Create empty dir
[ -d "./data" ] && mkdir data || rm -rf ./data/*
Moves selected files
find $PWD -type f -not -name "*mp4" -not -name "*png" | xargs -I '{}' mv '{}' ~/Downloads/
rename -n "s/[\W]+/./g" my_File
ls | while read -r FILE
do
mv "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' \
| tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
done
Pad digits for string comparison, e.g. Chapter1.mp3 to Chapter01.mp3
rename -ne 's/\d+/sprintf("%02d",$&)/e' -- *.mp3
Strip simple xml file into element, value pairs.
cat warrant.xml | grep -o "<[[:alpha:]]*>" \
| sed "s/<//" | sed "s/>//" \
| awk '{print "String "$1" = \""$1"\";"}'
sudo chmod 755 /usr/local/lib
sudo chown -R $USER:admin /usr/local
** Find $PATH on remote host **
ssh rhost "echo \$PATH"
** Add ssh keys to remote host. **
cat ~/.ssh/id.pub | ssh rhost "cat >> ~/.ssh/authorized_keys"
** fdupes finding duplicate files, recursively. **
diff - b=ignore_space_change | r=recursive | q=quiet, only file name
fdupes -S -r /path/to/folder
fdupes -rdN dir/
diff -brq sr1 src2
echo file{1..4}.txt
Restarting a program in windows, if not already running.
tasklist /FI "IMAGENAME eq Tunnelier.exe" 2>NUL | find /I /N "Tunnelier.exe">NUL
if "%ERRORLEVEL%"=="0" (
echo Programm is running
) else (
start "D" "C:\Program Files\Bitvise Tunnelier\Tunnelier.exe" -loginOnStartup
)
- Set java version
sudo update-alternatives --config java
- Search for packages
apt search openjdk-11-jdk