Linux, Maven and Git Cheat Sheet
The commands I reach for daily while working across Linux servers, Maven builds and Git repositories — collected in one place: finding a file by owner/group/size, SSH with custom ports and jump hosts, Maven proxy configuration, and the Git tag commands that show up in every release workflow.
Find a File by Owner, Group and Size
To locate a file owned by user bandit7, group bandit6, exactly 33 bytes in
size, use this find command:
find / -type f -user bandit7 -group bandit6 -size 33c 2>/dev/null
- Search the entire server.
-type f: look for regular files.-user bandit7: files owned by user bandit7.-group bandit6: files owned by group bandit6.-size 33c: files that are 33 bytes in size (c stands for bytes).2>/dev/null: suppress permission denied errors.
SSH with a Custom Port
When the remote SSH daemon listens on a non-standard port, pass it with lowercase -p:
ssh -p PORT_NUMBER username@hostname
SSH with ProxyJump (Jump Host)
If you need to use an intermediary server (jump host) to reach your destination server, use the
-J option:
ssh -J jump_user@jump_host destination_user@destination_host
ProxyJump chains the two connections for you — you authenticate against the jump host, which then carries you to the destination. See the SSH setup guide for more SSH patterns.
Why We Need Proxy Configuration in Maven's settings.xml
The proxy configuration in the settings.xml file is essential for the following reasons:
- Network Access Control:
If your network is behind a corporate firewall or proxy server, Maven needs this configuration to route its requests through the proxy. This allows Maven to access remote repositories (such as Maven Central or internal repositories) and download dependencies or plugins, especially when direct access to the internet is restricted.
- Security and Monitoring:
Proxies are often used to monitor and control network traffic for security and auditing purposes. By routing Maven's traffic through a proxy, your organization can track and control access to external resources.
- Optimized Performance (Caching):
Proxies can cache responses (like dependencies or artifacts), which can speed up build times when accessing commonly used resources. If Maven has already downloaded a dependency once, the proxy can serve it from the cache instead of downloading it again.
- Bypass Local Restrictions:
The
nonProxyHostsfield allows you to define exceptions where Maven doesn't use the proxy, such as for internal repositories or local network addresses. This ensures that Maven can still communicate directly with trusted hosts without needing to route everything through the proxy. - Consistency:
Configuring the proxy in the
settings.xmlensures that all developers and build environments within your organization are using the same proxy configuration, providing consistent behavior across different machines or systems.
In summary, this configuration is required when Maven needs to access the internet via a proxy server, ensuring smooth communication with remote repositories and better control over network traffic.
Example Proxy Configuration in settings.xml
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
Example path to settings.xml: /opt/mvn-3-0-3/conf. See
the Java/Maven binary install guide for Maven setup.
Git Tag Commands
Here are some useful Git commands for managing and working with tags:
1. List all tags
git tag
Lists all the tags in the repository.
2. Show the latest tag
git describe --tags --abbrev=0
This will show the most recent tag associated with the current commit, without any additional information.
3. Show information about a specific tag
git show <tag_name>
Displays the commit information associated with the specified tag.
4. Create a new tag
git tag <tag_name>
Creates a new tag at the current commit.
5. Create an annotated tag
git tag -a <tag_name> -m "Tag message"
Creates an annotated tag with a message at the current commit. Annotated tags are stored as full objects in the Git database, containing the tagger name, email, and date.
6. Create a lightweight tag at a specific commit
git tag <tag_name> <commit_hash>
Creates a lightweight tag pointing to a specific commit. It's simply a reference to that commit.
7. Delete a tag
git tag -d <tag_name>
Deletes the specified tag from your local repository.
8. Push a tag to remote
git push origin <tag_name>
Pushes a specific tag to the remote repository.
9. Push all tags to remote
git push --tags
Pushes all tags in the local repository to the remote.
10. Checkout a tag
git checkout <tag_name>
Switches to a specific tag. This creates a "detached HEAD" state, meaning you're not on a branch, but instead, you're pointing to a specific commit.
11. List all tags with their commit messages
git tag -n
Lists all tags with the first few lines of their associated commit messages.
12. Find tags for a specific commit
git tag --contains <commit_hash>
Shows all the tags that contain the specified commit.
13. Show the commit history for a specific tag
git log <tag_name>
Shows the commit history for the specified tag.