ITT you can share your favourite shell scripts.
I run this once a week via crontab to save some disk space on my old laptop:#!/bin/bash
for EBOOK in /home/user/Documents/ebook/*.pdf
do
gzip --best "$EBOOK"
done
>>54319944#!/bin/bash
tar -xvf /home/peterk/
>>54319963
Would fail the tar f parameter requires the output filename first then folder
#!/bin/bash
sudo rm -rf /
>>54319944
I use this over df -h because i think its cleaner#!/bin/bash
df -h | awk '{print $5 "\t" $3 "/" $4 "\t- " $1}' | grep -v tmpfs
alias apt="sudo apt"
alias apt-get="sudo apt"
>>54319944
>>54319963
>>54320446
>#!/bin/bash
All these work in sh. No bash needed. Also if you want to use bash use #!/usr/bin/env bash.
>>54320431
Retard detected. Everyone knows that rm will just throw out an error, except ofc tech illiterates.
trash() {
str="INTO THE TRASH IT GOES … "
for i in $(seq 0 ${#str}); do
printf '\033[48;5;202m%s\033[m' "${str:$i:1}"
sleep .02
done
printf '\n'
mv -vt "$HOME/.local/share/Trash/files/" "$@"
}
>>54321622
>trash()
Cool, I did not know that it is possible to make functions with shell script.
>>54320431
` ` `
rm: it is dangerous to operate recursively on '/'
rm: use --no-preserve-root to override this failsafe
` ` `
>>54323968
You can save it into your ~/.bashrc, restart terminal and the command trash is available.
>>54321581
Does
>#!/usr/bin/env bash
has any advantages over
>#!/usr/bin/bash
?
>>54324945
On OSX, the bash binary included is an old version. Users can install their own version of bash if they choose to.
>>54324945
env searches for bash first and executes the first entry. that makes your script more portable, since on some systems, bash isn't in bin.
>>54324077
Or don't restart terminal and just run source ~/.bashrc