SJ LinuxCommandsCheatSheet Searching Hardware Information File Commands System Management and Info Disk Usage dmesg Show bootup messages grep [pattern] [file] Search for a pattern in a file ls List files in the directory uname -r Show system information df -h Show free space on system cat /proc/cpuinfo Show CPU information grep -r [pattern] [directory] Search a pattern recursively ls -a List files, include hidden files uname -a Show kernel release info df -l Show free nodes on system free -h Show free and used memory locate [name] Search for files & directories pwd Show current directory uptime Show uptime length/avg. load fdisk -l Disk partition types and sizes lshw Hardware configuration info find [/location] -name [x] List items beginning with [x] mkdir [name] Create a directory hostname Show system hostname du -ah Show disk usage for all files lsblk Block devices info find [/location] -size [+100M] List items larger than 100MB rm [file] Remove a file hostname -l Show system IP address du -sh Show disk usage for current directory lspci -tv Tree-diagram of PCI devices rm -r [directory] Recursively remove directory last reboot Show reboot history findmnt Show target mount point mount [device] [mount_point] Mount a device lsusb -tv File Transfer Tree-diagram of USB devices dmidecode Show BIOS hardware info hdparm -i /dev/[disk] Show disk data info hdparm -tT /dev/[disk] Disk read speed test badblocks -s /dev/[disk] Unreadable blocks test scp [file.txt] [server/tmp] Securely copy file to server rsync -a [/location] [/backup/] Sync the contents of a location with the backup directory Process Related File Compression tar cf [file.tar] [file] whoami Show current user ln -s [/path/file] [link] Create a symbolic link to file finger [username] Show user information let "[variable]=[value]" Assign integer value to var touch [file] Create a new file ulimit [flags] [limit] View or limit system resources export [variable] Export a Bash variable more [file] Show file contents shutdown [hh:mm] Schedule a system shut down declare [variable]="[value]" Declare a Bash variable echo $[variable] Display value of the variable pmap Show process memory usage gpg -c [file] Encrypt a file top Show all running processes gpg [file.gpg] Decrypt a file kill [process_id] Kill the process by ID wc Count words/lines/bytes pkill [process_name] Kill the process by name killall [process_name] Kill all processes by name fg [job] Bring [job] to foreground Install a package with DNF List files opened by processes lsof Install a local rpm package trap "[commands]" [signal] Execute command on signal Remove an rpm package wait Pause terminal until process completes Install a package with APT nohup [command] & ls | xargs wc cut -d[delimiter] [file] [data] | cut -d[delimiter] awk '[pattern] {print $0}' [file] shred -u [file] Cut file section and print ip addr show Show IP addresses alias [alias]='[command]' Create command alias ip address add [ip] Assign IP address to interface watch -n [interval] [command] Set interval to run a command ifconfig Show all network interfaces sleep [interval] && [command] Postpone command execution netstat -pnltu Show active listening ports at [hh:mm] Schedule a job netstat -nutlp Show tcp and udp ports man [command] Display command manual whois [domain] Show domain information history Print command history dig [domain] Show domain's DNS info dig -x [host] Domain reverse lookup dig -x [ip] IP address reverse lookup Cut data section and print Print lines matching a pattern Overwrite and delete a file diff [file1] [file2] Compare two files source [file] Compile from source code [command] | tee [filename] >/ dev/null Store command output to a file, skip terminal output host [domain] Run a process in background File Permission Shell Command Management Network Management Words/lines/bytes in directory Users and Groups Keyboard Shortcuts Ctrl + C Kill current process Ctrl + Z Stop process (can be resumed) Ctrl + W Cut the word before the cursor Ctrl + U Cut part of the line before the cursor Ctrl + K Cut part of the line after the cursor Ctrl + Y Paste from clipboard Ctrl + R Recall last command IP lookup for a domain hostname -l Show local IP address wget [file_url] Download a file from url id Show active user details last Show last system logins who Show who is logged in w Show logged users and activity groupadd [group] Add a new group Full permission to owner, read and write for others adduser [user] Add a new user cd .. Move up one level Ctrl + O Run the recalled command chown [user] [file] Change file ownership usermod -aG [group] [user] Add user to group cd Change directory to $HOME Ctrl + G Exit command history chown [user]:[group] [file] Change file owner and group userdel [user] Delete a user cd [/location] Change to specified directory !! Repeat the last command usermod Modify user information exit Log out of the session chgrp [group] [directory] Change directory group chmod 777 [file] SSH Login chmod 755 [file] telnet [host] Rename a file Add a new kernel module Install a package with YUM ssh -p [port] [user]@[host] mv [filename1] [filename2] modprobe [module-name] yum install [package.rpm] Connect to host as user Connect to host via port 22 Variables Show last 10 lines of a file Most recent suspended job to foreground ssh [host] Show current day and month tail [file] fg ssh [user]@[host] cal Show processes as a tree Package info & summary Install software from source code Copy directory1 to directory2 pstree yum info [package] tar zxvf [source_code.tar.gz] cd [source_code] ./configure make make install cp -r [directory1] [directory2] List variables and functions List background processes apt install [package] Manage the system clock set bg rpm -e [package.rpm] timedatectl Shut down immediately Find a package by a keyword rpm -i [package.rpm] Copy file1 to file2 shutdown now yum search [keyword] dnf install [package.rpm] cp [file1] [file2] Show first 10 lines of a file Create a gz compressed file Package Installation Show current time and date head [file] Create a gzip tar file gzip [file] date Show active process snapshot Extract archived file tar czf [file.tar.gz] Force remove directory ps Create a tar file from a file tar xf [file.tar] rm -rf [directory] chmod 766 [file] File read, write, execute permissions to everyone Full permission to owner, read permissions for others Use a non-default port Connect to Telnet via port 23 curl -O [file_url] Download a file from url nslookup [domain] Show domain information Directory Navigation