Linux Commands
 
Notifications
Clear all

Linux Commands

1 Posts
1 Users
0 Reactions
11 Views
Frank Schroeder
(@iseetwizard)
Reputable Member Admin
Joined: 5 years ago
Posts: 97
Topic starter  

Here are some basic linux commands. Please be aware that depending on your distribution they might me slightly different or non existent.

 

File and directory management

 

command description
ls list directory contents
cd change directory
pwd print working directory
cp copy files and directories
mv move or rename files and directories
rm remove files or directories
mkdir make directories
rmdir remove empty directories
touch change file timestamps or create empty files
find search for files in a directory hierarchy
locate find files by name
tree display directories in a tree like format
chmod change file permissions
chown change file owner and group
chgrp change group ownership
stat display file or file system status

 

File viewing and editing

 

command description
cat concatenate and display file content
tac concatenate and display file content in reverse
more view file content interactively (page by page)
less view file content interactively (scrollable)
head output the first part of a file
tail output the last part of a file
nano text editor in terminal
vim or vi advanced text editor in terminal
emacs text editor in terminal
grep search text using patterns
sed stream editor for filtering and transforming text
awk pattern scanning and processing language
cut remove sections from each line of files
sort sort lines of text files
uniq report or omit repeated lines

 

Process Management

 

command description
ps report a snapshot of current processes
top display linux tasks
htop interactive process viewer (advanced top)
kill send a terminate signal to a process
killall terminate process by name
bg resume a suspended background job
fg bring a job to the foreground
jobs list active jobs
nice run a program with modified scheduling priority
renice alter priority of running processes
uptime show how long the system is up and running
time measure program running time

 

Disk management

 

command description
df report file system disk space usage
du estimate file space usage
fdisk partition table manipulator
lsblk list information about block devices
mount mount a file system
umount unmount a file system
parted partition table manipulator
mkfs create a file system
fsck file system consistency check and repair
blkid locate/print block device attributes

 

Networking

For the networking command I gonna create a seperate entry too...

command description
ifconfig configure network interfaces
ip show/manipulate routing, devices and tunnels
ping send ICMP echo requests to network host
netstat network statistics
ss socket statistics
traceroute trace the route packets take to a network host
nslookup query internet name servers interactively
dig DNS lookup utility
wget non-interactive downloader
curl transfer data with URLs
scp secure copy files between hosts
ssh secure shell for remote login
ftp file transfer protocol client

 

User and group management

 

command description
useradd add a user
usermod modify a user
userdel delete a user
groupadd add a group
groupdel delete a group
passwd modify the user password
chage change password expiry information
whoami print the current logged in user
who show who is logged in
w show who is logged in and what they are doing
id display the user and group id
groups show the user's groups

 

System information and monitoring

 

command description
uname print system information
hostname show or set the system's hostname
uptime how long the system has been running
dmesg boot and system messages
free display memory usage
top display linux tasks
vmstat report virtual memory statistics
lscpu display information about the CPU architecture
lsusb list USB devices
lspci list PCI devices
lshw list hardware configuration

 

Archiving and compression

 

command description
tar archive files
tar -czf test.tar.gz /directory/path/ → compress files using gzip
tar -xzf test.tar.gz → extract gzipped tarball
tar -cf test.tar → /directory/path → create a tarball
tar -xf test.tar → extract tarball
zip package and compress files into a ZIP archive
unzip extract files from a ZIP archive
gzip compress files using the gzip algorithm
gunzip decompress files compressed with gzip
bzip2 compress files using the bzip2 algorithm
bunzip2 decompress files compressed with bzip2
xz compress files using the xz algorithm
unxz decompress files compressed with xz

 

Package Management

Debian based (like Ubuntu)

 

command description
apt-get APT package handling utility
apt-get install packagename → install a package
apt-get update → update package list
apt-get upgrade → upgrade installed packages
apt-get remove packagename → remove a package
apt-cache query APT cache
apt-cache search packagename → search for a package
apt-cache show packagename → show package details

 

Red Hat based (like Centos, Fedora)

 

command description
yum package manager for RPM based systems
yum install packagename → install a package
yum update → update installed package
yum remove packagename → remove a package
dnf next generation package manager (CentOS 8+, Fedora)
dnf install packagename → install a package
dnf update → update installed packages
dnf remove packagename → remove a package

 

General

 

command description
rpm RPM package manager
rpm -i packagename.rpm → install an RPM package
rpm -e packagename → remove an RPM package
dpkg Debian package manager
dpkg -i packagename.deb → install a Debian package
dpkg -r packagename → remove a Debian package

 

System services and daemon management

 

command description
systemctl control the systemd system and service manager
systemctl start servicename → start a service
systemctl stop servicename → stop a service
systemctl restart servicename → restart a service
systemctl enable servicename → enable a service to start on boot
systemctl disable servicename → disable a service from starting on boot
systemctl status servicename → check service status
service older service management command (used in non systemd systems)
service servicename start → start a service
service servicename stop → stop a service
service servicename restart → restart a service
service servicename status → check service status

 

Scheduling tasks

 

command description
cron daemon for running scheduled commands
crontab -e → edit cron jobs for the current user
crontab -l → list the current user's cron jobs
crontab -r → remove the current user's cron jobs
at run commands at a specified time
at 06:00 → schedule a command to run at 6:00 o'clock
batch run commands when the system load is low
sleep delay for a specified time
sleep 6s → sleep for 6 seconds

 

File permissions and security

 

command description
chmod change file permissions
chown change file owner and group
chgrp change the group ownership of a file
umask set default permissions for new files
setfacl set file access control lists (ACL)
getfacl get file access control lists
sudo execute a command as another user (usually root)
visudo edit the sudoers file safely
passwd change a user's password
sudoers manage sudo access for users
gpasswd administer group password
ss display socket statistics (for secure network connections)

 

System backup and restore

 

command description
rsync remote file and directory synchronization
rsync -avz source destination → synchronize files
rsync -avz -e ssh source user@remote:/destination/ → sync over SSH
cpio copy files to and from archives
dd low-level copying and backup of entire filesystems
dd if=/dev/sda of=/path/backup.img → backup a disk or partition
dd if=/path/backup.img of=/dev/sda → restore a disk or partition

 

System Diagnostics and Troubleshooting

 

command description
dmesg print the kernel ring buffer messages
system boot and hardware related messages
journalctl query and view logs from systemd's jourmal
strace trace system calls and signals
strace commandname → trace a command's system call
lsof list open files
lsof files → show processes using a specific file
vmstat report virtual memory statistics
iostat report CPU and I/O statistics
mpstat report CPU usage statistics
pidstat report statistics by process
free display memory usage
uptime how long the system has been running
watch execute a program periodically - showing output
watch -n 1 free → watch memory usage every second
lshw list hardware configuration
htop interactive process viewer
netstat network statistics (replaced by ss)
ss show socket statistics

 

Networking & Remote Management

 

command description
ifconfig configure network interfaces (replaced by ip)
ip a more modern alternative for managing network interfaces and routing
ip addr → show ip addresses
ip link → show or manipulate network interfaces
ip route → show or manipulate routing tables
ss show socket statistics
nmap network exploration tool
telnet user interface to the telnet protocol
nc network utility for reading and writing from network connections
netcat
nc -l -p 1234 → listen on port 1234
nc host port → connect to a host and port
iptables administration tool for IPv4 packet filtering and NAT
firewalld frontend for managing firewall rules (Fedora/CentOS)
ufw uncomplicated firewall
ufw enable → enable firewall
ufw allow port → allow traffic on a specific port
tcpdump command line packet analyzer
curl transfer data from or to a server using various protocols
wget download files from the web
scp secure copy over SSH
scp test.txt user@remotemachine:/path → copy file to remote machine
rsync remote file and directory synchronization
rsync -avz /path/ remotemachine:/path → sync directories between 2 machines

 

Text Processing Utilities

 

command description
grep search for patterns within files
grep 'pattern' file.txt → search for a pattern in a file
grep -r 'pattern' /dirname/ → recursively search for a pattern
sed stream editor for filtering and transforming text
sed 's/old/ne/g' file.txt → replace old by new globally
awk a powerful text processing language
awk '{print $1} file.txt → print the first column of each line in a file
cut remove sections from each line of a file
cut -d ':' -f 1 /etc/passwd → print the first field of each line delimited by ":"
sort sort lines of text files
sort file.txt → sort file content in ascending order
uniq report or omit repeated lines in a file
sort file.txt | uniq → sort an remove duplicate lines
tee read from standard input and write to standard output and files
echo "text" | tee file.txt → write to file and show output on screen
tr translate or delete characters
echo "hello" | tr 'a-z' 'A-Z' → convert lowercase to upercase letters
paste merge lines of files
paste file1.txt file2.txt → combine lines of file1 and file2 side by side
wc word, line, character and or byte count
wc -l file.txt → count lines in a file
wc -w file.txt → count words in a file

 

System shutdown and reboot

 

command description
shutdown shut down a system
shutdown -h now → immediately shut down the system
shutdown -r now → immediately reboot the system
shutdown -h +10 → shut down after 10 minutes
reboot reboot the system
halt halt the system immediately
poweroff power off the system
init change the runlevel (old-style system manager)
init 0 → shutdown
init 6 → reboot

 

File system mounting and management

 

command description
mount mount a file system
mount /dev/sda1 /mnt → mount partition to a directory
umount umount a file system
umount /mnt → unmount the file system mounted at /mnt
fstab file system table
configuration file for mounting file systems
blkid display block device attributes
fsck check and repair a file system
fsck /dev/sda1 → check and repair /dev/sda1

 

Filesystem permissions and security

 

command description
chmod change file permissions
chmod 755 file.txt → give read write and execute permissions to owner
and read/execute permissions to others
chown change file owner and group
chown user:group file.txt → change owner and group of a file
chgrp change group ownership of a file
chgrp group file.txt → change the group of a file
umask set default permissions for new files
umask 022 → set default permissions for newly created files to 755
setfack set access control lists (ACL) for file permissions
getfacl get access control lists (ACL) for file permissions

 

Docker (containerization and orchestration)

 

command description
docker docker command line (CLI) for managing containers
docker run image run a container from an image
docker ps list running containers
docker ps -a list all containers including stopped ones
docker build -t imagename . build an image from a dockerfile
docker exec -it container_id bash start an interactive bash shell inside a running container
docker stop container_id stop a container
docker rm container_id remove a container
docker logs container_id view logs of a container
dock images list available images
docker rmi imagename remove an image
docker network ls list docker networks
docker-compose manage multi-container docker applications
docker-compose up start up a multi-container environment
docker compose down stop and remove containers created by docker-compose
docker-compose logs view logs from containers managed by docker-compose

 

Kubernetes (k8s) (containerization and orchestration)

 

command description
kubectl command line tool for interacting with Kubernetes clusters
kubectl get pods list pods in the current namespace
kubectl get nodes list nodes in the cluster
kubectl get services list services in the cluster
kubectl apply -f file.yaml apply configuration from a file
kubectl create -f file.yaml create a resource from a file
kubectl delete -f file.yaml delete a ressource defined in a file
kubectl exec -it podname --bash execute a command inside a pod (ex. open a shell)
kubectl logs podname view the logs of a pod
kubectl describe pod podname get detailed information about a pod
kubectl scale deployment deploymentname --replicas=number scale a deployment to the desired number of replicas
kubectl rollout restart deployment deploymentname restart a deployment
kubectl port-forward pod podname localport:remoteport forward a port from a pod to localhost

 

Helm (containerization and orchestration)

 

command description
helm Kubernetes package manager for deploying applications
helm install releasename chartname install a helm chart
helm upgrade releasename chartname upgrade a helm release
helm list list all helm releases
helm delete releasename delete a helm release
helm search chartname search for a helm chart

 

Automation and configuration management

Ansible

command description
ansible automation tool for configuration management
ansible all -m ping ping all hosts defined in the inventory
ansible-playbook playbook.yml run an ansible playbook
ansible -m command -a 'command' host run a single command on a target host
ansible-playbook --check playbook.yml dry run a playbook to see what would change
ansible-playbook --limit host playbook.yml run a playbook on a specific host or group
ansible-playbook --extra-vars "key=value" pass extra variables to a playbook

 

Terraform

 

command description
terraform infrastructure as code tool for provisioning and managing cloud ressources
terraform init initialize a working directory for terraform configuration
terraform plan show an execution plan (what changes would be made)
terraform apply apply the changes described in a terraform configuration
terraform destroy destroy infrastructure created by terraform
terraform validate validate the configuration files
terraform show show the current state of the infrastructure

 

Puppet

 

command description
puppet configuration management tool
puppet apply manifest.pp apply a puppet manifest locally
puppet agent ---test test the puppet agent
puppet resource show the current state of resources
(files, services, etc.)

 

CI/CD tools and commands

Jenkins

 

command description
jenkins continous integration tool
java -jar jenkins.war start jenkins from a war file
access jenkins trough http://localhost:8080 by default

 

GitLab CI

 

command description
.gitlab-ci.yml configuration file for GitLab CI/CD pipelines
gitlab-runner register register a new runner with GitLab
gitlab-runner run run the Gitlab Runner to process jobs

 

GitHub Actions

 

command description
Info GitHub Actions uses YAML configuration files
typically located in .github/workflows/
actions/checkout@v2 checkout the repository code in your CI pipeline
actions/setup-node@v2 setup Node.JS for use in a pipeline
docker/setup-buildx-action@v1 set up docker buildx for building multi platform images

 

Cloud Services

AWS CLI (Amazon Web Services)

 

command description
aws command line tool for managing AWS services
aws configure configure AWS CLI with your credentials
aws s3 cp file.txt s3://bucketname/ copy a file to an S3 bucket
aws ec2 describe-instances descripe EC2 instances
aws ec2 start-instances --instance-ids id start an EC2 instance
aws ec2 stop-instances --instance-ids id stop an EC2 instance
aws s3 sync sync directories with an S3 bucket

 

Azure CLI (Microsoft)

 

command description
az command line tool for managing Azure services
az login log in to your Azure account
az vm list list all virtual machines
az vm start --name vmname --resource-group resourcegroup start an Azure VM
az storage blob upload upload files to an Azure blob storage
az group create create a new resource group in Azure AD

 

Google Cloud SDK

 

command description
gcloud command line tool for Google cloud platform
gcloud auth login log in to Google cloud
gcloud compute instances list list compute instances
gcloud compute instances stop instancename stop a Google cloud VM instance
gcloud ap browse open the current Google app engine application in a browser

 

Logging and Monitoring

Prometheus

 

command description
prometheus open source system monitoring and alerting toolkit
start prometheus server (usually as a background service)
prometheus --config.file=configfile start prometheus with a specific config file

 

Grafana

 

command description
grafana-cli command line interface for managing Grafana plugins
grafana-cli plugins install pluginname install a plugin in Grafana

 

ELK Stack (Elasticsearch, Logstash, Kibana)

 

command description
elasticsearch search engine for logging and data analytics
curl -XGET 'localhost:9200/_cluster/health?pretty' get cluster health status
logstash server side data processing pipeline
logstash -f configfile run logstash with the specified configuration file
kibana web interface for visualizing Elasticsearch data
Kibana is generally access through web on http://localhost:5601

 


   
Quote