Linux Important Commands
Commands on Linux-like operating systems are either built-ins or external commands. The former are part of the shell. The latter consist of both executables, which are programs that have been written in a programming language (e.g., C, C++, Java or Python) and then compiled into a binary, and shell scripts.
Note: A command is an instruction given by a user telling a computer to do something, such a run a single program or a group of linked programs.:
# Display Linux system information
uname -a
# Display kernel release information
uname -r
# Show which version of redhat installed
cat /etc/redhat-release
# Show how long the system has been running + load
uptime
# Show system host name
hostname
# Display the IP addresses of the host
hostname -I
# Show system reboot history
last reboot
# Show the current date and time
date
# Show this month's calendar
cal
# Display who is online
w
# Who you are logged in as
whoami
dmesg
# 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
top
# 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
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
ls -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
# Display your currently running processes
ps
# Display all the currently running processes on the system.
ps -ef
# Display process information for processname
ps -ef | grep processname
# Display and manage the top processes
top
# Interactive process viewer (top alternative)
htop
# Kill process with process ID of pid
kill pid
# Kill all processes named processname
killall processname
# Start program in the background
program &
# Display stopped or background jobs
bg
# Brings the most recent background job to foreground
fg
# Brings job n to the foreground
fg n
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!
r = Read
w = write
x = execute
- = no access