Unix Commands
Nov 5, 2022
# Cheat Sheets
# Users / Groups
To get the current user in a shell or script, run the below command
or
# SSH
- Template command to remotely run a script and immediately exit, without caring about the result. This is useful for automation scripts that involve running multiple commands on remote servers.
1
| ssh -q $SSH_USER@$SERVER "nohup /appl/bin/start.sh start > /dev/null 2>&1 & "
|
# Verify DNS Resolution
1
| nslookup www.google.com
|
# IP Address
# Public IP Address of local machine
# Private IP Address of local machine
# Grand total size of all the subdirectories in the current directory
# Process ID Number
lsof -p PID
will list all the files that have been touched by the currently running process
# egrep
- Search contents of every file for this matching text:
find . -type f -exec egrep -lH search_for_me '{}' ';'
# find command
- Find every file named config.txt in your home directory:
find ~ -name "config.txt"
# scp file transfer commands
- Copy a file from a local to a remote system:
scp file.txt ssh_user@hostname:/tmp
- List all certs in a keystore:
keytool -list -keystore <PATH_TO_CACERTS> -storepass changeit -noprompt
- Add a cert to a keystore:
keytool -import -trustcacerts -keystore <PATH_TO_CACERTS> -storepass changeit -noprompt -alias <ALIAS> -file <PATH_TO_NEW_CERT>
- Delete cert in a keystore by alias:
keytool -delete -alias <ALIAS> -keystore <PATH_TO_CACERTS>
# OpenSSL commands
- Verify contents of a cert:
openssl x509 -in <PATH_TO_CERT> -text
- View certs of a client:
openssl s_client -showcerts -connect google.com:636
# Change Ownership of Symlink
chown -h USER:GROUP jre
if you want to change the ownership of the symlink itself, not the destination directory
# What’s using this port?
- Handy command for Mac to check what process is using a port
- If you’re on Mac You can also look up and stop processes via the Activity Monitor GUI.
- If you wanted to stop a
java
process, for example, you could go to the Disk
section, and filter by java
processes.