Mac Quick Tips
October 22, 2018 Leave a comment
Below is a list of commands that I found useful whilst working in a Mac environment. I have not attempted to explain what each command does in details, as there are tons of online materials that do that already. Do ensure you have the right privileges whilst executing the commands. So here we go:
FIND DIRECTORY OF YOUE MOST RECENT JAVA VERSION
/usr/libexec/java_home -v
Output:
/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home
CHECKING THAT A PROCESS IS RUNNING ON A PORT e.g. 9000
> ps -ef | grep 9000
>netstat -anp | grep 9000
For all processes: > netstat -anp
FETCHING AN IP ADDRESS
> sudo /sbin/ifconfig
COMPRESSING AND UN-COMPRESSING FILES
> tar -cvzf srcbackup.tgz {directory}
-c: compress -v: verbose -z : use Gzip -f: zipped file name
> tar -xvzf srcbackup.tgz {directory}
-x: extract
SECURE COPY
Copy the file “foobar.txt” from a remote host to the local host
$ scp your_username@remotehost:foobar.txt /some/local/directory
Copy the file “foobar.txt” from the local host to a remote host
$ scp foobar.txt your_username@remotehost:/some/remote/directory
Copy the directory “sample” from the local host to a remote host’s directory “test”
$ scp -r sample your_username@remotehost:/some/remote/directory/test
CHECK ALL ACTIVE CONNECTIONS ON A MACHINE
> #sudo netstat -tuplen
CHECK ALL PROGRAMS THAT PROVIDE JAVA
# sudo alternatives –config java
Output:
There are 2 programs which provide ‘java’.
Selection Command
———————————————–
*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
Enter to keep the current selection[+], or type selection number:
CHECK THE TLS CERTIFICATE ON A SERVER (e.g. an smtp server)
# sudo openssl s_client -connect mail.sever.com:25 -starttls smtp < /dev/null
</dev/null – is not required ans its just to end the command.
HOW TO MANAGE CENTOS SYSTEM SERVICES
A very good write-up . Thanks Milosz .
DELETING ALL FILES EXCEPT FOLDERS WITHIN A DIRECTORY
# sudo find . -maxdepth 1 -type f -delete
FIND OUT LAST REBOOT DATE, TIME AND WHO
https://www.cyberciti.biz/tips/linux-last-reboot-time-and-date-find-out.html
FIND OUT ALL SOCKETS ON THE SYSTEM
sudo find / -type s