Linux Common Command List,Tip: Ctrl+F to quickly find Linux commands (click on the title to collapse or expand)
Command Code | Comment Description |
---|---|
arch | Displays the processor architecture of the machine (1) |
uname -m | Displays the processor architecture of the machine (2) |
uname -r | Display the version of the kernel currently in use |
dmidecode -q | Display hardware system components - (SMBIOS / DMI) |
hdparm -i /dev/hda | List the architectural characteristics of a disk |
hdparm -tT /dev/sda | Perform a test read operation on the disk |
cat /proc/cpuinfo | Display CPU information |
cat /proc/interrupts | Display interrupts |
cat /proc/meminfo | Check memory usage |
cat /proc/swaps | Display which swaps are being used |
cat /proc/version | Display the version of the kernel |
cat /proc/net/dev | Display network adapters and statistics |
cat /proc/mounts | Display loaded file systems |
lspci -tv | List PCI devices |
lsusb -tv | Display USB devices |
date | Display system date |
cal 2007 | Display the calendar for the year 2007 |
date 041217002007.00 | Set the date and time - month day hour minute year.second |
clock -w | Save the time change to BIOS |
Command Code | Comment Description |
---|---|
shutdown -h now | Shutdown the system |
init | Shutdown the system |
telinit | Shutdown the system |
shutdown -h hours:minutes & | Shutdown the system at a scheduled time |
shutdown -c | Cancel the scheduled system shutdown |
shutdown -r now | Restart |
reboot | Restart |
logout | Logout |
Command Code | Comment Description |
---|---|
cd /home | Enter the '/home' directory' |
cd .. | Return to the parent directory |
cd ../.. | Return to the directory two levels up |
cd | Enter the user's home directory |
cd ~user1 | Enter the user's home directory |
cd - | Return to the last directory you were in |
pwd | Print the working directory |
ls | List the contents of a directory |
ls -F | List the contents of a directory |
ls -l | Display detailed information about files and directories |
ls -a | List all files, including hidden ones |
ls *[-9]* | List files and directories that contain numbers in their names |
tree | Display the directory tree starting from the root directory |
lstree | Display the directory tree starting from the root directory |
mkdir dir1 | Create a directory named 'dir1' |
mkdir dir1 dir2 | Create two directories at the same time |
mkdir -p /tmp/dir1/dir2 | Create a directory tree |
rm -f file1 | Remove a file named 'file1' |
rmdir dir1 | Remove a directory named 'dir1' |
rm -rf dir1 | Remove a directory named 'dir1' and its contents |
rm -rf dir1 dir2 | Remove two directories and their contents at the same time |
mv dir1 new_dir | Rename/move a directory |
cp file1 file2 | Copy a file |
cp dir/* . | Copy all files from a directory to the current working directory |
cp -a /tmp/dir1 . | Copy a directory to the current working directory |
cp -a dir1 dir2 | Copy a directory |
ln -s file1 lnk1 | Create a symbolic link pointing to a file or directory |
ln file1 lnk1 | Create a hard link pointing to a file or directory |
touch -t 712250000 file1 | Change the timestamp of a file or directory - (YYMMDDhhmm) |
iconv -l | List known encodings |
iconv -f fromEncoding -t toEncoding inputFile > outputFile | Change the encoding of characters |
find . -maxdepth 1 -name *.jpg -print -exec convert | Batch resize files in the current directory and send them to the thumbnail directory (requires ImageMagick conversion) |
Command Code | Explanation |
---|---|
find / -name file1 | Search for files and directories starting from the root file system '/' |
find / -user user1 | Search for files and directories owned by user 'user1' |
find /home/user1 -name \*.bin | Search for files ending with '.bin' in the directory '/home/user1' |
find /usr/bin -type f -atime +100 | Search for executable files that have not been used in the past 100 days |
find /usr/bin -type f -mtime -10 | Search for files that have been created or modified within the last 10 days |
find / -name \*.rpm -exec chmod 755 '{}' \; | Search for files ending with '.rpm' and set their permissions |
find / -xdev -name \*.rpm | Search for files ending with '.rpm', ignoring removable devices such as optical drives and flash drives |
locate \*.ps | Find files ending with '.ps' - run the 'updatedb' command first |
whereis halt | Display the location of a binary, source code, or man page |
which halt | Display the full path of a binary or executable file |
Command Code | Explanation |
---|---|
mount /dev/hda2 /mnt/hda2 | Mount a disk called hda2 - Ensure the directory '/mnt/hda2' exists |
umount /dev/hda2 | Unmount a disk called hda2 - Exit from the mount point '/mnt/hda2' first |
fuser -km /mnt/hda2 | Force unmount when the device is busy |
umount -n /mnt/hda2 | Perform the unmount operation without writing to the /etc/mtab file - Very useful when the file is read-only or when the disk is full |
mount /dev/fd /mnt/floppy | Mount a floppy disk |
mount /dev/cdrom /mnt/cdrom | Mount a CD-ROM or DVD-ROM |
mount /dev/hdc /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
mount /dev/hdb /mnt/cdrecorder | Mount a CD-RW or DVD-ROM |
mount -o loop file.iso /mnt/cdrom | Mount a file or ISO image file |
mount -t vfat /dev/hda5 /mnt/hda5 | Mount a Windows FAT32 file system |
mount /dev/sda1 /mnt/usbdisk | Mount a USB flash drive or flash memory device |
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share | Mount a Windows network share |
Command Code | Comment Description |
---|---|
df -h | Display the list of mounted partitions |
ls -lSr |more | Arrange files and directories by size |
du -sh dir1 | Estimate the disk space used by the directory 'dir1' |
du -sk * | sort -rn | Display the size of files and directories in order of capacity |
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n | Display the space used by installed rpm packages in order of size (Fedora, Red Hat-like systems) |
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n | Display the space used by installed deb packages in order of size (Ubuntu, Debian-like systems) |
Command Code | Comment Description |
---|---|
groupadd group_name | Create a new group |
groupdel group_name | Delete a group |
groupmod -n new_group_name old_group_name | Rename a group |
useradd -c "Name Surname" -g admin -d /home/user1 -s /bin/bash user1 | Create a user belonging to the "admin" group |
useradd user1 | Create a new user |
userdel -r user1 | Delete a user ('-r' to exclude the home directory) |
usermod -c "User FTP" -g system -d /ftp/user1 -s /bin/nologin user1 | Modify user attributes |
passwd | Modify password |
passwd user1 | Modify a user's password (only allowed for root to execute) |
chage -E 202-12-31 user1 | Set the expiration date for a user's password |
pwck | Check the '/etc/passwd' file format and syntax correction, as well as existing users |
grpck | Check the '/etc/passwd' file format and syntax correction, as well as existing groups |
newgrp group_name | Log in to a new group to change the default group of newly created files |
Command Code | Comment Explanation |
---|---|
ls -lh | Display permissions |
ls /tmp | pr -T5 -W$COLUMNS | Divide the terminal into 5 columns for display |
chmod ugo+rwx directory1 | Set read (r), write (w), and execute (x) permissions for everyone (u), group (g), and others (o) on a directory |
chmod go-rwx directory1 | Remove read, write, and execute permissions for the group (g) and others (o) on a directory |
chown user1 file1 | Change the ownership of a file |
chown -R user1 directory1 | Change the ownership of a directory and all files within it |
chgrp group1 file1 | Change the group of a file |
chown user1:group1 file1 | Change the owner and group of a file |
find / -perm -u+s | List all files in the system that use SUID control |
chmod u+s /bin/file1 | Set the SUID bit for a binary file - the user running the file is given the same permissions as the owner |
chmod u-s /bin/file1 | Disable the SUID bit for a binary file |
chmod g+s /home/public | Set the SGID bit for a directory - similar to SUID, but for directories |
chmod g-s /home/public | Disable the SGID bit for a directory |
chmod o+t /home/public | Set the STIKY bit for a file - only the legitimate owner can delete the file |
chmod o-t /home/public | Disable the STIKY bit for a directory |
Command Code | Comment Explanation |
---|---|
chattr +a file1 | Only allow appending to the file |
chattr +c file1 | Allow the file to be automatically compressed/decompressed by the kernel |
chattr +d file1 | During file system backup, the dump utility will ignore this file |
chattr +i file1 | Set the file to be immutable, cannot be deleted, modified, renamed, or linked |
chattr +s file1 | Allow a file to be safely deleted |
chattr +S file1 | Once an application writes to this file, make the system immediately write the modified results to the disk |
chattr +u file1 | If the file is deleted, the system will allow you to recover the deleted file later |
lsattr | Display special attributes |
Command Code | Comments |
---|---|
bunzip2 file1.bz2 | Unzip a file called 'file1.bz2' |
bzip2 file1 | Compresses a file called 'file1' |
gunzip file1.gz | Unzip a file called 'file1.gz' |
gzip file1 | Compresses a file called 'file1' |
gzip -9 file1 | Maximum compression |
rar a file1.rar test_file | Create a package called 'file1.rar' |
rar a file1.rar file1 file2 dir1 | Compresses 'file1', 'file2', and the directory 'dir1' at the same time |
rar x file1.rar | Unzip rar package |
unrar x file1.rar | Unzip rar package |
tar -cvf archive.tar file1 | Create an uncompressed tarball |
tar -cvf archive.tar file1 file2 dir1 | Create an archive file containing 'file1', 'file2', and 'dir1' |
tar -tf archive.tar | Display the contents of a package |
tar -xvf archive.tar | Release a package |
tar -xvf archive.tar -C /tmp | Release the compressed package to the /tmp directory |
tar -cvfj archive.tar.bz2 dir1 | Create a bzip2 compressed package |
tar -jxvf archive.tar.bz2 | Unzip a bzip2 compressed package |
tar -cvfz archive.tar.gz dir1 | Create a gzip compressed package |
tar -zxvf archive.tar.gz | Unzip a gzip compressed package |
zip file1.zip file1 | Create a zip compressed package |
zip -r file1.zip file1 file2 dir1 | Compresses several files and directories into a zip compressed package at the same time |
unzip file1.zip | Unzip a zip compressed package |
Command Code | Comment Description |
---|---|
rpm -ivh package.rpm | Install an RPM package |
rpm -ivh --nodeeps package.rpm | Install an RPM package ignoring dependency warnings |
rpm -U package.rpm | Update an RPM package without altering its configuration files |
rpm -F package.rpm | Update a specifically installed RPM package |
rpm -e package_name.rpm | Remove an RPM package |
rpm -qa | Display all installed RPM packages in the system |
rpm -qa | grep httpd | Display all RPM packages with "httpd" in their names |
rpm -qi package_name | Obtain special information about an installed package |
rpm -qg "System Environment/Daemons" | Display the RPM package of a component |
rpm -ql package_name | Display the list of files provided by an installed RPM package |
rpm -qc package_name | Display the list of configuration files provided by an installed RPM package |
rpm -q package_name --whatrequires | Display the list of packages that have a dependency on an RPM package |
rpm -q package_name --whatprovides | Display the disk space occupied by an RPM package |
rpm -q package_name --scripts | Display the scripts executed during installation/deletion |
rpm -q package_name --changelog | Display the modification history of an RPM package |
rpm -qf /etc/httpd/conf/httpd.conf | Identify which RPM package provides the given file |
rpm -qp package.rpm -l | Display the list of files provided by an uninstalled RPM package |
rpm --import /media/cdrom/RPM-GPG-KEY | Import a public key digital certificate |
rpm --checksig package.rpm | Confirm the integrity of an RPM package |
rpm -qa gpg-pubkey | Confirm the integrity of all installed RPM packages |
rpm -V package_name | Check file size, permissions, type, owner, group, MD5 checksum, and last modification time |
rpm -Va | Check all installed RPM packages in the system - use with caution |
rpm -Vp package.rpm | Verify that an RPM package is not yet installed |
rpm2cpio package.rpm | cpio --extract --make-directories *bin* | Execute executable files from an RPM package |
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm | Install a built package from an RPM source |
rpmbuild --rebuild package_name.src.rpm | Build an RPM package from RPM source |
Command Code | Comment Description |
---|---|
yum install package_name | Install a package using yum, resolving dependencies automatically |
yum update | Update all installed packages to their latest versions |
yum update package_name | Update a specific package to its latest version |
yum remove package_name | Remove a package and its dependencies that were installed with it |
yum list available | List all available packages from repositories |
yum search keyword | Search for packages by keyword |
yum info package_name | Display detailed information about a package |
yum clean all | Clean up cache and metadata to free disk space |
yum groupinstall group_name | Install a package group |
yum groupremove group_name | Remove a package group |
yum check-update | Check for available updates without applying them |
Command Code | Comment Description |
---|---|
yum install package_name | Download and install an rpm package |
yum localinstall package_name.rpm | Install an rpm package, using your own software repository to resolve all dependencies |
yum update package_name.rpm | Update all installed rpm packages in the current system |
yum update package_name | Update an rpm package |
yum remove package_name | Delete an rpm package |
yum list | List all packages currently installed in the system |
yum search package_name | Search for a software package in the rpm repository |
yum clean packages | Clean the rpm cache and delete downloaded packages |
yum clean headers | Delete all header files |
yum clean all | Delete all cached packages and header files |
Command Code | Comment Explanation |
---|---|
dpkg -i package.deb | Install/Update a deb package |
dpkg -r package_name | Remove a deb package from the system |
dpkg -l | Display all deb packages that have been installed in the system |
dpkg -l | grep httpd | Display all deb packages that contain the word "httpd" |
dpkg -s package_name | Get information about a specific package that has been installed in the system |
dpkg -L package_name | Display the list of files provided by an installed deb package in the system |
dpkg --contents package.deb | Display the list of files provided by an uninstalled package |
dpkg -S /bin/ping | Confirm which deb package provides the given file |
Command Code | Comment Explanation |
---|---|
apt-get install package_name | Install/Update a deb package |
apt-cdrom install package_name | Install/Update a deb package from a CD-ROM |
apt-get update | Upgrade the software packages in the list |
apt-get upgrade | Upgrade all installed software |
apt-get remove package_name | Remove a deb package from the system |
apt-get check | Confirm that the dependency software repository is correct |
apt-get clean | Clean the cache from downloaded software packages |
apt-cache search searched-package | Return the names of software packages that contain the search string |
Command Code | Comment Explanation |
---|---|
cat file1 | View the contents of the file from the first byte in the forward direction |
tac file1 | View the contents of a file in reverse from the last line |
more file1 | View the contents of a long file |
less file1 | Similar to the 'more' command, but it allows reverse operations in the file like forward operations |
head -2 file1 | View the first two lines of a file |
tail -2 file1 | View the last two lines of a file |
tail -f /var/log/messages | Real-time view of the content being added to a file |
Command Code | Comment Explanation |
---|---|
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt | Merge the detailed explanation text of a file and write the summary into a new file |
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt | Merge the detailed explanation text of a file and write the summary into an existing file |
grep Aug /var/log/messages | Search for the keyword "Aug" in the file '/var/log/messages' |
grep ^Aug /var/log/messages | Find words starting with "Aug" in the file '/var/log/messages' |
grep [-9] /var/log/messages | Select all lines in the '/var/log/messages' file that contain numbers |
grep Aug -R /var/log/* | Search for the string "Aug" in the directory '/var/log' and subsequent directories |
sed 's/stringa1/stringa2/g' example.txt | Replace "string1" with "string2" in the example.txt file |
sed '/^$/d' example.txt | Delete all blank lines from the example.txt file |
sed '/ *#/d; /^$/d' example.txt From example.txt | Delete all comments and blank lines in the file |
echo 'esempio' | tr '[:lower:]' '[:upper:]' | Merge the content of the upper and lower cells |
sed -e '1d' result.txt | Exclude the first line from the file example.txt |
sed -n '/stringa1/p' | View lines that only contain the word "string1" |
sed -e 's/ *$//' example.txt | Delete the blank characters at the end of each line |
sed -e 's/stringa1//g' example.txt | Delete only the word "string1" from the document and keep the rest |
sed -n '1,5p;5q' example.txt | View content from the first line to the 5th line |
sed -n '5p;5q' example.txt | View the 5th line |
sed -e 's/00*//g' example.txt | Replace multiple zeros with a single zero |
cat -n file1 | Mark the line numbers of the file |
cat example.txt | awk 'NR%2==1' | Delete all even lines in the example.txt file |
echo a b c | awk '{print $1}' | View the first column of a line |
echo a b c | awk '{print $1,$3}' | View the first and third columns of a line |
paste file1 file2 | Merge the contents of two files or two columns |
paste -d '+' file1 file2 | Merge the contents of two files or two columns, separated by "+" |
sort file1 file2 | Sort the contents of two files |
sort file1 file2 | uniq | Extract the union of two files (duplicate lines are kept only once) |
sort file1 file2 | uniq -u | Delete the intersection, leave the other lines |
sort file1 file2 | uniq -d | Extract the intersection of two files (only keep the files that exist in both files) |
comm -1 file1 file2 | Compare the contents of two files and delete the contents contained in 'file1' only |
comm -2 file1 file2 | Compare the contents of two files and delete the contents contained in 'file2' only |
comm -3 file1 file2 | Compare the contents of two files and delete the common parts of both files |
Command Code | Comment Description |
---|---|
dos2unix filedos.txt fileunix.txt | Convert the format of a text file from MSDOS to UNIX |
unix2dos fileunix.txt filedos.txt | Convert the format of a text file from UNIX to MSDOS |
recode ..HTML < page.txt > page.html | Convert a text file to HTML |
recode -l | more | Display all allowed conversion formats |
Command Code | Comment Description |
---|---|
badblocks -v /dev/hda1 | Check for bad blocks on the hda1 disk |
fsck /dev/hda1 | Repair/Check the integrity of the Linux file system on the hda1 disk |
fsck.ext2 /dev/hda1 | Repair/Check the integrity of the ext2 file system on the hda1 disk |
e2fsck /dev/hda1 | Repair/Check the integrity of the ext2 file system on the hda1 disk |
e2fsck -j /dev/hda1 | Repair/Check the integrity of the ext3 file system on the hda1 disk |
fsck.ext3 /dev/hda1 | Repair/Check the integrity of the ext3 file system on the hda1 disk |
fsck.vfat /dev/hda1 | Restore the MBR content from the backup that has been saved to a floppy disk |
Command Code | Comment Description |
---|---|
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force | Erase the content of a rewritable CD |
mkisofs /dev/cdrom > cd.iso | Create an ISO image file of a CD on the disk |
mkisofs /dev/cdrom | gzip > cd_iso.gz | Create a compressed ISO image file of a CD on the disk |
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd | Create an ISO image file of a directory |
cdrecord -v dev=/dev/cdrom cd.iso | Burn an ISO image file |
gzip -dc cd_iso.gz | cdrecord dev=/dev/cdrom - | Burn a compressed ISO image file |
mount -o loop cd.iso /mnt/iso | Mount an ISO image file |
cd-paranoia -B | Transfer audio tracks from a CD to wav files |
cd-paranoia -- "-3" | Transfer audio tracks from a CD to wav files (parameter -3) |
cdrecord --scanbus | Scan the bus to identify SCSI channels |
dd if=/dev/hdc | md5sum | Check the md5sum code of a device, such as a CD |
Command Code | Comment Description |
---|---|
dhclient eth | Enable the 'eth' network device in DHCP mode |
ethtool eth | Display traffic statistics of the network card 'eth' |
host www.example.com | Find the hostname to resolve the name and IP address and mirror |
hostname | Display the hostname |
ifconfig eth | Display the configuration of an Ethernet card |
ifconfig eth 192.168.1.1 netmask 255.255.255. | Control the IP address |
ifconfig eth promisc | Set 'eth' to promiscuous mode to sniff packets (sniffing) |
ifdown eth | Disable a 'eth' network device |
ifup eth | Enable a 'eth' network device |
ip link show | Display the connection status of all network devices |
iwconfig eth1 | Display the configuration of a wireless network card |
iwlist scan | Display wireless networks |
mii-tool eth | Display the connection status of 'eth' |
netstat -tup | Display all enabled network connections and their PID |
netstat -tup1 | Display all listening network services and their PIDs |
netstat -rn | Display routing table, similar to the "route -n" command |
nslookup www.example.com | Resolve hostnames to map names to IP addresses and mirrors |
route -n | Display routing table |
route add -net 0/0 gw IP_Gateway | Control the default gateway |
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 | Control static routing to the network '192.168.0.0/16' |
route del 0/0 gw IP_gateway | Delete static route |
echo "1"> /proc/sys/net/ipv4/ip_forward | Enable IP forwarding |
tcpdump tcp port 80 | Display all HTTP loopbacks |
whois www.example.com | Lookup in the Whois database |
Command Code | Comment Description |
---|---|
mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share | Mount a Windows network share |
nbtscan ip addr | NetBIOS name resolution |
nmblookup -A ip addr | NetBIOS name resolution |
smbclient -L ip addr/hostname | Display remote shares from a Windows host |
smbget -Rr smb://ip addr/share | Downloads files from a Windows host via SMB, akin to wget |
Command Code | Comment Description |
---|---|
iptables -t filter -L | Display all chains in the filter table |
iptables -t nat -L | Corrected: Display all chains in the nat table |
iptables -t filter -F | Flush all rules based on the filter table |
iptables -t nat -F | Flush all rules based on the nat table |
iptables -t filter -X | Delete all links created by the user |
iptables -t filter -A INPUT -p tcp --dport telnet -j ACCEPT | Allow telnet access |
iptables -t filter -A OUTPUT -p tcp --dport telnet -j DROP | Block telnet access |
iptables -t filter -A FORWARD -p tcp --dport pop3 -j ACCEPT | Allow forwarding of POP3 connections on the link |
iptables -t filter -A INPUT -j LOG --log-prefix | Log all packets that are blocked in the link |
iptables -t nat -A POSTROUTING -o eth -j MASQUERADE | Set up a PAT (Port Address Translation) on eth to mask outgoing packets |
iptables -t nat -A POSTROUTING -d 192.168..1 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10...2:22 | Redirect packets sent to a host address to another host |
Command Code | Comment Description |
---|---|
free -m | List RAM status in megabytes |
kill -9 process id | Forcefully close a process and end it |
kill -1 process id | Force a process to reload its configuration |
last reboot | Display reboot history |
lsmod | List loaded kernel modules |
lsof -p process id | List a file list opened by a process |
lsof /home/user1 | List the list of files opened in the given system path |
ps -eafw | List Linux tasks |
ps -e -o pid,args --forest | List Linux tasks in a hierarchical manner |
pstress | Display programs in a tree diagram |
smartctl -A /dev/hda | Monitor the reliability of a hard disk device by enabling SMART |
smartctl -i /dev/hda | Check whether the SMART of a hard disk device is enabled |
strace -c ls >/dev/null | List system calls made and receive them with a process |
strace -f -e open ls >/dev/null | List library calls |
tail /var/log/dmesg | Display internal events during the kernel boot process |
tail /val/log/messages | Display system events |
top | List Linux tasks that use the most CPU resources |
watch -nl ‘cat /proc/interrupts’ | List real-time interrupts |
Command Code | Comment Description |
---|---|
alias hh='history' | Set an alias for the history command |
apropos ...keyword | List a command list including the program keyword, especially useful when you only know what the program does and do not remember the command |
chsh | Change the shell command |
chsh --list-shells | A good command to know if you need to remotely connect to another machine |
gpg -c filel | Encrypt a file with GNU Privacy Guard |
gpg filel.gpg | Decrypt a file with GNU Privacy Guard |
Friendship link: Online Tool Network masters tool Calculation Assistant mathematical calculator ipsaya Random IP Strong Random Password Generator 2 to the power of what is 1/64 Globe Ask hello wordl Live Clock Numbers to Letters Pokemon Guide Snail Bob Red Light Green Light Game Excel Game Block Blast Unblocked Incredibox Sprunki Today Lucky Number Military Time Chart Chronological Age Calculator 12 Weeks From Today Weeks From Today Bottleneck Calculator Letters to Numbers