Linux Commands: gunzip, hostnamectl, iptables, and More
The gunzip Command
The
gunzipcommand decompresses files compressed by thegzipcommand.It replaces files ending with
.gz,-gz,.z,-z, or_z(case-insensitive) that begin with the correct magic number with an uncompressed file without the original extension..tgzand.tazextensions are recognized as shorthands for.tar.gzand.tar.Zrespectively.Examples:
gunzip filename.gz: Uncompressesfilename.gz.gunzip -r directory_name/: Recursively uncompresses content inside a directory, matching extensions accepted bygunzip.gunzip -S .tgz *: Uncompresses all files in the current directory with the.tgzsuffix.gunzip -l file_1 file_2: Lists compressed and uncompressed sizes, compression ratio, and uncompressed names of input compressed files.
Syntax:
gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]Flags:
-c,--stdout: Writes to standard output, keeps original files unchanged.-h,--help: Displays help information.-k,--keep: Keeps (doesn't delete) input files.-l,--list: Lists compressed file contents.-q,--quiet: Suppresses all warnings.-r,--recursive: Operates recursively on directories.-S,--suffix=SUF: Uses suffixSUFon compressed files.--synchronous: Synchronous output (safer if the system crashes, but slower).-t,--test: Tests compressed file integrity.-v,--verbose: Verbose mode.-V,--version: Displays the version number.
The hostnamectl Command
The
hostnamectlcommand is used to control the Linux system hostname and its related settings.It can change the hostname without directly editing the
/etc/hostnamefile.Syntax:
$ hostnamectl [OPTIONS...] COMMAND ...Commands:
status: Checks the current hostname settings.set-hostname NAME: Sets the system hostname.set-icon-name NAME: Sets the icon name for the host.
Examples:
hostnamectlorhostnamectl status: Views the current hostnames.hostnamectl set-hostname myhostname --static: Changes the static hostname tomyhostname(may require root access).hostnamectl set-hostname myotherhostname --transient: Sets or changes a transient hostname.hostnamectl set-hostname "prettyname" --pretty: Sets the pretty hostname (name must be in double quotes).
The iptables Command
The
iptablescommand is used to set up and maintain tables for the Netfilter firewall for IPv4 in the Linux kernel.It matches packets with rules defined in tables and takes specified actions on a match.
Syntax:
iptables --table TABLE -A/-C/-D... CHAIN rule --jump TargetExamples:
iptables [-t table] --append [chain] [parameters]: Appends to the chain provided in parameters.iptables -t filter --append INPUT -j DROP: Drops all traffic coming on any port.
Flags:
-C: Checks if a rule is present in the chain; returns 0 if the rule exists, 1 otherwise.-A: Appends to the chain provided in parameters.
The netstat Command
netstatstands for Network Statistics.- It displays current network connections, networking protocol statistics, and various interfaces.
- Check installation:
netstat -v - Install if not available:
sudo apt install net-tools - Use Cases and Examples:
netstat -nr: Shows the routing table detail on the terminal.netstat -i: Shows statistics for the currently configured network interfaces.netstat -tunlp: Provides a list of networks, their current states, and their associated ports.netstat -at: Gets the list of all TCP port connections.netstat -au: Gets the list of all UDP port connections.netstat -l: Gets the list of all active connections.
The lsof Command
- The
lsofcommand shows file information for all files opened by a running process; stands for