Skip to content

Instantly share code, notes, and snippets.

@Eidansoft
Last active July 23, 2020 08:13
Show Gist options
  • Save Eidansoft/408b6b46aba9fec2f8c2fe50ba336b49 to your computer and use it in GitHub Desktop.
Save Eidansoft/408b6b46aba9fec2f8c2fe50ba336b49 to your computer and use it in GitHub Desktop.
Shellscripts useful tips without category
# Force a shellscript to run from its folder, instead the current directory
# folder where was called from. Useful to use relative paths.
# Set the folder to project, no matter from where the script was called.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
pushd $SCRIPT_DIR
# Test the connectivity from a machine to another and the port
nc -vv 192.168.1.200 80
# Another possible test is to start a service at destination machine, and
# check from another if the data send is received there:
# 1.- You can easely start a listener at the destination machine:
nc -vlkp 8080
# 2.- Then just send it anything and see if the listener receive it, you can
# do it with a browser pointing to http://LISTENER_IP:8080 or from console with:
nc -v LISTENER_IP 8080
# View the size of all current subfolders sorted by size
du -sh ./* | sort -hr
# du command calculate the space used, the options used are:
# s -> summarice sizes (one value per folder)
# h -> human readable
# sort command is to sort the results, the options used are:
# h -> to sort properly the values in human format
# r -> reverse results to show the bigger values first
# Generate a file of specific size (usually for testing porpouses) for example 100Mb
# Source -> https://skorks.com/2010/03/how-to-quickly-generate-a-large-file-on-the-command-line-with-linux/
dd if=/dev/urandom of=/tmp/test_100mb.txt bs=1048576 count=100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment