- Download the contents of a URL to a file:
curl http://example.com --output path/to/file
- Download a file, saving the output under the filename indicated by the URL:
curl --remote-name http://example.com/filename
- Download a file, following location redirects, and automatically continuing (resuming) a previous file transfer and return an error on server error:
curl --fail --remote-name --location --continue-at - http://example.com/filename
- Send form-encoded data (POST request of type `application/x-www-form-urlencoded`). Use `--data @file_name` or `--data @'-'` to read from STDIN:
curl --data 'name=bob' http://example.com/form
- Send a request with an extra header, using a custom HTTP method:
curl --header 'X-My-Header: 123' --request PUT http://example.com
- Send data in JSON format, specifying the appropriate content-type header:
curl --data '{"name":"bob"}' --header 'Content-Type: application/json' http://example.com/users/1234
- Pass a username and password for server authentication:
curl --user myusername:mypassword http://example.com
- Pass client certificate and key for a resource, skipping certificate validation:
curl --cert client.pem --key key.pem --insecure https://example.com
- Request the first 100 bytes
curl -r 0-99 http://exmaple.com
- Send delete request
curl -X DELETE https://www.baidu.com
Â
Advanced usage
Output the entire process of a request communication
Bash
curl -v https://www.google.com
Â
systemctl
The systemctl command is used for to init system and service manager.
Starting and Stopping Services
Start/Stop a Service immediately.
Shell
systemctl start/stop [service_name]
Enabling and Disabling Services
Enable/Dsiable a Service to start on boot.
Shell
systemctl enable [service_name]
Checking Service Status
Check Status: Check the status of a service.
Shell
systemctl status [service_name]
Managing the Systemd System
Reload Systemd: Reload the systemd manager configuration.
Shell
systemctl daemon-reload
Reboot the System: Use systemctl to reboot the system.
Shell
systemctl reboot
Listing Services
List Active Services: List all active services.
Shell
systemctl list-units --type=service
Â
Other Useful Commands
Mask/Unmask a Service: Prevent a service from being started manually or automatically (mask) or reverse this action (unmask).
$ teststr="Jeff and the pet Lucky. Gregg and the dog Fido. Chris has 1 bird named Tweety."
$ echo $teststr | grep -Poi 'g{1,2}'
dig
DNS lookup utility.
Bash
- Lookup the IP(s) associated with a hostname (A records):
dig +short example.com
- Get a detailed answer for a given domain (A records):
dig +noall +answer example.com
- Query a specific DNS record type associated with a given domain name:
dig +short example.com A|MX|TXT|CNAME|NS
- Get all types of records for a given domain name:
dig example.com ANY
- Specify an alternate DNS server to query:
dig @8.8.8.8 example.com
- Perform a reverse DNS lookup on an IP address (PTR record):
dig -x 8.8.8.8
- Find authoritative name servers for the zone and display SOA records:
dig +nssearch example.com
- Perform iterative queries and display the entire trace path to resolve a domain name:
dig +trace example.com
NC
A networking tool used for reading from and writing to network connections using TCP or UDP protocols. It's often described as the "Swiss army knife" of networking due to its wide range of capabilities. Here are some common uses and examples of the nc command:
Common Uses
Creating a TCP Connection:
Connect to a server: nc [server] [port]
For example, to connect to a web server on port 80: nc example.com 80
Listening for Incoming Connections:
Listen on a specific port: nc -l [port]
For example, to listen on port 1234: nc -l 1234
Transferring Files:
On the receiving end: nc -l [port] > filename.ext
On the sending end: nc [destination] [port] < filename.ext
Chat Server and Client:
Server: nc -l [port]
Client: nc [server address] [port]
Port Scanning:
Scan a range of ports: nc -z [destination] [port-range]
For example, to scan ports 20-30: nc -z example.com 20-30
Testing Network Throughput:
On the server: nc -l [port] > /dev/null
On the client: nc [server address] [port] < /dev/zero