There are various linux commands which are used in daily operations, I have tried to combine most of them below.
Display OS name, kernel version and hostname
uname -aDisplay system uptime, load average and users logged in
uptimeKernel details
cat /proc/versionListing all the files
ls
cd - Change Directory
cd /path/to/directory
Print Working Directory
pwd
Copy
cp source_file destinationMove/Rename
mv old_file new_locationRemove/Delete
rm fileMake Directory
mkdir new_directory
Global Regular Expression Print
grep pattern file.txtChange File Permissions
chmod +x file.shChange Ownership
chown user:group fileProcess Status
ps auxTerminate a Process
kill PIDDisk Free
df -hDisk Usage
du -hTape Archive
tar -czvf archive.tar.gz directory/Network Interface Configuration
ifconfigTest Network Connectivity
ping google.com
Test if remote server is reachable over a specific port
telnet host port
Trace Route to a Host
traceroute google.com
Network Statistics
netstat -a
Socket Statistics
ss -a
IP Packet Filter and NAT
iptables -LCheck process running on a port
lsof -i :80Query DNS for Information
nslookup google.com
The resolv.conf
file is a configuration file used by Linux systems to configure the DNS (Domain Name System) resolver. It contains information about the DNS servers and search domains that the system should use to resolve domain names to IP addresses.
cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
Firewall Commands
There are various firewall commands which can be used to check zones, open ports and close ports either temporary or permanently.
Ubutnu
On Ubuntu, the default firewall management tool is usually ufw
(Uncomplicated Firewall).
1. Enable UFW
sudo ufw enable
2. Allow a Specific Port
sudo ufw allow 80/tcp
3. Allow a Specific Application (Service)
sudo ufw allow ssh
4. Deny a Specific Port
sudo ufw disable
Redhat
firewall-cmd
is a command-line utility for managing firewalld, the default firewall management tool on many Linux distributions, such as CentOS, Fedora, and RHEL.
1. List all zones
firewall-cmd --get-zones
2. Show the default zone
firewall-cmd --get-default-zone
3. List all services
firewall-cmd --get-services
4. List allowed services in a zone
firewall-cmd --zone=public --list-services
5. Add a service to a zone
firewall-cmd --zone=public --add-service=http
6. Add a port to a zone
firewall-cmd --zone=public --add-port=80/tcp
7. Reload firewall rules
firewall-cmd --reload
8. Permanent changes
firewall-cmd --zone=public --add-service=http --permanent firewall-cmd --reload
9. Open a range of ports
firewall-cmd --zone=public --add-port=3000-3100/tcp
Crontab
The crontab
command in Unix-like operating systems is used to create, edit, display, and manage the cron jobs for a user. Cron jobs are scheduled tasks that run automatically at specified intervals.
Here are some common crontab
commands and examples
crontab - Schedule Jobs
crontab -e
crontab - View Crontab
crontab -l
Cron Syntax
* * * * * command_to_be_executed
*
represents minute, hour, day of the month, month, and day of the week.
30 15 * /path/to/script.sh
Example: Run a script every day at 3:30 PM.
systemctl - Enable/Start/Stop Services
systemctl enable cron # Enable the cron service
systemctl start cron # Start the cron service
systemctl stop cron # Stop the cron service