Useful commands to look up system information, install package etc. (Linux, Debian, Ubuntu, Kali Linux, RedHat, CentOS etc.)

Last Updated on

System

uname -a               #Show kernel Info/Operating System/CPU Info
head -n 1 /etc/issue   #Show operating system Name
cat /proc/cpuinfo      #Show detail about CPU
hostname               #Show host name
lspci -tv              #List all PCI devices
lsusb -tv              #List all USB devices
lsmod                  #List all loaded kernel modules
env                    #Show environment variables

Processes

top        #Show real-time status of processes
ps -ef     #Show all processes

Services

systemctl list-units                        #List all running services
 systemctl list-units -a                        #List all services, including inactive units
 systemctl list-units -a --state=inactive    #List all inactive units

Users

w                       #Show active users
id <UserName>           #Show info about the user
last                    #Show user login log
cut -d: -f1 /etc/passwd #Show all users
cut -d: -f1 /etc/group  #Show all groups
crontab -l              #Show all cron jobs (Scheduled jobs) for current user

Resources

free -m                       #Show RAM, SWAP usage
df -h                         #Show partition usage
du -sh                        #Show folder/directory size
grep MemTotal /proc/meminfo   #Show total RAM
grep MemFree /proc/meminfo    #Show free/available RAM
uptime                        #Show system uptime, users, load
cat /proc/loadavg             #Show system load

Disk & Partition

mount | column -t    #Show mounted partition info
fdisk -l             #Show all partitions
swapon -s            #Show all swap partition info

Networking

ifconfig        #Show all interface properties
iptables -L     #Show firewall (iptable) configuration
route -n        #Show routing table
netstat -lntp   #Show all listening ports
netstat -antp   #Show all established connections
netstat -s      #Show statistics about Ethernet

apt-get

update            #Update package list
upgrade           #Upgrade packages
install           #Install new packages
remove            #Remove packages
autoremove        #Remove packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed
purge             #Remove package and configuration files
source            #fetch source packages
build-dep         #Install all dependencies for 'packagename'
dist-upgrade      #Upgrade distro
full-upgrade      #Upgrade distro (For newer 'apt')
dselect-upgrade   #Resolves the delta between the currently-installed packages and the states requested in the list of available packages, and performs the necessary actions to reconcile the two.
clean             #Clears out the local repository of retrieved package files
autoclean         #Another method used to clear out the local repository of downloaded package files, just like clean . The difference between clean and autoclean is that the latter only removes package files that can no longer be downloaded from their sources, and are very likely to be useless.
check             #It does an update of the package lists and checks for broken dependencies
-h        #Local help document
-q        #Output to log (Do not indicate progress)
-qq       #Only output errors
-d        #Only download (Do not Extract or Install)
-s        #Simulate the command, does not install the package for real
-y        #Answer Yes for all commands
-f        #Try to fix dependency issues
-m        #Try to continue even the archive can't be located
-u        #Also show the list of upgrade package
-b        #Compile after getting the source (-V to show detailed version number)
-c=?      #Show the configuration file
-o=?      #Set custom/arbitrary configuration e.g. -d dir::cache=/tmp
#Examples
 
apt-cache search PACKAGE                 #Search package
apt-cache show PACKAGE                   #Get details about the package (Manual, size, version etc.)
apt list --installed                     #List all installed packages
apt-get install PACKAGE                  #Install the packag
apt-get install PACKAGE --reinstall      #Reinstall the package
apt-get -f install                       #Repair install (-f = –fix-missing)
apt-get remove PACKAGE                   #Remove package
apt-get remove PACKAGE --purge           #Remove package and configuration files
apt-get update                           #Update source info (repositories and PPAs)
apt-get upgrade                          #Upgrade installed packages
apt-get dist-upgrade                     #Upgrade system
apt full-upgrade                         #Upgrade system (Newer apt)
apt-get dselect-upgrade                  #Use dselect to upgrade
apt-cache depends PACKAGE                #List the dependencies in human form
apt-cache showpkg PACKAGE                #find the details about dependencies with
apt-cache rdepends PACKAGE               #Searches through the APT cache to locate dependencies for an application, and knows how to emulate the results
apt-get build-dep PACKAGE                #Install all dependencies for 'PACKAGE'
apt-get source PACKAGE                   #Download the source for this PACKAGE
apt-get clean                            #Clears out the local repository of retrieved package files
apt-get autoclean                        #Another method used to clear out the local repository of downloaded package files, just like clean . The difference between clean and autoclean is that the latter only removes package files that can no longer be downloaded from their sources, and are very likely to be useless.
apt-get check                            #It does an update of the package lists and checks for broken dependencies

RPM

rpm -qa                                      #List all installed packages
rpm -qpi Linux-1.4-6.i368.rpm                #Show detail about the package
rpm -qpl Linux-1.4-6.i368.rpm                #Show dependencies
rpm -ivh Linux-1.4-6.i368.rpm                #Begin to inatll
rpm -ivh -replacepkgs Linux-1.4-6.i368.rpm   #Force to install
rpm -e PACKAGE                               #Uninstall package
rpm -uvh filename                            #Upgrade by patch (The filename must be the upgrade patch not package)
rpm -i https://contoso.com/packagename.rpm   #Install package from internet
rpm -Va                                      #Search for corrupted filename
rpm -qf filename                             #Find out which package does the file belongs to 

Leave a Reply

Your email address will not be published. Required fields are marked *