
$ STRING="username:homedir:shell"
$ echo "$STRING"|cut -d ":" -f 3
shell
$ echo "${STRING##*:}"
shell$ cat test.sh
#!/usr/bin/env bash
STRING="Name:Date:Shell"
echo "using cut"
time for A in {1..1000}
do
  cut -d ":" -f 3 > /dev/null <<<"$STRING"
done
echo "using ##"
time for A in {1..1000}
do
 echo "${STRING##*:}" > /dev/null
done
$ ./test.sh
using cut
real    0m0.950s
user    0m0.012s
sys     0m0.232s
using ##
real    0m0.011s
user    0m0.008s
sys     0m0.004s
$ cat test.sh
#!/usr/bin/env bash
echo "using cut"
time for count in {1..1000}
do
  cut -d ":" -f 7 </etc/passwd > /dev/null
done
echo "using ##"
time for count in {1..1000}
do
  while read
  do
    echo "${REPLY##*:}" > /dev/null
  done </etc/passwd
done
$ ./test.sh
$ ./test.sh
using cut
real    0m0.827s
user    0m0.004s
sys     0m0.208s
using ##
real    0m0.613s
user    0m0.436s
sys     0m0.172s
$ VAR="myClassName = helloClass"
$ echo ${VAR##*= }
helloClass
$ VAR="Hello my friend (enemy)"
$ TEMP="${VAR##*\(}"
$ echo "${TEMP%\)}"
enemy
$ alias TAsteriskLog="tail -f /var/log/asteriks.log"
$ alias TMailLog="tail -f /var/log/mail.log"
$ TA[tab]steriksLog
$ TM[tab]ailLogfunction LastLogin {
  STRING=$(last | head -n 1 | tr -s " " " ")
  USER=$(echo "$STRING"|cut -d " " -f 1)
  IP=$(echo "$STRING"|cut -d " " -f 3)
  SHELL=$( grep "$USER" /etc/passwd | cut -d ":" -f 7)
  echo "User: $USER, IP: $IP, SHELL=$SHELL"
}$ L[tab]astLogin
User: saboteur, IP: 10.0.2.2, SHELL=/bin/bash$ echo "hello"
hello
$ history 2
 2011  echo "hello"
 2012  history 2
$  echo "my password secretmegakey"
my password secretmegakey
$ history 2
 2011  echo "hello"
 2012  history 2secret.sh
PASSWORD=LOVESEXGOD
myapp.sh
. ~/secret.sh
sqlplus -l user/"$PASSWORD"@database:port/sid @mysqfile.sql$ echo "secretpassword" > secret.key; chmod 600 secret.key$ echo "string_to_encrypt" | openssl enc -pass file:secret.key -e -aes-256-cbc -a
U2FsdGVkX194R0GmFKCL/krYCugS655yLhf8aQyKNcUnBs30AE5lHN5MXPjjSFML$ echo 'U2FsdGVkX194R0GmFKCL/krYCugS655yLhf8aQyKNcUnBs30AE5lHN5MXPjjSFML' | openssl enc -pass file:secret.key -d -aes-256-cbc -a
string_to_encrypttail -f application.log | grep -i errortail -f application.log | grep -i -P "(error|warning|failure)"tail -f application.log | grep -v -i "info"> application.logtruncate --size=1M application.logecho "$(tail -n 1000 application.log)" > application.logwatch <>for srv in 1 2 3; do echo "server${srv}";done
server1
server2
server3for srv in server{1..3}; do echo "$srv";done
server1
server2
server3for srv in $(seq -w 1 10); do echo "server${srv}";done
server01
server02
server03
server04
server05
server06
server07
server08
server09
server10for file in *.txt; do name=$(basename "$file" .txt);mv $name{.txt,.lst}; donefor file in *.txt; do mv ${file%.txt}{.txt,.lst}; donemkdir -p project/src/{main,test}/{java,resources}project/
   !--- src/
        |--- main/
        |    |-- java/
        |    !-- resources/
        !--- test/
             |-- java/
             !-- resources/tail -f /var/logs/*.logalias TFapplog='tail -f --pid=$(cat /opt/app/tmp/app.pid) /opt/app/logs/app.log'dd if=/dev/zero of=out.txt bs=1M count=10fallocate -l 10M file.txt$ #    5 
for string in string{1..5}; do echo $string >> file.lst; done
$ cat file.lst
string1
string2
string3
string4
string5
saboteur@ubuntu:~$ cat file.lst | xargs -n 2
string1 string2
string3 string4
string5cat file | xargs -n 2 -P 3cat file | xargs -n 2 -P $(nproc)read -p "Press any key to continue " -n 1read -p "Press any key to continue (autocontinue in 30 seconds) " -t 30 -n 1REPLY=""
until [ "$REPLY" = "y" ]; do
  # executing some command
  read "Press 'y' to continue or 'n' to break, any other key to repeat this step" -n 1
  if [ "$REPLY" = 'n' ]; then exit 1; fi
done
Source: https://habr.com/ru/post/340544/
All Articles