Change and reset colors

01-08-2023, source: StackOverflow; SuperUser

echo "$(tput setaf 4)==>$(tput sgr0) Hello World"

Change the printed text

01-08-2023, source: StackOverflow

echo -n " 50% complete."$'\r'; sleep 1; echo "100% complete."

List the colors

01-08-2023, source: self

for i in {0..50}
   echo "$(tput setaf $i) ### $i$(tput sgr0)"

List the file types (estimate)

05-12-2022, source: StackOverflow

find . -type f -exec file -- {} +
  • -type f determines file type

  • -f NAMEFILE/--files-from NAMEFILE specifies a particular file

List the file sizes

22-11-2022, source: StackOverflow

du -hs .
  • du displays disk usage statistics

  • -h stands for a human-readable format.

  • -s stands for the files only (depth is 0, i.e., -d 0).

  • By default, the du program recursively lists the directories.

List recursively files and occurrences containing a text

17-08-2022, source: self

grep -R 'text' .
  • -R/-r/--recursive forces recursive search

Find empty JAR archives

25-07-2023, source: StackOverflow

find $HOME/.m2/repository -iname "*.jar" -size 0
find $HOME/.m2/repository -iname "*.jar" -size 0 -exec rm {} \;


Move all files (but not directories)

15-02-2023, source: self + AskUbuntu

for i in `find documents/source -type f -maxdepth 1` ; do
  cp $i documents/destination ;
  • -type f determines file type

  • -maxdepth MAXDEPTH sets the depth limit from the source directory, remove for recursive search


Is a program installed

29-11-2022, source: StackOverflow

# Node.js for example
if which node > /dev/null
    echo "Using Node.js version: $(node -v)"
    echo "Node.js not installed"
    exit 1

Users and Rights

Make the file executable

23-12-2022, source: self

chmod +x
chmod +x *.sh

List all users

30.10.2023, source: StackOverflow

dscl . list /Users | grep -v '^_'