Skip to content

Commit

Permalink
SO: Add missing files
Browse files Browse the repository at this point in the history
  • Loading branch information
JCapucho committed Dec 10, 2024
1 parent 727b85e commit 98143d0
Show file tree
Hide file tree
Showing 124 changed files with 5,428 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 2ano1/SO/aula02/aula02e01-v2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Este é o meu primeiro script
msg="O meu segundo script em bash!"
echo msg
4 changes: 4 additions & 0 deletions 2ano1/SO/aula02/aula02e01.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Este é o meu primeiro script
msg="O meu primeiro script em bash!"
echo $msg
4 changes: 4 additions & 0 deletions 2ano1/SO/aula02/aula02e02.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Atenção aos espaços
echo Este e um teste
echo "Este e um teste"
7 changes: 7 additions & 0 deletions 2ano1/SO/aula02/aula02e03.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env -S bash -i
# O comando type permite saber o tipo de um comando
type rm
type cd
type for
type ll
type dequote
18 changes: 18 additions & 0 deletions 2ano1/SO/aula02/aula02e04-b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
echo "Todos os items em /etc:"
find /etc -maxdepth 1 -printf "%f\n"

printf "\n"

echo "Começam por a:"
find /etc -maxdepth 1 -name "a*" -printf "%f\n"

printf "\n"

echo "Começam por a e têm mais que 3 caracteres":
find /etc -maxdepth 1 -regextype egrep -regex ".*/a.{3,}" -printf "%f\n"

printf "\n"

echo "Contêm conf no nome":
find /etc -maxdepth 1 -name "*conf*" -printf "%f\n"
6 changes: 6 additions & 0 deletions 2ano1/SO/aula02/aula02e04.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env -S bash
echo "O meu editor por omissão BASH $BASH \$BASH"
echo 'O meu editor por omissão BASH $BASH \$BASH'
echo $(( 5 + 5 ))
(( 5 > 0 )) && echo "cinco é maior do que zero"
today=$(date); echo $today
6 changes: 6 additions & 0 deletions 2ano1/SO/aula02/aula02e05.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "$#"
echo "Arg 1: $1"
echo "Arg 2: $2"
echo "$*"
echo "$@"
12 changes: 12 additions & 0 deletions 2ano1/SO/aula02/aula02e05d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
echo using '$*:' $*
for i in $*; do echo "$i"; done

echo using '$@:' $@
for i in $@; do echo "$i"; done

echo using '"$*":' "$*"
for i in "$*"; do echo "$i"; done

echo using '"$@":' "$@"
for i in "$@"; do echo "$i"; done
6 changes: 6 additions & 0 deletions 2ano1/SO/aula02/aula02e06.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Parameter Expansion
file="$HOME/.bashrc"
echo "File path: $file"
echo "File name: ${file##*/}"
echo "Directory name: ${file%/*}"
4 changes: 4 additions & 0 deletions 2ano1/SO/aula02/aula02e07.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# Brace Expansion
echo {1..9}
echo {0,1}{0..9}
6 changes: 6 additions & 0 deletions 2ano1/SO/aula02/aula02e08.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Exit status
ping -c 1 www.ua.pt
echo "Exit code: $?" # $? gives exit code of last process
ping -c 1 wwwww.ua.pt
echo "Exit code: $?"
4 changes: 4 additions & 0 deletions 2ano1/SO/aula02/aula02e09.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
mkdir d && cd d && pwd
echo "----------------"
pwd && rm xpto || echo "I couldn't remove the file"
2 changes: 2 additions & 0 deletions 2ano1/SO/aula02/c10param.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
touch "$1"{0..9}.dat
2 changes: 2 additions & 0 deletions 2ano1/SO/aula02/c10xpto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
touch xpto0{0..9}.dat
3 changes: 3 additions & 0 deletions 2ano1/SO/aula02/exitfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
file -E "$1"
echo "Exit code: $?"
2 changes: 2 additions & 0 deletions 2ano1/SO/aula02/px.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
chmod +x "$@"
7 changes: 7 additions & 0 deletions 2ano1/SO/aula02/soma2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
if [[ "$#" -ne "2" ]]; then
echo "Usage: $0 num1 num2"
exit 1
fi

echo $(("$1" + "$2"))
9 changes: 9 additions & 0 deletions 2ano1/SO/aula03/aula03e01.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Agrupamento de comandos na Bash
{
i=0
while read line; do
echo $i: $line
i=$(($i+1))
done
} < $1
7 changes: 7 additions & 0 deletions 2ano1/SO/aula03/aula03e02a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Conditional block if
if $1; then
echo "Verdadeiro"
else
echo "Falso"
fi
7 changes: 7 additions & 0 deletions 2ano1/SO/aula03/aula03e02b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Conditional block if
if [[ $1 = $2 ]] ; then
echo "O arg1 é igual ao arg2"
else
echo "Os args são diferentes"
fi
7 changes: 7 additions & 0 deletions 2ano1/SO/aula03/aula03e02c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Conditional block if
if [ $1 = $2 ]; then
echo "O arg1 é igual ao arg2"
else
echo "Os args são diferentes"
fi
7 changes: 7 additions & 0 deletions 2ano1/SO/aula03/aula03e02d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Conditional block if
if [ "$1" = "$2" ]; then
echo "O arg1 é igual ao arg2"
else
echo "Os args são diferentes"
fi
5 changes: 5 additions & 0 deletions 2ano1/SO/aula03/aula03e02e.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# Conditional block if
if [ "$1" -gt 5 ] && [ "$1" -lt 10 ]; then
echo "número maior do que 5 e menor do que 10"
fi
21 changes: 21 additions & 0 deletions 2ano1/SO/aula03/aula03e03.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# This script checks the existence of a file

if [ "$#" -ne 1 ]; then
if [ "$#" -lt 1 ]; then
>&2 echo "Error: Not enough arguments"
else
>&2 echo "Error: Too many arguments"
fi

>&2 echo "Usage: $0 file"
exit 1;
fi

echo "Checking..."
if [[ -f "$1" ]] ; then
echo "$1 existe."
else
echo "$1 não existe"
fi
echo "...done."
40 changes: 40 additions & 0 deletions 2ano1/SO/aula03/aula03e03b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# This script checks the existence of a file

if [ "$#" -ne 1 ]; then
if [ "$#" -lt 1 ]; then
>&2 echo "Error: Not enough arguments"
else
>&2 echo "Error: Too many arguments"
fi

>&2 echo "Usage: $0 file"
exit 1;
fi

echo "Checking..."

if ! [ -e "$1" ]; then
echo "$1 não existe."
exit 1
fi

TYPE="unknown file"

if [ -f "$1" ]; then TYPE="regular file"
elif [ -b "$1" ]; then TYPE="block dev file"
elif [ -c "$1" ]; then TYPE="char dev file"
elif [ -d "$1" ]; then TYPE="directory"
fi

echo "$1 is a $TYPE"

PERMS=""

if [ -r "$1" ]; then PERMS="${PERMS}r"; else PERMS="${PERMS}-"; fi
if [ -w "$1" ]; then PERMS="${PERMS}w"; else PERMS="${PERMS}-"; fi
if [ -x "$1" ]; then PERMS="${PERMS}x"; else PERMS="${PERMS}-"; fi

echo "$1 permissions: $PERMS"

echo "...done."
20 changes: 20 additions & 0 deletions 2ano1/SO/aula03/aula03e03c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
# Testa se ano dado (ou ano actual, se nenhum for dado)
# é bissexto ou comum.
if [[ $# = 1 ]]; then
year=$1
else
year=$(date +%Y)
fi

if [[ $(($year % 400)) -eq "0" ]]; then
echo "Ano bissexto. Fevereiro tem 29 dias."
elif [[ $(($year % 4)) -eq 0 ]]; then
if [[ $(($year % 100)) -ne 0 ]]; then
echo " Ano bissexto. Fevereiro tem 29 dias."
else
echo "Ano comum. Fevereiro tem 28 dias."
fi
else
echo " Ano comum. Fevereiro tem 28 dias."
fi
33 changes: 33 additions & 0 deletions 2ano1/SO/aula03/aula03e04.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
#This script does a very simple test for checking disk space.

# `df -h`, report file system space usage in human readable format
# `awk '{print $5}'` - Print the fifth column (white space separated columns)
# `grep %` - Remove lines without the % symbol
# `grep -v Use` - Remove lines with the `Use` word
# `sort -n` - Sort lines numerically
# `tail -1` - Select the last line
# `cut -d "%" -f1 -` - Run the command `cut` reading from stdin (`-`) with the delimiter %
# and selecting the first field.
space=$(df -h | awk '{print $5}' | grep % | grep -v use | sort -n \
| tail -1 | cut -d "%" -f1 - | awk '{printf("%02d\n", $1)}')

echo "largest occupied space = $space%"
case $space in
[0-6][0-9]) # espaço < 70%
Message="All OK."
;;
[7-8][0-9] ) # 70% <= espaço < 90%
Message="Cleaning out. One partition is $space % full."
;;
9[0-8] ) # 90% <= espaço < 99%
Message="Better buy a new disk. One partition is $space % full."
;;
99 ) # espaço = 99%
Message="I'm drowning here! There's a partition at $space %!"
;;
* )
Message="I seem to be running with a non-existent disk..."
;;
esac
echo $Message
38 changes: 38 additions & 0 deletions 2ano1/SO/aula03/aula03e04b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#This script does a very simple test for checking disk space.

# `df -h`, report file system space usage in human readable format
# `awk '{print $5}'` - Print the fifth column (white space separated columns)
# `grep %` - Remove lines without the % symbol
# `grep -v Use` - Remove lines with the `Use` word
# `sort -n` - Sort lines numerically
# `tail -1` - Select the last line
# `cut -d "%" -f1 -` - Run the command `cut` reading from stdin (`-`) with the delimiter %
# and selecting the first field.
space=$(df -h | awk '{print $5}' | grep % | grep -v Use | sort -n \
| tail -1 | cut -d "%" -f1 -)

echo "largest occupied space = $space%"

largest=$(df | awk '{print $2 " " $1}' | tail -n +2 | sort -n -k1 \
| tail -1 | awk '{print $2 ": " $1}' | numfmt --field=2 --to=iec --from-unit=1024 )

echo "Largest partition $largest"
case $space in
[0-6][0-9]) # espaço < 70%
Message="All OK."
;;
[7-8][0-9] ) # 70% <= espaço < 90%
Message="Cleaning out. One partition is $space % full."
;;
9[0-8] ) # 90% <= espaço < 99%
Message="Better buy a new disk. One partition is $space % full."
;;
99 ) # espaço = 99%
Message="I'm drowning here! There's a partition at $space %!"
;;
* )
Message="I seem to be running with a non-existent disk..."
;;
esac
echo $Message
11 changes: 11 additions & 0 deletions 2ano1/SO/aula03/aula03e04c.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
shopt -s extglob

case "$1|$2" in
?([0-9])[0-9]"|"sec*)
echo "Válido."
;;
* )
echo "Não é válido"
;;
esac
5 changes: 5 additions & 0 deletions 2ano1/SO/aula03/aula03e05a.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash
# For all the files in a folder, show their properties
for f in $1/*; do
file "$f"
done
15 changes: 15 additions & 0 deletions 2ano1/SO/aula03/aula03e05b.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
if [ "$#" -ne 1 ]; then
if [ "$#" -lt 1 ]; then
>&2 echo "Error: Not enough arguments"
else
>&2 echo "Error: Too many arguments"
fi

>&2 echo "Usage: $0 dir"
exit 1;
fi
# For all the files in a folder, show their properties
for f in $1/*; do
file "$f"
done
Loading

0 comments on commit 98143d0

Please sign in to comment.