Useful Commands
This is a collection of useful linux commands that can be easily copy pasted.
General
Replacing lines in a file
./path/to/my_file.txt
and apply the specified changes. In this case these changes are the value of the key_in_file
key. The sed command can also be used to apply the same changes to outputs of other functions.
Extract values from JSON files
.json
files. Make sure to install it before attempting to use the above command. As mentioned on the webpage jq is like sed for JSON data
.
GIT
View all remotes
Change remote URL of specific remote
Add a new remote
Push to a specific remote
Revert already pushed commits
CRON
The cron command-line utility is a job scheduler on Unix-like operating systems 1. It can be used to periodically run various scripts on your server. A detailed CRON guide is provide by DigitalOcean. A helpful utility for understanding the cron time settings can be found on the following link: https://crontab.guru
Editing the crontab of the current user:
Erasing the crontab of the current user:
Storing the output of a cron job to a log file:
Info
In some environments you may need to setup environment variables such as the PATH
and the DOCKER_HOST
. This will enable your cron scripts to access and interact with services such as docker.
Tip
Ensure that you terminate commands with new lines and escape percentage signs using a backslash \%
as this may cause issues if it is not done.