1 – SYSTEM INFORMATION
uname -a# Display Linux system informationuname -r# Display kernel release informationcat /etc/redhat-release# Show which version of Red Hat installeduptime# Show how long the system has been running + loadhostname# Show system host namehostname -I# Display all local IP addresses of the hostlast reboot# Show system reboot historydate# Show the current date and timecal# Show this month’s calendarw# Display who is onlinewhoami# Who you are logged in as
2 – HARDWARE INFORMATION
dmesg# Display messages in kernel ring buffercat /proc/cpuinfo# Display CPU informationcat /proc/meminfo# Display memory informationfree -h# Display free and used memory ( -h for human readable,-m for MB, -g for GB.)lspci -tv# Display PCI deviceslsusb -tv# Display USB devicesdmidecode# Display DMI/SMBIOS (hardware info) from the BIOShdparm -i /dev/sda# Show info about disk sdahdparm -tT /dev/sda# Perform a read speed test on disk sdabadblocks -s /dev/sda# Test for unreadable blocks on disk sdaLINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com2
3 – PERFORMANCE MONITORING AND STATISTICS
top# Display and manage the top processeshtop# Interactive process viewer (top alternative)mpstat 1# Display processor related statisticsvmstat 1# Display virtual memory statisticsiostat 1# Display I/O statisticstail -100 /var/log/messages# Display the last 100 syslog messages (Use/var/log/syslog for Debian based systems.)tcpdump -i eth0# Capture and display all packets on interface eth0tcpdump -i eth0 ‘port 80’# Monitor all traffic on port 80 ( HTTP )lsof# List all open files on the systemlsof -u user# List files opened by userfree -h# Display free and used memory ( -h for humanreadable, -m for MB, -g for GB.)watch df -h# Execute “df -h”, showing periodic updates
4 – USER INFORMATION AND MANAGEMENTid# Display the user and group ids of yourcurrent user.last# Display the last users who have logged ontothe system.who# Show who is logged into the system.w# Show who is logged in and what they aredoing.groupadd test# Create a group named “test”.useradd -c “John Smith” -m john# Create an account named john, with acomment of “John Smith” and create the user’shome directory.userdel john# Delete the john account.usermod -aG sales john# Add the john account to the sales groupLINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com3
5 – FILE AND DIRECTORY COMMANDSls -al# List all files in a long listing (detailed) formatpwd# Display the present working directorymkdir directory# Create a directoryrm file# Remove (delete) filerm -r directory# Remove the directory and its contentsrecursivelyrm -f file# Force removal of file without prompting forconfirmationrm -rf directory# Forcefully remove directory recursivelycp file1 file2# Copy file1 to file2cp -r source_directory destination# Copy source_directory recursively todestination. If destination exists, copysource_directory into destination,otherwise create destination with thecontents of source_directory.mv file1 file2# Rename or move file1 to file2. If file2 isan existing directory, move file1 into directoryfile2ln -s /path/to/file linkname# Create symbolic link to linknametouch file# Create an empty file or update the accessand modification times of file.cat file# View the contents of fileless file# Browse through a text filehead file# Display the first 10 lines of filetail file# Display the last 10 lines of filetail -f file# Display the last 10 lines of file and “follow”the file as it grows.LINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com4
6 – PROCESS MANAGEMENT
ps# Display your currently running processesps -ef# Display all the currently running processes on thesystem.ps -ef | grep processname# Display process information for processnametop# Display and manage the top processeshtop# Interactive process viewer (top alternative)kill pid# Kill process with process ID of pidkillall processname# Kill all processes named processnameprogram &# Start program in the backgroundbg# Display stopped or background jobsfg# Brings the most recent background job toforegroundfg n# Brings job n to the foreground
7 – FILE PERMISSIONS
PERMISSION EXAMPLE U G W rwx rwx rwx chmod 777 filename # Use sparingly! rwx rwx r-x chmod 775 filename rwx r-x r-x chmod 755 filename rw- rw- r– chmod 664 filename rw- r– r– chmod 644 filenameLINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com5
LEGEND U = User G = Group W = World r = Read w = write x = execute – = no access
8 – NETWORKING
ip a# Display all network interfaces and IP addressip addr show dev eth0# Display eth0 address and detailsethtool eth0# Query or control network driver and hardware settingsping host# Send ICMP echo request to hostwhois domain# Display whois information for domaindig domain# Display DNS information for domaindig -x IP_ADDRESS# Reverse lookup of IP_ADDRESShost domain# Display DNS IP address for domainhostname -i# Display the network address of the host name.hostname -I# Display all local IP addresses of the host.wget http://domain.com/file# Download http://domain.com/filenetstat -nutlp# Display listening tcp and udp ports and correspondingprograms
9 – ARCHIVES (TAR FILES)
tar cf archive.tar directory# Create tar named archive.tar containingdirectory.tar xf archive.tar# Extract the contents from archive.tar.tar czf archive.tar.gz directory# Create a gzip compressed tar file namearchive.tar.gz.LINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com6
tar xzf archive.tar.gz# Extract a gzip compressed tar file.tar cjf archive.tar.bz2 directory# Create a tar file with bzip2 compressiontar xjf archive.tar.bz2# Extract a bzip2 compressed tar file.
10 – INSTALLING PACKAGES
yum search keyword# Search for a package by keyword.yum install package# Install package.yum info package# Display description and summary informationabout package.rpm -i package.rpm# Install package from local file namedpackage.rpmyum remove package# Remove/uninstall package.tar zxvf sourcecode.tar.gzcd sourcecode./configuremakemake install# Install software from source code.
11 – SEARCH
grep pattern file# Search for pattern in filegrep -r pattern directory# Search recursively for pattern in directorylocate name# Find files and directories by namefind /home/john -name ‘prefix*’# Find files in /home/john that start with “prefix”.find /home -size +100M# Find files larger than 100MB in /home
12 – SSH LOGINS
ssh host# Connect to host as your local username.ssh user@host# Connect to host as userssh -p port user@host# Connect to host using portLINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com7
13 – FILE TRANSFERS
scp file.txt server:/tmp# Secure copy file.txt to the /tmp folder onserverscp server:/var/www/*.html /tmp# Copy *.html files from server to the local/tmp folder.scp -r server:/var/www /tmp# Copy all files and directories recursively fromserver to the current system’s /tmp folder.rsync -a /home /backups/# Synchronize /home to /backups/homersync -avz /home server:/backups/# Synchronize files/directories between the localand remote system with compression enabled
14 – DISK USAGE
df -h# Show free and used space on mounted filesystemsdf -i# Show free and used inodes on mounted filesystemsfdisk -l# Display disks partitions sizes and typesdu -ah# Display disk usage for all files and directories inhuman readable formatdu -sh# Display total disk usage off the current directory
15 – DIRECTORY NAVIGATION
cd ..# To go up one level of the directory tree. (Change intothe parent directory.)cd# Go to the $HOME directorycd /etc# Change to the /etc directoryLINUX COMMAND LINE CHEAT SHEET https://www.LinuxTrainingAcademy.com8