117 lines
2.4 KiB
Bash
117 lines
2.4 KiB
Bash
|
# 1
|
||
|
function rmcore {
|
||
|
find $1 -name "core" -size +0 -exec rm {} \;
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 2
|
||
|
function satisfait {
|
||
|
ans="\0"
|
||
|
until [ ${ans:0:1} = "o" ] || [ ${ans:0:1} = "n" ]
|
||
|
do
|
||
|
echo -n "Etes-vous satisfait ? (o/n) "
|
||
|
read ans
|
||
|
done
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 3
|
||
|
# Via la commande "last | head" un utilisateur peut savoir précisement la date à laquelle il s'est deconnecté.
|
||
|
# Ensuite en executant: "find ~" il peut ainsi regarder quels fichiers on été modifiés.
|
||
|
|
||
|
function lastmodif {
|
||
|
find ~ -printf "%AFT%Ar %TFT%Tr %p \n" | sort
|
||
|
tput setaf 1 && echo "last access last modified"
|
||
|
echo -n "last logout : "
|
||
|
tput setaf 1 && last `whoami` --time-format=iso | head -n 2 | tail -n 1 | awk '{print $5}' | cut -c -19 &&
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 4 plutôt lent
|
||
|
function arbre {
|
||
|
if [ $1 = "-d" ]
|
||
|
then
|
||
|
list=`find $2 -type d -printf "%d %f\n"`
|
||
|
else
|
||
|
list=`find $1 -printf "%d %f\n"`
|
||
|
fi
|
||
|
|
||
|
while IFS= read -r line; do
|
||
|
nb=`echo $line | awk '{print $1}'`
|
||
|
printf '\t%.0s ' {0..$nb}
|
||
|
echo $line | awk '{print $2}'
|
||
|
done <<< "$list"
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 5
|
||
|
function profondeur {
|
||
|
find $1 -printf "%d %p\n" | sort -n | tail -n 1
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 6
|
||
|
# on peut créer un alias qui supprime automatiquement les options -T et -e et qui remplace automatiquement -t par -x
|
||
|
|
||
|
# 7
|
||
|
function inv {
|
||
|
for (( i=$#1-1; i>=0; i-- ))
|
||
|
do
|
||
|
echo -n ${1:$i:1}
|
||
|
done
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 8
|
||
|
alias lsd="ls -lahd -- */ .*/"
|
||
|
|
||
|
# 9 # TODO: mode d'emploi + multi mois
|
||
|
function arbre {
|
||
|
if [ $1 = "-d" ]
|
||
|
then
|
||
|
find $2 -type d -printf "%Tb %p\n" | grep $3 | awk '{print $2}'
|
||
|
else
|
||
|
find . -printf "%Tb %p\n" | grep $1 | awk '{print $2}'
|
||
|
fi
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 10
|
||
|
function tuer {
|
||
|
list=`ps -eo pid,comm | grep $1`
|
||
|
|
||
|
if [ `echo $list | awk '{ print $2 }' | sort | uniq | wc -l` -gt 1 ]
|
||
|
then
|
||
|
return -1
|
||
|
else
|
||
|
echo $list | awk '{ print $1 }' | xargs kill
|
||
|
fi
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 11
|
||
|
function compter {
|
||
|
cat $1 | grep -o $2 | wc -l
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 12
|
||
|
function voyelles {
|
||
|
echo $1 | egrep -Eo "*[aeiouy]" | sort | uniq | tr -d "\n"
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 13
|
||
|
... | awk '{ print length " " $0 }' | sort -n | tail -n 1 | awk '{$1=""}1'
|
||
|
|
||
|
# 14
|
||
|
function multipath {
|
||
|
echo $PATH | tr ':' '\n' | xargs -I{} find {} -type l -printf "%l\n" | sort | uniq -d
|
||
|
return 0
|
||
|
}
|
||
|
|
||
|
# 15
|
||
|
function doublons {
|
||
|
cat $1 | tr -d "\n" | grep -E '(\b.+) \1\b'
|
||
|
return 0
|
||
|
}
|