Showing 122 commands
lsList directory contentsls -lals -lhSls -lt --color=autocpCopy files and directoriescp file.txt backup.txtcp -r src/ dest/cp -p file.txt /backup/mvMove or rename files and directoriesmv old.txt new.txtmv file.txt /target/dir/mv -i src destrmRemove files or directoriesrm file.txtrm -rf directory/rm -i *.logmkdirCreate directoriesmkdir new_dirmkdir -p parent/child/grandchildmkdir -m 755 secure_dirrmdirRemove empty directoriesrmdir empty_dirrmdir -p a/b/ctouchCreate empty files or update timestampstouch newfile.txttouch -t 202301011200 file.txttouch -r ref.txt target.txtfindSearch for files in a directory hierarchyfind / -name '*.conf'find . -type f -mtime -7find . -size +100M -exec rm {} \;locateFind files by name using a prebuilt databaselocate nginx.conflocate -i READMEchmodChange file permissionschmod 755 script.shchmod +x script.shchmod -R 644 /var/www/chownChange file owner and groupchown user:group file.txtchown -R www-data:www-data /var/www/chown --reference=ref.txt target.txtchgrpChange group ownership of fileschgrp developers project/chgrp -R staff /shared/lnCreate hard and symbolic linksln -s /path/to/target link_nameln file.txt hardlink.txtln -sf /new/target link_namestatDisplay detailed file or filesystem statusstat file.txtstat -f /fileDetermine file typefile image.pngfile -i document.pdfcatConcatenate and display file contentscat file.txtcat -n file.txtcat file1.txt file2.txt > merged.txtlessView file contents page by pageless /var/log/syslogless -N file.txtmoreView file contents one screen at a timemore file.txtdmesg | moreheadOutput the first part of fileshead -n 20 file.txthead -c 100 file.txttailOutput the last part of filestail -n 50 file.txttail -f /var/log/syslogtail -f --pid=1234 logfilegrepSearch text using patternsgrep 'error' /var/log/sysloggrep -rni 'TODO' ./src/grep -E '^[0-9]+' file.txtsedStream editor for text transformationssed 's/old/new/g' file.txtsed -i '5d' file.txtsed -n '10,20p' file.txtawkPattern scanning and text processing languageawk '{print $1, $3}' file.txtawk -F: '{print $1}' /etc/passwdawk '/error/{count++} END{print count}' logsortSort lines of text filessort file.txtsort -n -r numbers.txtsort -t, -k2 data.csvuniqReport or omit repeated linessort file.txt | uniqsort file.txt | uniq -csort file.txt | uniq -dwcCount lines, words, and byteswc -l file.txtwc -w file.txtfind . -name '*.py' | wc -lcutRemove sections from each line of filescut -d: -f1 /etc/passwdcut -c1-10 file.txttrTranslate or delete charactersecho 'hello' | tr a-z A-Ztr -d '\n' < file.txttr -s ' ' < file.txtdiffCompare files line by linediff file1.txt file2.txtdiff -u old.txt new.txtdiff -r dir1/ dir2/teeRead from stdin and write to stdout and filesecho 'log entry' | tee output.logmake 2>&1 | tee build.logecho 'line' | tee -a file.txtunamePrint system informationuname -auname -rhostnameShow or set the system hostnamehostnamehostname -IuptimeShow how long the system has been runninguptimeuptime -pwhoamiPrint the current usernamewhoamiidPrint user and group IDsidid -uid usernamedfReport filesystem disk space usagedf -hdf -Tdf -h /homeduEstimate file space usagedu -sh *du -h --max-depth=1 /vardu -sh /home/user/freeDisplay memory usagefree -hfree -mtopDisplay real-time process informationtoptop -bn1 | head -20htopInteractive process viewer (enhanced top)htophtop -u usernamelscpuDisplay CPU architecture informationlscpulscpu | grep 'Model name'lsblkList block deviceslsblklsblk -flsusbList USB deviceslsusblsusb -vdmidecodeDMI/SMBIOS hardware informationsudo dmidecode -t memorysudo dmidecode -t biospsReport a snapshot of current processesps auxps aux | grep nginxps -ef --forestkillSend signals to processeskill 1234kill -9 1234kill -HUP 1234killallKill processes by namekillall firefoxkillall -9 python3pkillSignal processes based on name and attributespkill -f 'node server'pkill -u usernameniceRun a command with modified scheduling prioritynice -n 10 ./heavy_task.shnice -n -5 ./important.shreniceAlter priority of running processesrenice +10 -p 1234renice -5 -u usernamenohupRun a command immune to hangupsnohup ./script.sh &nohup ./script.sh > output.log 2>&1 &bgResume a suspended job in the backgroundbg %1fgBring a background job to the foregroundfg %1jobsList active jobs in the current shelljobsjobs -l&Run a command in the background./long_task.sh &sleep 60 && echo done &waitWait for background processes to finishwaitwait 1234ipShow/manipulate routing, devices, and tunnelsip addr showip route showip link set eth0 upifconfigConfigure network interfaces (legacy)ifconfigifconfig eth0 192.168.1.10 netmask 255.255.255.0pingSend ICMP echo requests to hostsping -c 4 google.comping -i 0.5 192.168.1.1tracerouteTrace the route to a network hosttraceroute google.comtraceroute -n 8.8.8.8netstatNetwork statistics (legacy, use ss)netstat -tlnpnetstat -anssSocket statistics (modern netstat replacement)ss -tlnpss -sss -tp state establishedcurlTransfer data from or to a servercurl -I https://example.comcurl -O https://example.com/file.tar.gzcurl -X POST -d '{"key":"val"}' -H 'Content-Type: application/json' http://api/endpointwgetNon-interactive network downloaderwget https://example.com/file.tar.gzwget -r -np https://example.com/docs/wget -c https://example.com/large.isodigDNS lookup utilitydig example.comdig +short example.com Adig @8.8.8.8 example.com MXnslookupQuery DNS name serversnslookup example.comnslookup -type=MX example.comnmapNetwork exploration and port scannernmap -sV 192.168.1.1nmap -p 1-1000 192.168.1.0/24nmap -A target.comiptablesIPv4 packet filter and NAT administrationiptables -L -n -viptables -A INPUT -p tcp --dport 80 -j ACCEPTiptables -A INPUT -s 10.0.0.0/8 -j DROPufwUncomplicated firewall frontend for iptablesufw enableufw allow 22/tcpufw status verboseuseraddCreate a new user accountuseradd -m -s /bin/bash newuseruseradd -G sudo,docker newuseruserdelDelete a user accountuserdel usernameuserdel -r usernameusermodModify a user accountusermod -aG docker usernameusermod -s /bin/zsh usernameusermod -L usernamepasswdChange user passwordpasswdpasswd usernamepasswd -e usernamegroupaddCreate a new groupgroupadd developersgroupadd -g 1500 customgroupsShow group membershipsgroupsgroups usernamesuSwitch user identitysu - usernamesu -c 'command' usernamesudoExecute a command as another user (typically root)sudo commandsudo -u www-data commandsudo -ivisudoSafely edit the sudoers filesudo visudosudo visudo -f /etc/sudoers.d/customaptDebian/Ubuntu package managersudo apt update && sudo apt upgradesudo apt install nginxapt search keywordyumRHEL/CentOS package manager (legacy)sudo yum install httpdyum list installeddnfFedora/RHEL 8+ package managersudo dnf install nginxdnf search keywordsudo dnf upgrade --refreshpacmanArch Linux package managersudo pacman -Syusudo pacman -S packagepacman -Ss keywordapkAlpine Linux package managerapk add nginxapk update && apk upgradesnapSnap package managersudo snap install code --classicsnap listflatpakFlatpak application managerflatpak install flathub org.gimp.GIMPflatpak listdpkgLow-level Debian package managersudo dpkg -i package.debdpkg -l | grep nginxrpmLow-level RPM package managersudo rpm -ivh package.rpmrpm -qa | grep httpdmountMount a filesystemmount /dev/sdb1 /mnt/usbmount -o loop image.iso /mnt/isomount | column -tumountUnmount a filesystemumount /mnt/usbumount -l /mnt/busyfdiskPartition table manipulatorsudo fdisk -lsudo fdisk /dev/sdbmkfsBuild a Linux filesystemsudo mkfs.ext4 /dev/sdb1sudo mkfs.xfs /dev/sdb1lsblkList information about block deviceslsblklsblk -fblkidLocate/print block device attributesblkidblkid /dev/sda1ddConvert and copy a file (low-level)dd if=/dev/sda of=backup.img bs=4M status=progressdd if=ubuntu.iso of=/dev/sdb bs=4M status=progressrsyncFast, versatile file copying toolrsync -avz src/ dest/rsync -avz -e ssh /local/ user@host:/remote/rsync -avz --delete src/ dest/scpSecure copy over SSHscp file.txt user@host:/path/scp -r user@host:/remote/dir/ ./local/tarArchive utilitytar -czvf archive.tar.gz /path/to/dirtar -xzvf archive.tar.gztar -tf archive.tar.gzgzipCompress files with gzipgzip file.txtgzip -k file.txtgzip -9 file.txtgunzipDecompress gzip filesgunzip file.txt.gzbzip2Compress files with bzip2bzip2 file.txtbzip2 -dk file.txt.bz2xzCompress files with xz (high ratio)xz file.txtxz -dk file.txt.xzzipPackage and compress fileszip archive.zip file1.txt file2.txtzip -r archive.zip directory/unzipExtract zip archivesunzip archive.zipunzip archive.zip -d /target/dir/unzip -l archive.zip7z7-Zip file archiver (high compression)7z a archive.7z files/7z x archive.7zsshSecure shell remote loginssh user@hostnamessh -p 2222 user@hostnamessh -L 8080:localhost:80 user@hostscpSecure copy files over SSHscp file.txt user@host:/path/scp user@host:/remote/file.txt ./rsyncRemote file synchronization over SSHrsync -avz -e ssh local/ user@host:/remote/rsync -avz user@host:/remote/ ./local/sftpSecure FTP over SSHsftp user@hostnamesftp -P 2222 user@hostnamessh-keygenGenerate SSH key pairsssh-keygen -t ed25519 -C '[email protected]'ssh-keygen -t rsa -b 4096ssh-copy-idCopy SSH public key to a remote hostssh-copy-id user@hostnamessh-copy-id -i ~/.ssh/id_ed25519.pub user@hostssh-agentSSH authentication agenteval $(ssh-agent -s)ssh-add ~/.ssh/id_ed25519systemctlControl systemd services and unitssystemctl status nginxsystemctl start nginxsystemctl enable --now nginxjournalctlQuery the systemd journaljournalctl -u nginx --since '1 hour ago'journalctl -fjournalctl -p err -btimedatectlControl system time and datetimedatectltimedatectl set-timezone America/New_YorkhostnamectlControl the system hostnamehostnamectlhostnamectl set-hostname webserverloginctlControl the systemd login managerloginctl list-sessionsloginctl show-user usernamedocker runCreate and start a containerdocker run -d -p 80:80 nginxdocker run -it --rm ubuntu bashdocker run -v /host:/container -e VAR=val imagedocker psList running containersdocker psdocker ps -adocker ps --format 'table {{.Names}}\t{{.Status}}'docker buildBuild an image from a Dockerfiledocker build -t myapp:latest .docker build --no-cache -t myapp .docker build -f Dockerfile.prod -t myapp:prod .docker execRun a command in a running containerdocker exec -it container_name bashdocker exec container_name ls /appdocker logsFetch logs from a containerdocker logs container_namedocker logs -f --tail 100 container_namedocker-composeDefine and run multi-container applicationsdocker-compose up -ddocker-compose down -vdocker-compose logs -f service_name