Using rsync to Sync Two Directories
You can sync two directories using rsync tool. The following command:
$ rsync -a -v --delete sending_directory target_directory;
will copy sending_directory to target_directory creating a directory structure of sending_directory/target_directory. The --delete flag will ensure that any files that were previously in sending_directory/target_directory that are not in sending_directory will be deleted so that the contents of the two directories are the same.
Move Files Older Than So Many Days with Find
You may want to clean up a directory that has files older than a certain number of days, for example, 30 days. You can do this with the find command:
To move files older than 30 days in current folder to the old folder:
$ find . -mtime +30 -exec mv {} old/ \;
Build, Tag, and Push a Docker Image with One Command
You can build, tag, and push a docker image to a remote all in one command with the –quiet parameter on docker build, which only outputs the SHA256 hash (annoyingly prefixed with SHA256:, but nothing a little cutting can’t fix).
$ docker tag $(docker build . -q | cut -c 8-999) myregid/imagename:1.0.1 && docker push myregid/imagename
Vim Tips: Searching a File for Multiple Strings
In Vim you can perform a search like this: /string1/;/string2
This will will combine two searches. It tells Vim:
- Search for string1, then
- From there search for string2 on any line that also contains string1.
Using RClone to Mount Your OneDrive Folder in Linux
If you have a Microsoft Office 365 account you know that it comes with 1TB of storage. You can use RClone to mount your OneDrive locally on your Linux machine so that you can read and write documents stored there.
- Install rclone from whatever package repository that your Linux operating system uses.
- Follow the instructions here to configure your OneDrive environment. The instructions are rather straightforward and a couple pieces of extra advice follows:
In the first section, type n for a new installation and give your mountpoint a name:
Find the IP Addresses of KVM Virtual Machines (Command Line)
To find details about the virtual network you can use these commands:
root@slacker:~# virsh net-listName State Autostart Persistent--------------------------------------------default active yes yesroot@slacker:~# virsh net-info defaultName: defaultUUID: 14a90f27-9a85-42ca-b434-6ce6c142690cActive: yesPersistent: yesAutostart: yesBridge: virbr0root@slacker:~# virsh net-dhcp-leases defaultExpiry Time MAC address Protocol IP address Hostname Client ID or DUID------------------------------------------------------------------------------------------------------------2023-07-22 16:18:45 52:54:00:dd:7b:62 ipv4 192.168.122.216/24 centos7-bbk -
SSH Escape Sequences
Have you ever had an SSH connection timeout on you and you’re left with what looks like a locked session. Repeatedly hitting the Enter key does nothing. It seems that there is nothing that you can do except close the console terminal session…or is there something else?
Many people are not aware that SSH has its own set of keyboard shortcuts. The solution to the above problem is to terminate the connection using the first of these shortcuts.
View lshw Output as a HTML Page
You can use the lshw command to output your hardware configuration to an html file by passing the -html parameter to it:
$ sudo lshw -html >hardware.html
List TCP Connections Sorted By Host and Most Connections
Assuming your system still has netstat installed (Slackware 15.0 does :^), you can summarize the TCP connections on you host using the following command:
$ netstat -ntu|awk '{print $5}'|cut -d: -f1 -s|sort|uniq -c|sort -nk1 -r3 52.50.230.xxx3 104.18.27.xxx3 104.18.26.xxx2 205.166.94.xx2 192.168.1.xx2 142.251.40.xxx2 104.18.13.xx1 74.120.9.xxx1 66.255.245.xxx1 54.154.65.xxx1 52.96.182.xxx1 45.56.116.xxx1 45.33.73.xxx1 34.117.65.xx1 20.190.135.xx1 192.168.122.xxx1 192.168.1.xx1 172.253.63.xxx1 162.159.61.x1 162.125.21.x1 142.251.40.xxx1 142.251.32.xxx1 142.251.16.xxx1 127.0.0.x
Test If a Port is Open with Bash
If netcat isn’t available on your machine and you don’t have the priviledge to install it you can use this trick to test if a port is open or not. It will throw a connection refused message if a port is closed.
$ : </dev/tcp/127.0.0.1/80
And you can use it in a script like this:
(: </dev/tcp/127.0.0.1/80) &>/dev/null && echo "OPEN" || echo "CLOSED"