Linux Commands

Linux Commands

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

commanddescription
lslist directory contents
cdchange directory
pwdprint working directory
cpcopy files and directories
mvmove or rename files and directories
rmremove files or directories
mkdirmake directories
rmdirremove empty directories
touchchange file timestamps or create empty files
findsearch for files in a directory hierarchy
locatefind files by name
treedisplay directories in a tree like format
chmodchange file permissions
chownchange file owner and group
chgrpchange group ownership
statdisplay file or file system status

File viewing and editing

commanddescription
catconcatenate and display file content
tacconcatenate and display file content in reverse
moreview file content interactively (page by page)
lessview file content interactively (scrollable)
headoutput the first part of a file
tailoutput the last part of a file
nanotext editor in terminal
vim or viadvanced text editor in terminal
emacstext editor in terminal
grepsearch text using patterns
sedstream editor for filtering and transforming text
awkpattern scanning and processing language
cutremove sections from each line of files
sortsort lines of text files
uniqreport or omit repeated lines

Process Management

commanddescription
psreport a snapshot of current processes
topdisplay linux tasks
htopinteractive process viewer (advanced top)
killsend a terminate signal to a process
killallterminate process by name
bgresume a suspended background job
fgbring a job to the foreground
jobslist active jobs
nicerun a program with modified scheduling priority
renicealter priority of running processes
uptimeshow how long the system is up and running
timemeasure program running time

Disk management

commanddescription
dfreport file system disk space usage
duestimate file space usage
fdiskpartition table manipulator
lsblklist information about block devices
mountmount a file system
umountunmount a file system
partedpartition table manipulator
mkfscreate a file system
fsckfile system consistency check and repair
blkidlocate/print block device attributes

Networking

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

commanddescription
ifconfigconfigure network interfaces
ipshow/manipulate routing, devices and tunnels
pingsend ICMP echo requests to network host
netstatnetwork statistics
sssocket statistics
traceroutetrace the route packets take to a network host
nslookupquery internet name servers interactively
digDNS lookup utility
wgetnon-interactive downloader
curltransfer data with URLs
scpsecure copy files between hosts
sshsecure shell for remote login
ftpfile transfer protocol client

User and group management

commanddescription
useraddadd a user
usermodmodify a user
userdeldelete a user
groupaddadd a group
groupdeldelete a group
passwdmodify the user password
chagechange password expiry information
whoamiprint the current logged in user
whoshow who is logged in
wshow who is logged in and what they are doing
iddisplay the user and group id
groupsshow the user’s groups

System information and monitoring

commanddescription
unameprint system information
hostnameshow or set the system’s hostname
uptimehow long the system has been running
dmesgboot and system messages
freedisplay memory usage
topdisplay linux tasks
vmstatreport virtual memory statistics
lscpudisplay information about the CPU architecture
lsusblist USB devices
lspcilist PCI devices
lshwlist hardware configuration

Archiving and compression

commanddescription
tararchive 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
zippackage and compress files into a ZIP archive
unzipextract files from a ZIP archive
gzipcompress files using the gzip algorithm
gunzipdecompress files compressed with gzip
bzip2compress files using the bzip2 algorithm
bunzip2decompress files compressed with bzip2
xzcompress files using the xz algorithm
unxzdecompress files compressed with xz

Package Management

Debian based (like Ubuntu)

commanddescription
apt-getAPT 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-cachequery APT cache
apt-cache search packagename → search for a package
apt-cache show packagename → show package details

Red Hat based (like Centos, Fedora)

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

General

commanddescription
rpmRPM package manager
rpm -i packagename.rpm → install an RPM package
rpm -e packagename → remove an RPM package
dpkgDebian package manager
dpkg -i packagename.deb → install a Debian package
dpkg -r packagename → remove a Debian package

System services and daemon management

commanddescription
systemctlcontrol 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
serviceolder 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

commanddescription
crondaemon 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
atrun commands at a specified time
at 06:00 → schedule a command to run at 6:00 o’clock
batchrun commands when the system load is low
sleepdelay for a specified time
sleep 6s → sleep for 6 seconds

File permissions and security

commanddescription
chmodchange file permissions
chownchange file owner and group
chgrpchange the group ownership of a file
umaskset default permissions for new files
setfaclset file access control lists (ACL)
getfaclget file access control lists
sudoexecute a command as another user (usually root)
visudoedit the sudoers file safely
passwdchange a user’s password
sudoersmanage sudo access for users
gpasswdadminister group password
ssdisplay socket statistics (for secure network connections)

System backup and restore

commanddescription
rsyncremote file and directory synchronization
rsync -avz source destination → synchronize files
rsync -avz -e ssh source user@remote:/destination/ → sync over SSH
cpiocopy files to and from archives
ddlow-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

commanddescription
dmesgprint the kernel ring buffer messages
system boot and hardware related messages
journalctlquery and view logs from systemd’s jourmal
stracetrace system calls and signals
strace commandname → trace a command’s system call
lsoflist open files
lsof files → show processes using a specific file
vmstatreport virtual memory statistics
iostatreport CPU and I/O statistics
mpstatreport CPU usage statistics
pidstatreport statistics by process
freedisplay memory usage
uptimehow long the system has been running
watchexecute a program periodically – showing output
watch -n 1 free → watch memory usage every second
lshwlist hardware configuration
htopinteractive process viewer
netstatnetwork statistics (replaced by ss)
ssshow socket statistics

Networking & Remote Management

commanddescription
ifconfigconfigure network interfaces (replaced by ip)
ipa 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
ssshow socket statistics
nmapnetwork exploration tool
telnetuser interface to the telnet protocol
ncnetwork 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
iptablesadministration tool for IPv4 packet filtering and NAT
firewalldfrontend for managing firewall rules (Fedora/CentOS)
ufwuncomplicated firewall
ufw enable → enable firewall
ufw allow port → allow traffic on a specific port
tcpdumpcommand line packet analyzer
curltransfer data from or to a server using various protocols
wgetdownload files from the web
scpsecure copy over SSH
scp test.txt user@remotemachine:/path → copy file to remote machine
rsyncremote file and directory synchronization
rsync -avz /path/ remotemachine:/path → sync directories between 2 machines

Text Processing Utilities

commanddescription
grepsearch for patterns within files
grep ‘pattern’ file.txt → search for a pattern in a file
grep -r ‘pattern’ /dirname/ → recursively search for a pattern
sedstream editor for filtering and transforming text
sed ‘s/old/ne/g’ file.txt → replace old by new globally
awka powerful text processing language
awk ‘{print $1} file.txt → print the first column of each line in a file
cutremove sections from each line of a file
cut -d ‘:’ -f 1 /etc/passwd → print the first field of each line delimited by “:”
sortsort lines of text files
sort file.txt → sort file content in ascending order
uniqreport or omit repeated lines in a file
sort file.txt | uniq → sort an remove duplicate lines
teeread from standard input and write to standard output and files
echo “text” | tee file.txt → write to file and show output on screen
trtranslate or delete characters
echo “hello” | tr ‘a-z’ ‘A-Z’ → convert lowercase to upercase letters
pastemerge lines of files
paste file1.txt file2.txt → combine lines of file1 and file2 side by side
wcword, 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

commanddescription
shutdownshut 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
rebootreboot the system
halthalt the system immediately
poweroffpower off the system
initchange the runlevel (old-style system manager)
init 0 → shutdown
init 6 → reboot

File system mounting and management

commanddescription
mountmount a file system
mount /dev/sda1 /mnt → mount partition to a directory
umountumount a file system
umount /mnt → unmount the file system mounted at /mnt
fstabfile system table
configuration file for mounting file systems
blkiddisplay block device attributes
fsckcheck and repair a file system
fsck /dev/sda1 → check and repair /dev/sda1

Filesystem permissions and security

commanddescription
chmodchange file permissions
chmod 755 file.txt → give read write and execute permissions to owner
and read/execute permissions to others
chownchange file owner and group
chown user:group file.txt → change owner and group of a file
chgrpchange group ownership of a file
chgrp group file.txt → change the group of a file
umaskset default permissions for new files
umask 022 → set default permissions for newly created files to 755
setfackset access control lists (ACL) for file permissions
getfaclget access control lists (ACL) for file permissions

Docker (containerization and orchestration)

commanddescription
dockerdocker command line (CLI) for managing containers
docker run imagerun a container from an image
docker pslist running containers
docker ps -alist all containers including stopped ones
docker build -t imagename .build an image from a dockerfile
docker exec -it container_id bashstart an interactive bash shell inside a running container
docker stop container_idstop a container
docker rm container_idremove a container
docker logs container_idview logs of a container
dock imageslist available images
docker rmi imagenameremove an image
docker network lslist docker networks
docker-composemanage multi-container docker applications
docker-compose upstart up a multi-container environment
docker compose downstop and remove containers created by docker-compose
docker-compose logsview logs from containers managed by docker-compose

Kubernetes (k8s) (containerization and orchestration)

commanddescription
kubectlcommand line tool for interacting with Kubernetes clusters
kubectl get podslist pods in the current namespace
kubectl get nodeslist nodes in the cluster
kubectl get serviceslist services in the cluster
kubectl apply -f file.yamlapply configuration from a file
kubectl create -f file.yamlcreate a resource from a file
kubectl delete -f file.yamldelete a ressource defined in a file
kubectl exec -it podname –bashexecute a command inside a pod (ex. open a shell)
kubectl logs podnameview the logs of a pod
kubectl describe pod podnameget detailed information about a pod
kubectl scale deployment deploymentname –replicas=numberscale a deployment to the desired number of replicas
kubectl rollout restart deployment deploymentnamerestart a deployment
kubectl port-forward pod podname localport:remoteportforward a port from a pod to localhost

Helm (containerization and orchestration)

commanddescription
helmKubernetes package manager for deploying applications
helm install releasename chartnameinstall a helm chart
helm upgrade releasename chartnameupgrade a helm release
helm listlist all helm releases
helm delete releasenamedelete a helm release
helm search chartnamesearch for a helm chart

Automation and configuration management

Ansible

commanddescription
ansibleautomation tool for configuration management
ansible all -m pingping all hosts defined in the inventory
ansible-playbook playbook.ymlrun an ansible playbook
ansible -m command -a ‘command’ hostrun a single command on a target host
ansible-playbook –check playbook.ymldry run a playbook to see what would change
ansible-playbook –limit host playbook.ymlrun a playbook on a specific host or group
ansible-playbook –extra-vars “key=value”pass extra variables to a playbook

Terraform

commanddescription
terraforminfrastructure as code tool for provisioning and managing cloud ressources
terraform initinitialize a working directory for terraform configuration
terraform planshow an execution plan (what changes would be made)
terraform applyapply the changes described in a terraform configuration
terraform destroydestroy infrastructure created by terraform
terraform validatevalidate the configuration files
terraform showshow the current state of the infrastructure

Puppet

commanddescription
puppetconfiguration management tool
puppet apply manifest.ppapply a puppet manifest locally
puppet agent —testtest the puppet agent
puppet resourceshow the current state of resources
(files, services, etc.)

CI/CD tools and commands

Jenkins

commanddescription
jenkinscontinous integration tool
java -jar jenkins.warstart jenkins from a war file
access jenkins trough http://localhost:8080 by default

GitLab CI

commanddescription
.gitlab-ci.ymlconfiguration file for GitLab CI/CD pipelines
gitlab-runner registerregister a new runner with GitLab
gitlab-runner runrun the Gitlab Runner to process jobs

GitHub Actions

commanddescription
InfoGitHub Actions uses YAML configuration files
typically located in .github/workflows/
actions/checkout@v2checkout the repository code in your CI pipeline
actions/setup-node@v2setup Node.JS for use in a pipeline
docker/setup-buildx-action@v1set up docker buildx for building multi platform images

Cloud Services

AWS CLI (Amazon Web Services)

commanddescription
awscommand line tool for managing AWS services
aws configureconfigure AWS CLI with your credentials
aws s3 cp file.txt s3://bucketname/copy a file to an S3 bucket
aws ec2 describe-instancesdescripe EC2 instances
aws ec2 start-instances –instance-ids idstart an EC2 instance
aws ec2 stop-instances –instance-ids idstop an EC2 instance
aws s3 syncsync directories with an S3 bucket

Azure CLI (Microsoft)

commanddescription
azcommand line tool for managing Azure services
az loginlog in to your Azure account
az vm listlist all virtual machines
az vm start –name vmname –resource-group resourcegroupstart an Azure VM
az storage blob uploadupload files to an Azure blob storage
az group createcreate a new resource group in Azure AD

Google Cloud SDK

commanddescription
gcloudcommand line tool for Google cloud platform
gcloud auth loginlog in to Google cloud
gcloud compute instances listlist compute instances
gcloud compute instances stop instancenamestop a Google cloud VM instance
gcloud ap browseopen the current Google app engine application in a browser

Logging and Monitoring

Prometheus

commanddescription
prometheusopen source system monitoring and alerting toolkit
start prometheus server (usually as a background service)
prometheus –config.file=configfilestart prometheus with a specific config file

Grafana

commanddescription
grafana-clicommand line interface for managing Grafana plugins
grafana-cli plugins install pluginnameinstall a plugin in Grafana

ELK Stack (Elasticsearch, Logstash, Kibana)

commanddescription
elasticsearchsearch engine for logging and data analytics
curl -XGET ‘localhost:9200/_cluster/health?pretty’get cluster health status
logstashserver side data processing pipeline
logstash -f configfilerun logstash with the specified configuration file
kibanaweb interface for visualizing Elasticsearch data
Kibana is generally access through web on http://localhost:5601
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments