Skip to content
Agustí Sánchez edited this page Aug 17, 2020 · 13 revisions

Linux

System

Ports in use

lsof -i -n -P | grep java

Solaris

pfiles `ls /proc` 2>/dev/null | awk "/^[^ \\t]/{smatch=\$0;next}/port:[ \\t]*${1}/{print smatch, \$0}{next}"

Batch-convert line endings

find . -name "*.txt" | xargs dos2unix

Disk Usage

du

Disk free

df

Free RAM

free

Partion of filesystem

Filesystem a directory is mounted on:

df <dir>

Hardware report

sudo lshw -html > hardware.html

Open in GUI

xdg-open

Bash

Remove directories with a given name

find . -name target -exec rm -fR {} \;

Test if file does not exists

f [ ! -e "$file" ]; then
    echo "File does not exist"
else 
    echo "File exists"
fi 
```

```
-b filename - Block special file
-c filename - Special character file
-d directoryname - Check for directory existence
-e filename - Check for file existence, regardless of type (node, directory, socket, etc.)
-f filename - Check for regular file existence not a directory
-G filename - Check if file exists and is owned by effective group ID.
-g filename - true if file exists and is set-group-id.
-k filename - Sticky bit
-L filename - Symbolic link
-O filename - True if file exists and is owned by the effective user id.
-r filename - Check if file is a readable
-S filename - Check if file is socket
-s filename - Check if file is nonzero size
-u filename - Check if file set-user-id bit is set
-w filename - Check if file is writable
-x filename - Check if file is executable

For loop

#!/bin/bash
for i in {1..5}
do
   echo "Welcome $i times"
done

SSH non-strict

-o StrictHostKeyChecking=no 
lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0  30G  0 disk
└─xvda1 202:1    0  30G  0 part /