📜 ⬆️ ⬇️

10 mini life hacks in Bash

1. To quickly copy / rename a file with a long name, you can type:

cp /home/user1/myfile123456789.txt{,-new} 

and back:

 cp /home/user1/myfile123456789.txt{-new,} 

2. Useless, but cool fork-bomb (although it will not work if you have set ulimit for the number of processes):
')
 :(){ :|:& };: 

3. Network printer emulator on local computer:

 nc -l -p 9100 > job.prn 

4. The simplest load testing website:

 for i in {1..1000}; do echo ya.ru; done | xargs -P 20 wget &>/dev/null 

5. Readable output of the mount command:

 mount | column -t 

6. SSH tunnel from local port 7777 to remote port 8888 on myserver.com server:

 ssh -fN user@myserver.com -L 7777:myserver.com:8888 

7. Print a random number from 0 to 32767:

 echo $RANDOM 

8. Execute commands from a text file in the console:

 source ./commands.txt 

9. Create a random password:

 openssl rand -base64 8 

10. Protection against simultaneous launch of multiple copies of the script:

 flock -n /tmp/lock.txt -c "/home/user1/test.sh > test.log" 

That's all for now, successful experiments on the command line!

Source: https://habr.com/ru/post/327194/


All Articles