0% found this document useful (0 votes)
2 views12 pages

Free Linux Complete Command Notes

The document provides a comprehensive list of command-line commands for various tasks in a Unix/Linux environment, categorized into sections such as navigation, file management, viewing and paging, search and text processing, permissions, processes, system info, networking, archiving, package management, services, environment, containers, cloud CLIs, and shutdown commands. Each command is accompanied by a brief description of its function. This serves as a quick reference guide for users to efficiently utilize command-line operations.

Uploaded by

rishav17062000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Free Linux Complete Command Notes

The document provides a comprehensive list of command-line commands for various tasks in a Unix/Linux environment, categorized into sections such as navigation, file management, viewing and paging, search and text processing, permissions, processes, system info, networking, archiving, package management, services, environment, containers, cloud CLIs, and shutdown commands. Each command is accompanied by a brief description of its function. This serves as a quick reference guide for users to efficiently utilize command-line operations.

Uploaded by

rishav17062000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Navigation

●​ 𝚙𝚠𝚍 — print working directory.​​


●​ ls — list directory contents.​​
●​ ls -la — list all files with details.​​
●​ cd /path — change to path.​​
●​ cd .. — go to parent directory.​​
●​ cd ~ — go to home directory.​​
●​ tree — display directories as a tree.​

Files and directories


●​ touch file.txt — create an empty file or update
timestamp.​​
●​ mkdir dir — create a directory.​​
●​ mkdir -p a/b/c — create nested directories.​​
●​ cp src dst — copy a file or directory.​​
●​ cp -r dir1 dir2 — copy a directory recursively.​​
●​ mv old new — move or rename a file or directory.​​
●​ rm file — remove a file.​​
●​ rm -rf dir — remove a directory tree (use with caution).​​
●​ rmdir emptydir — remove an empty directory.​​
●​ stat file — show file metadata and timestamps.​
●​ basename /path/file — print filename from path.​
●​ dirname /path/file — print directory path from filename.​

Viewing and paging


●​ cat file — print file contents.​​
●​ tac file — print file contents in reverse.​
●​ head -n 20 file — show first 20 lines.​​
●​ tail -n 20 file — show last 20 lines.​​
●​ tail -f logfile — follow file updates (logs).​​
●​ less file — page through a file with search.​​
●​ more file — basic pager for files.​​
●​ nl file — number lines while viewing.​
●​ wc -l file — count lines in a file.​

Search and text processing


●​ grep "pattern" file — search pattern in a file.​
●​ grep -ri "pattern" dir/ — recursive, case-insensitive
search.​
●​ sort file — sort lines in a file.​
●​ uniq file — omit repeated adjacent lines.​
●​ cut -d ':' -f 1 file — select delimited fields.​
●​ awk '{print $1}' file — print the first column.​
●​ sed -i 's/old/new/g' file — in-place find and replace.​
●​ tr 'a-z' 'A-Z' — translate characters (lower to upper).​
●​ paste file1 file2 — merge lines side by side.​
●​ tee out.txt — write output to file and stdout.​

Permissions and ownership


●​ chmod 644 file — set rw-r--r-- permissions.​​
●​ chmod 755 file — set rwxr-xr-x permissions.​​
●​ chmod +x script.sh — make a file executable.​​
●​ chown user:group file — change owner and group.​​
●​ chgrp group file — change group ownership.​​
●​ umask 022 — set default permissions mask.​
●​ getfacl file — view file ACLs.​
●​ setfacl -m u:user:rwx file — set ACL for a user.​

Processes and jobs


●​ ps aux — list all processes with details.​
●​ top — interactive process viewer.​
●​ htop — enhanced process viewer (if installed).​
●​ pgrep name — find PIDs by process name.​
●​ pkill name — send signals by process name.​
●​ kill PID — terminate a process by PID.​
●​ killall name — terminate processes by name.​
●​ nice -n 10 cmd — start with adjusted priority.​
●​ renice -n 10 -p PID — change priority of running process.​
●​ jobs — list shell jobs.​
●​ bg %1 — resume job in background.​
●​ fg %1 — bring job to foreground.​
●​ nohup command & — ignore hangups and run in
background.​
●​ time command — measure execution time.​
●​ watch -n 1 free — rerun a command at intervals.​

System info and logs


●​ uname -a — kernel and system information.​
●​ hostnamectl — view or set hostname.​
●​ uptime — show load averages and uptime.​
●​ free -h — memory and swap usage.​
●​ vmstat — virtual memory statistics.​
●​ iostat — CPU and I/O statistics.​
●​ mpstat — per-CPU usage statistics.​
●​ pidstat — per-process statistics.​
●​ lscpu — CPU architecture details.​
●​ lsusb — list USB devices.​
●​ lspci — list PCI devices.​
●​ lshw — hardware inventory.​
●​ dmesg — kernel ring buffer messages.​
●​ journalctl -xe — view recent critical system logs.​
●​ journalctl -u nginx — view logs for a systemd unit.​

Disks, partitions, and filesystems


●​ df -h — mounted filesystem disk usage.​
●​ du -sh dir/ — directory size summary.​
●​ lsblk — list block devices.​
●​ blkid — print block device attributes.​
●​ fdisk -l — list partition tables.​
●​ parted -l — list partitions with parted.​
●​ mkfs.ext4 /dev/sdX1 — create an ext4 filesystem.​
●​ fsck /dev/sdX1 — check and repair filesystem.​
●​ mount /dev/sdX1 /mnt — mount a partition.​
●​ umount /mnt — unmount a filesystem.​
●​ cat /etc/fstab — view persistent mount table.​
Networking and DNS
●​ ip addr — show IP addresses.​
●​ ip route — show routing table.​
●​ ping -c 4 host — test connectivity.​
●​ traceroute host — trace network path.​
●​ ss -tuln — list listening sockets and ports.​
●​ netstat -tuln — legacy sockets and ports list.​
●​ nslookup example.com — DNS query.​
●​ dig example.com — detailed DNS query.​
●​ curl -I https://example.com — HTTP request.​
●​ wget https://example.com/file — download a file.​
●​ ssh user@host — connect via SSH.​
●​ scp file user@host:/path/ — copy file over SSH.​
●​ sftp user@host — interactive file transfer over SSH.​
●​ nc -l -p 1234 — listen on TCP port.​
●​ nc host 80 — connect to TCP port.​
●​ tcpdump -i eth0 port 443 — capture packets.​
●​ nmap -sS host — scan ports with SYN.​
●​ ufw enable — enable uncomplicated firewall.​
●​ ufw allow 22 — allow SSH.​
●​ iptables -L — list firewall rules.​
●​ firewall-cmd --list-all — show firewalld config.​
Archiving, compression, and sync
●​ tar -czf archive.tar.gz dir/ — create gzip tarball.​
●​ tar -xzf archive.tar.gz — extract gzip tarball.​
●​ tar -cf archive.tar dir/ — create tar archive.​
●​ tar -xf archive.tar — extract tar archive.​
●​ zip -r archive.zip dir/ — create zip archive.​
●​ unzip archive.zip — extract zip archive.​
●​ gzip file — compress with gzip.​
●​ gunzip file.gz — decompress gzip file.​
●​ bzip2 file — compress with bzip2.​
●​ bunzip2 file.bz2 — decompress bzip2 file.​
●​ xz file — compress with xz.​
●​ unxz file.xz — decompress xz file.​
●​ rsync -avz src/ dest/ — sync files locally.​
●​ rsync -avz -e ssh src/ user@host:/dest/ — sync
over SSH.​
●​ cpio -ov < filelist > archive.cpio — create cpio
archive.​
Package management
(Debian/Ubuntu)
●​ apt-get update — refresh package lists.​
●​ apt-get install nginx — install a package.​
●​ apt-get upgrade — upgrade installed packages.​
●​ apt-get remove pkg — remove a package.​
●​ apt-cache search nginx — search packages.​
●​ apt-cache show pkg — show package details.​
●​ dpkg -i pkg.deb — install a .deb file.​
●​ dpkg -r pkg — remove a .deb package.​

Package management
(RHEL/CentOS/Fedora)
●​ yum install pkg — install a package.​
●​ yum update — update packages.​
●​ yum remove pkg — remove a package.​
●​ dnf install pkg — install with dnf.​
●​ dnf update — update with dnf.​
●​ rpm -i pkg.rpm — install an RPM.​
●​ rpm -e pkg — erase an RPM.​
Services and scheduling
●​ systemctl start nginx — start a service.​
●​ systemctl stop nginx — stop a service.​
●​ systemctl restart nginx — restart a service.​
●​ systemctl status nginx — check service status.​
●​ systemctl enable nginx — enable at boot.​
●​ systemctl disable nginx — disable at boot.​
●​ service nginx start — legacy start command.​
●​ service nginx status — legacy status command.​
●​ crontab -e — edit cron jobs.​
●​ crontab -l — list cron jobs.​
●​ crontab -r — remove all cron jobs.​
●​ at 09:00 — schedule one-time job.​
●​ batch — run when load is low.​
●​ sleep 5s — delay for five seconds.​
Environment and shell
●​ env — print environment variables.​​
●​ echo $VAR — print a variable value.​​
●​ export VAR=value — set an environment variable.​​
●​ which command — show command path.​​
●​ history — show command history.​​
●​ alias ll='ls -la' — create a command alias.​​
●​ unalias ll — remove an alias.​​

Containers and orchestration


●​ docker run image — run a container.​
●​ docker ps — list running containers.​
●​ docker ps -a — list all containers.​
●​ docker exec -it container bash — open a shell in a
container.​
●​ docker logs container — show container logs.​
●​ docker build -t image . — build an image.​
●​ docker rmi image — remove an image.​
●​ docker-compose up — start multi-container app.​
●​ docker-compose down — stop and remove app.​
●​ kubectl get pods — list pods.​
●​ kubectl get nodes — list nodes.​
●​ kubectl get services — list services.​
●​ kubectl apply -f file.yaml — apply configuration.​
●​ kubectl logs pod — view pod logs.​
●​ kubectl exec -it pod -- bash — exec into a pod.​
●​ kubectl describe pod podname — describe a pod.​
●​ kubectl scale deployment name --replicas=3 — scale
a deployment.​
●​ kubectl rollout restart deployment name — restart a
deployment.​
●​ helm install release chart — install a Helm chart.​
●​ helm upgrade release chart — upgrade a release.​
●​ helm list — list releases.​
●​ helm delete release — delete a release.​

Cloud CLIs
●​ aws configure — set up AWS CLI credentials.​
●​ aws s3 cp file s3://bucket/ — upload a file to S3.​
●​ aws ec2 describe-instances — list EC2 instances.​
●​ az login — authenticate Azure CLI.​
●​ az vm list — list Azure VMs.​
●​ gcloud auth login — authenticate gcloud.​
●​ gcloud compute instances list — list GCP instances.​
Shutdown and reboot
●​ shutdown -h now — power off immediately.​
●​ shutdown -r now — reboot immediately.​
●​ shutdown -h +10 — schedule power off in 10 minutes.​
●​ reboot — restart the system.​
●​ poweroff — power off the system.​
●​ halt — halt the system.​
●​ init 0 — switch to shutdown runlevel.​
●​ init 6 — switch to reboot runlevel.​

You might also like