Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Linux Commands Cheat Sheet

Did you know that there are literally hundreds of Linux commands? Even on a bare-bones Linux server install there are easily over 1,000 different commands.

The interesting thing is that most people only need to use a very small subset of those commands. Below you’ll find a Linux “cheat sheet” that breaks down some of the most commonly used commands by category.

To get your own PDF and printable copy, scroll to the bottom of the page.

Enjoy!

1 – SYSTEM INFORMATION

# Display Linux system informationuname -a# Display kernel release informationuname -r# Show operating system information such as distribution name and versioncat /etc/os-release# Show how long the system has been running + loaduptime# Show system host namehostname# Display all local IP addresses of the host.hostname -I# Show system reboot historylast reboot# Show the current date and timedate# Show this month's calendarcal# Display who is onlinew# Who you are logged in aswhoami

2 – HARDWARE INFORMATION

# Display messages in kernel ring bufferdmesg# Display CPU informationcat /proc/cpuinfo# Display memory informationcat /proc/meminfo# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)free -h# Display PCI deviceslspci -tv# Display USB deviceslsusb -tv# Display DMI/SMBIOS (hardware info) from the BIOSdmidecode# Show info about disk sdahdparm -i /dev/sda# Perform a read speed test on disk sdahdparm -tT /dev/sda# Test for unreadable blocks on disk sdabadblocks -s /dev/sda

3 – PERFORMANCE MONITORING AND STATISTICS

# Display and manage the top processestop# Interactive process viewer (top alternative)htop# Display processor related statisticsmpstat 1# Display virtual memory statisticsvmstat 1# Display I/O statisticsiostat 1# Display the last 100 syslog messages  (Use /var/log/syslog for Debian based systems.)tail -100 /var/log/messages# Capture and display all packets on interface eth0tcpdump -i eth0# Monitor all traffic on port 80 ( HTTP )tcpdump -i eth0 'port 80'# List all open files on the systemlsof# List files opened by userlsof -u user# Display free and used memory ( -h for human readable, -m for MB, -g for GB.)free -h# Execute "df -h", showing periodic updateswatch df -h

4 – USER INFORMATION AND MANAGEMENT

# Display the user and group ids of your current user.id# Display the last users who have logged onto the system.last# Show who is logged into the system.who# Show who is logged in and what they are doing.w# Create a group named "test".groupadd test# Create an account named john, with a comment of "John Smith" and create the user's home directory.useradd -c "John Smith" -m john# Delete the john account.userdel john# Add the john account to the sales groupusermod -aG sales john

5 – FILE AND DIRECTORY COMMANDS

# List all files in a long listing (detailed) formatls -al# Display the present working directorypwd# Create a directorymkdir directory# Remove (delete) filerm file# Remove the directory and its contents recursivelyrm -r directory# Force removal of file without prompting for confirmationrm -f file# Forcefully remove directory recursivelyrm -rf directory# Copy file1 to file2cp file1 file2# Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directory.cp -r source_directory destination# Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2mv file1 file2# Create symbolic link to linknameln -s /path/to/file linkname# Create an empty file or update the access and modification times of file.touch file# View the contents of filecat file# Browse through a text fileless file# Display the first 10 lines of filehead file# Display the last 10 lines of filetail file# Display the last 10 lines of file and "follow" the file as it grows.tail -f file

6 – PROCESS MANAGEMENT

# Display your currently running processesps# Display all the currently running processes on the system.ps -ef# Display process information for processnameps -ef | grep processname# Display and manage the top processestop# Interactive process viewer (top alternative)htop# Kill process with process ID of pidkill pid# Kill all processes named processnamekillall processname# Start program in the backgroundprogram &# Display stopped or background jobsbg# Brings the most recent background job to foregroundfg# Brings job n to the foregroundfg n

7 – FILE PERMISSIONS

Linux chmod example        PERMISSION      EXAMPLE         U   G   W        rwx rwx rwx     chmod 777 filename        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 filename# NOTE: Use 777 sparingly!        LEGEND        U = User        G = Group        W = World        r = Read        w = write        x = execute        - = no access

8 – NETWORKING

# Display all network interfaces and IP addressip a# Display eth0 address and detailsip addr show dev eth0# Query or control network driver and hardware settingsethtool eth0# Send ICMP echo request to hostping host# Display whois information for domainwhois domain# Display DNS information for domaindig domain# Reverse lookup of IP_ADDRESSdig -x IP_ADDRESS# Display DNS IP address for domainhost domain# Display the network address of the host name.hostname -i# Display all local IP addresses of the host.hostname -I# Download http://domain.com/filewget http://domain.com/file# Display listening tcp and udp ports and corresponding programsnetstat -nutlp

9 – ARCHIVES (TAR FILES)

# Create tar named archive.tar containing directory.tar cf archive.tar directory# Extract the contents from archive.tar.tar xf archive.tar# Create a gzip compressed tar file name archive.tar.gz.tar czf archive.tar.gz directory# Extract a gzip compressed tar file.tar xzf archive.tar.gz# Create a tar file with bzip2 compressiontar cjf archive.tar.bz2 directory# Extract a bzip2 compressed tar file.tar xjf archive.tar.bz2

10 – INSTALLING PACKAGES

# Search for a package by keyword.yum search keyword# Install package.yum install package# Display description and summary information about package.yum info package# Install package from local file named package.rpmrpm -i package.rpm# Remove/uninstall package.yum remove package# Install software from source code.tar zxvf sourcecode.tar.gzcd sourcecode./configuremakemake install

11 – SEARCH

# Search for pattern in filegrep pattern file# Search recursively for pattern in directorygrep -r pattern directory# Find files and directories by namelocate name# Find files in /home/john that start with "prefix".find /home/john -name 'prefix*'# Find files larger than 100MB in /homefind /home -size +100M

12 – SSH LOGINS

# Connect to host as your local username.ssh host# Connect to host as userssh user@host# Connect to host using portssh -p port user@host

13 – FILE TRANSFERS

# Secure copy file.txt to the /tmp folder on serverscp file.txt server:/tmp# Copy *.html files from server to the local /tmp folder.scp server:/var/www/*.html /tmp# Copy all files and directories recursively from server to the current system's /tmp folder.scp -r server:/var/www /tmp# Synchronize /home to /backups/homersync -a /home /backups/# Synchronize files/directories between the local and remote system with compression enabledrsync -avz /home server:/backups/

14 – DISK USAGE

# Show free and used space on mounted filesystemsdf -h# Show free and used inodes on mounted filesystemsdf -i# Display disks partitions sizes and typesfdisk -l# Display disk usage for all files and directories in human readable formatdu -ah# Display total disk usage off the current directorydu -sh

15 – DIRECTORY NAVIGATION

# To go up one level of the directory tree.  (Change into the parent directory.)cd ..# Go to the $HOME directorycd# Change to the /etc directorycd /etc

16 – SECURITY

# Change the current user's password.passwd# Switch to the root account with root's environment. (Login shell.)sudo -i# Execute your current shell as root. (Non-login shell.)sudo -s# List sudo privileges for the current user.sudo -l# Edit the sudoers configuration file.visudo# Display the current SELinux mode.getenforce# Display SELinux details such as the current SELinux mode, the configured mode, and the loaded policy.sestatus# Change the current SELinux mode to Permissive. (Does not survive a reboot.)setenforce 0# Change the current SELinux mode to Enforcing. (Does not survive a reboot.)setenforce 1# Set the SELinux mode to enforcing on boot by using this setting in the /etc/selinux/config file.SELINUX=enforcing# Set the SELinux mode to permissive on boot by using this setting in the /etc/selinux/config file.SELINUX=permissive# Set the SELinux mode to disabled on boot by using this setting in the /etc/selinux/config file.SELINUX=disabled

17 – LOGGING AND AUDITING

# Display messages in kernel ring buffer.dmesg# Display logs stored in the systemd journal.journalctl# Display logs for a specific unit (service).journalctl -u servicename

18 – Linux Command Line Cheat Sheet

Download My Linux Cheat Sheet!
Enter your email address below to download this Linux command line cheat sheet in an easy-to-read and ready-to-print format.
We respect your privacy.

Recent Linux Articles

Linux Cheat Sheet Download
Enter your email address below to download this Linux command line cheat sheet in an easy-to-read and ready-to-print format.
Download My Linux Cheat Sheet!
Enter your email address below to download this Linux command line cheat sheet in an easy-to-read and ready-to-print format.
We respect your privacy.

[8]ページ先頭

©2009-2025 Movatter.jp