Online Toolbox
switching mode
tool collection
put it on the desktop
inclusion application
tool search

linux command query

query

Linux commands Introduction

About linux commands:

1, Linux commands are the core part of the Linux operating system, they are the main way users interact with the system.

2. This tool can query linux commands through some keywords.

3, if you want to see more linux commands, you can see the list of linux commands provided below.

system information
command code notes
arch display the processor architecture of the machine (1)
uname -m display the processor architecture of the machine (2)
uname -r show the kernel version in use
dmidecode -q display hardware system components - (smbios / dmi)
hdparm -i /dev/hda list the architectural features of a disk
hdparm -tT /dev/sda perform test read operations on disk
cat /proc/cpuinfo display cpu info information
cat /proc/interrupts display interrupt
cat /proc/meminfo verify memory usage
cat /proc/swaps show which swaps are used
cat /proc/version show the kernel version
cat /proc/net/dev display network adapters and statistics
cat /proc/mounts show loaded file system
lspci -tv list pci devices
lsusb -tv show usb devices
date show system date
cal 2007 show calendar for 2007
date 041217002007.00 set date and time - month, day, time, year. seconds
clock -w save time modification to bios
system shutdown/restart
command code notes
shutdown -h now turn off the system
init 0 turn off the system
telinit 0 turn off the system
shutdown -h hours:minutes & turn off the system at the scheduled time
shutdown -c cancel shut down the system at the scheduled time
shutdown -r now restart
reboot restart
logout log out
files and directories
command code notes
cd /home enter the '/home' directory'
cd .. return to the previous directory
cd ../.. return to the previous two-level directory
cd enter your personal home directory
cd ~user1 enter your personal home directory
cd - return to the directory you were in the last time
pwd show work path
ls view files in the directory
ls -F view files in the directory
ls -l display detailed information of files and directories
ls -a show hidden files
ls *[0-9]* show file names and directory names containing numbers
tree displays the tree structure of files and directories starting from the root directory
lstree displays the tree structure of files and directories starting from the root directory
mkdir dir1 create a directory called 'dir1'
mkdir dir1 dir2 create two directories at the same time
mkdir -p /tmp/dir1/dir2 create a directory tree
rm -f file1 delete a file called 'file1'
rmdir dir1 delete a directory called 'dir1'
rm -rf dir1 delete a directory called 'dir1' and delete its contents at the same time
rm -rf dir1 dir2 delete 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 in one 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 soft link to a file or directory
ln file1 lnk1 create a physical link to a file or directory
touch -t 0712250000 file1 modify 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 the file in the current directory and send it to the thumbnail directory (need to be converted from imagemagick)
file search
command code notes
find / -name file1 starting from '/', enter the root file system to search for files and directories
find / -user user1 search for files and directories belonging to user 'user1'
find /home/user1 -name \*.bin search for a file ending with '.bin' in directory '/home/user1'
find /usr/bin -type f -atime +100 search for execution 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 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; search for files ending with '.rpm' and define their permissions
find / -xdev -name \*.rpm search for files ending with '.rpm', ignoring removable devices such as optical drives and shortcuts
locate \*.ps looking for files ending with '.ps' - run the 'updatedb' command first
whereis halt shows the location of a binary file, source code, or man
which halt shows the full path to a binary or executable file
mount the file system
command code notes
mount /dev/hda2 /mnt/hda2 mount a disk called hda2 - confirm the directory '/mnt/hda2' already exists
umount /dev/hda2 uninstall a disk called hda2 - exit from the mount point '/mnt/hda2'
fuser -km /mnt/hda2 forced uninstall when the device is busy
umount -n /mnt/hda2 run the uninstall operation without writing to the /etc/mtab file - useful when the file is read-only or when the disk is full
mount /dev/fd0 /mnt/floppy mount a floppy disk
mount /dev/cdrom /mnt/cdrom mount a cdrom or dvdrom
mount /dev/hdc /mnt/cdrecorder mount a cdrw or dvdrom
mount /dev/hdb /mnt/cdrecorder mount a cdrw or dvdrom
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 shortcut or flash device
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share mount a windows network share
disk space
command code notes
df -h shows the mounted partition list
ls -lSr |more arrange files and directories by size
du -sh dir1 estimate the disk space already used by directory 'dir1'
du -sk * | sort -rn display the size of files and directories in sequence based on capacity size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n display the space used by the installed rpm package in sequence based on size (fedora, redhat class system)
dpkg-query -W -f='${Installed-Size;10}t${Package}n' | sort -k1,1n display the space used by the installed deb package based on size (ubuntu, debian system)
users and groups
command code notes
groupadd group_name create a new user group
groupdel group_name delete a user group
groupmod -n new_group_name old_group_name rename a user group
useradd -c "Name Surname " -g admin -d /home/user1 -s /bin/bash user1 create a user belonging to the "admin" user group
useradd user1 create a new user
userdel -r user1 delete a user ('-r' exclude 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 root is allowed to execute)
chage -E 2020-12-31 user1 set the expiration period of user password
pwck check the file format and syntax correction of '/etc/passwd' and the existing users
grpck check the file format and syntax corrections of '/etc/passwd' and the existing groups
newgrp group_name log in to a new group to change the preset group of newly created files
file permissions
command code notes
ls -lh show permissions
ls /tmp | pr -T5 -W$COLUMNS divide the terminal into 5 columns to display
chmod ugo+rwx directory1 set permissions for everyone (u), group (g) and others (o) of the directory to read (r), write (w) and execute (x)
chmod go-rwx directory1 delete group (g) and others (o) read and write execution permissions to directories
chown user1 file1 change the properties of a file
chown -R user1 directory1 change the properties of all files in a directory and change the properties of all files in the directory at the same time
chgrp group1 file1 change the group of files
chown user1:group1 file1 change the owner and group properties of a file
find / -perm -u+s list all files in a system that use suid control
chmod u+s /bin/file1 set the suid bit of a binary file - the user running the file is also given the same permissions as the owner
chmod u-s /bin/file1 disable the suid bit of a binary file
chmod g+s /home/public set the sgid bit of a directory - similar to suid, but this is for the directory
chmod g-s /home/public disable the sgid bit of a directory
chmod o+t /home/public set the stiky bit of a file - only legal everyone can delete files
chmod o-t /home/public disable the stiky bit of a directory
file properties
command code notes
chattr +a file1 only read and write files in append mode are allowed
chattr +c file1 allows this file to be automatically compressed/decompressed by the kernel
chattr +d file1 when performing file system backup, the dump program ignores this file
chattr +i file1 files that are set to immutable cannot be deleted, modified, renamed or linked
chattr +s file1 allow a file to be deleted safely
chattr +S file1 once the application performs a write operation on this file, the system immediately writes the modified result to disk.
chattr +u file1 if the file is deleted, the system will allow you to restore the deleted file in the future.
lsattr show special properties
packaging and compression
command code notes
bunzip2 file1.bz2 unzip a file called 'file1.bz2'
bzip2 file1 compress a file called 'file1'
gunzip file1.gz unzip a file called 'file1.gz'
gzip file1 compress 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 compress 'file1', 'file2' and 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 a non-compressed tarball
tar -cvf archive.tar file1 file2 dir1 create an archive file containing 'file1', 'file2' and 'dir1'
tar -tf archive.tar show contents in a package
tar -xvf archive.tar release a package
tar -xvf archive.tar -C /tmp release the compressed package into /tmp directory
tar -cvfj archive.tar.bz2 dir1 create a bzip2 format compressed package
tar -jxvf archive.tar.bz2 unzip a compressed package in bzip2 format
tar -cvfz archive.tar.gz dir1 create a gzip package
tar -zxvf archive.tar.gz unzip a gzip compressed package
zip file1.zip file1 create a zip-format compressed package
zip -r file1.zip file1 file2 dir1 compress several files and directories into a zip format compressed package at the same time
unzip file1.zip unzip a zip format compressed package
rpm package
command code notes
rpm -ivh package.rpm install a rpm package
rpm -ivh --nodeeps package.rpm install an rpm package and ignore dependency warning
rpm -U package.rpm update an rpm package without changing its configuration file
rpm -F package.rpm update a rpm package that is sure to have been installed
rpm -e package_name.rpm delete a rpm package
rpm -qa display all installed rpm packages in the system
rpm -qa | grep httpd show all rpm packages with the word "httpd" in their names
rpm -qi package_name get special information about an installed package
rpm -qg "System Environment/Daemons" displays a component's rpm package
rpm -ql package_name shows a list of files provided by an installed rpm package
rpm -qc package_name displays a list of configuration files provided by an installed rpm package
rpm -q package_name --whatrequires shows a list of dependencies with an rpm package
rpm -q package_name --whatprovides shows the volume occupied by an rpm package
rpm -q package_name --scripts show scripts executed during installation/deletion
rpm -q package_name --changelog shows the modification history of an rpm package
rpm -qf /etc/httpd/conf/httpd.conf confirm which rpm package is provided by the given file
rpm -qp package.rpm -l shows a list of files provided by a rpm package that has not been installed yet
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, permission, type, owner, group, md5 check and last modification time
rpm -Va check all installed rpm packages in the system - use with caution
rpm -Vp package.rpm confirm that a rpm package has not been installed yet
rpm2cpio package.rpm | cpio --extract --make-directories *bin* run an executable from a rpm package
rpm -ivh /usr/src/redhat/RPMS/`arch`/package.rpm install a built package from a rpm source code
rpmbuild --rebuild package_name.src.rpm build an rpm package from a rpm source
yum package upgrader
command code notes
yum install package_name download and install an rpm package
yum localinstall package_name.rpm a rpm package will be installed and all dependencies will be resolved for you using your own repository
yum update package_name.rpm update all installed rpm packages in the current system
yum update package_name update a rpm package
yum remove package_name delete a rpm package
yum list list all packages installed in the current system
yum search package_name search for packages in rpm repository
yum clean packages clean up rpm cache to delete downloaded packages
yum clean headers delete all header files
yum clean all delete all cached packages and header files
deb package
command code notes
dpkg -i package.deb install/update a deb package
dpkg -r package_name delete a deb package from the system
dpkg -l display all installed deb packages in the system
dpkg -l | grep httpd show all deb packages with the word "httpd" in their names
dpkg -s package_name get information about a special package that has been installed in the system
dpkg -L package_name displays the file list provided by a deb package that has been installed in the system
dpkg --contents package.deb shows a list of files provided by a package that has not been installed yet
dpkg -S /bin/ping confirm which deb package is provided by the given file
apt software tools
command code notes
apt-get install package_name install/update a deb package
apt-cdrom install package_name install/update a deb package from the cd
apt-get update upgrade the packages in the list
apt-get upgrade upgrade all installed software
apt-get remove package_name delete a deb package from the system
apt-get check confirm that the dependent repository is correct
apt-get clean clean cache from downloaded package
apt-cache search searched-package returns the package name containing the string you want to search for
view file content
command code notes
cat file1 starting from the first byte, the contents of the file are viewed forward
tac file1 starting from the last line, view the contents of a file in reverse
more file1 view the contents of a long file
less file1 similar to the 'more' command, but it allows reverse operations in files as well as 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 view content added to a file in real time
text processing
command code notes
cat file1 | command( sed, grep, awk, grep, etc...) > result.txt merge the detailed description text of a file and write the introduction into a new file
cat file1 | command( sed, grep, awk, grep, etc...) >> result.txt merge the detailed description text of a file and write the introduction into an existing file
grep Aug /var/log/messages find keyword "aug" in file '/var/log/messages'
grep ^Aug /var/log/messages find vocabulary starting with "aug" in file '/var/log/messages'
grep [0-9] /var/log/messages select all lines containing numbers in the '/var/log/messages' file
grep Aug -R /var/log/* search the string "aug" in the directory '/var/log' and subsequent directories
sed 's/stringa1/stringa2/g' example.txt replace "string1" in the example.txt file with "string2"
sed '/^$/d' example.txt remove all blank lines from example.txt file
sed '/ *#/d; /^$/d' example.txt 从example.txt delete all comments and blank lines in the file
echo 'esempio' | tr '[:lower:]' '[:upper:]' merge upper and lower cell contents
sed -e '1d' result.txt exclude the first line from the file example.txt
sed -n '/stringa1/p' view lines that contain only the word "string1"
sed -e 's/ *$//' example.txt delete the last whitespace character of each line
sed -e 's/stringa1//g' example.txt only delete the word "string1" from the document and keep all remaining
sed -n '1,5p;5q' example.txt view content from line 1 to line 5
sed -n '5p;5q' example.txt view line 5
sed -e 's/00*/0/g' example.txt replace multiple zeros with a single zero
cat -n file1 number of lines indicating 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 row
echo a b c | awk '{print $1,$3}' view the first and third columns of a row
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, and use "+" to distinguish them in the middle.
sort file1 file2 sort the contents of two files
sort file1 file2 | uniq take out the union of two files (only one copy of the duplicate lines)
sort file1 file2 | uniq -u delete the intersection, leaving other lines
sort file1 file2 | uniq -d take out the intersection of two files (leave only files that exist in both files at the same time)
comm -1 file1 file2 compare the contents of two files to delete only the contents contained in 'file1'
comm -2 file1 file2 compare the contents of two files to delete only the contents contained in 'file2'
comm -3 file1 file2 compare the contents of two files and delete only the parts shared by the two files.
character settings/file format conversion
command code notes
dos2unix filedos.txt fileunix.txt convert a text file format from msdos to unix
unix2dos fileunix.txt filedos.txt convert a text file format from unix to msdos
recode ..HTML < page.txt > page.html convert a text file to html
recode -l | more show all allowed conversion formats
file system analysis
command code notes
badblocks -v /dev/hda1 check for bad blocks on disk hda1
fsck /dev/hda1 fix/check the integrity of the linux file system on hda1 disk
fsck.ext2 /dev/hda1 fix/check the integrity of ext2 file system on hda1 disk
e2fsck /dev/hda1 fix/check the integrity of ext2 file system on hda1 disk
e2fsck -j /dev/hda1 fix/check the integrity of ext3 file system on hda1 disk
fsck.ext3 /dev/hda1 fix/check the integrity of ext3 file system on hda1 disk
fsck.vfat /dev/hda1 fix/check the integrity of the fat file system on hda1 disk
fsck.msdos /dev/hda1 fix/check the integrity of the dos file system on hda1 disk
dosfsck /dev/hda1 fix/check the integrity of the dos file system on hda1 disk
initialize the file system
command code notes
mkfs /dev/hda1 create a file system in hda1 partition
mke2fs /dev/hda1 create a linux ext2 file system in hda1 partition
mke2fs -j /dev/hda1 create a linux ext3 (log type) file system in hda1 partition
mkfs -t vfat 32 -F /dev/hda1 create a fat32 file system
fdformat -n /dev/fd0 format a floppy disk
mkswap /dev/hda3 create a swap file system
swap file system
command code notes
mkswap /dev/hda3 create a swap file system
swapon /dev/hda3 enable a new swap file system
swapon /dev/hda2 /dev/hdb3 enable two swap partitions
backup
command code notes
dump -0aj -f /tmp/home0.bak /home make a full backup of the '/home' directory
dump -1aj -f /tmp/home0.bak /home make an interactive backup of the '/home' directory
restore -if /tmp/home0.bak restore an interactive backup
rsync -rogpav --delete /home /tmp synchronize the directories on both sides
rsync -rogpav -e ssh --delete /home ip_address:/tmp rsync via ssh channel
rsync -az -e ssh --delete ip_addr:/home/public /home/local synchronize a remote directory to a local directory through ssh and compression
rsync -az -e ssh --delete /home/local ip_addr:/home/public synchronize local directories to remote directories via ssh and compression
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr 'dd of=hda.gz' perform a backup of local disks on a remote host via ssh
dd if=/dev/sda of=/tmp/file1 backup disk contents to a file
tar -Puf backup.tar /home/user perform an interactive backup operation to the '/home/user' directory
( cd /tmp/local/ && tar c . ) | ssh -C user@ip_addr 'cd /home/share/ && tar x -p' copy a directory content in a remote directory via ssh
( tar c /home ) | ssh -C user@ip_addr 'cd /home/backup-home && tar x -p' copy a local directory in a remote directory via ssh
tar cf - . | (cd /tmp/backup ; tar xf - ) locally copy one directory to another place, retaining the original permissions and links
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents find and copy all files ending with '.txt' from one directory to another
find /var/log -name '*.log' | tar cv --files-from=- | bzip2 > log.tar.bz2 find all files ending with '.log' and make a bzip package
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 do an action to copy mbr (master boot record) content to the floppy disk
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 recover mbr content from backups that have been saved to floppy disk
cd
command code notes
cdrecord -v gracetime=2 dev=/dev/cdrom -eject blank=fast -force clear a rewriteable cd content
mkisofs /dev/cdrom > cd.iso create a disc's iso image file on disk
mkisofs /dev/cdrom | gzip > cd_iso.gz create a compressed disc iso image file on disk
mkisofs -J -allow-leading-dots -R -V "Label CD" -iso-level 4 -o ./cd.iso data_cd create an iso image file for 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 transcribing audio tracks from a cd disc to a wav file
cd-paranoia -- "-3" transcribing the track from a cd disc to a wav file (parameter-3)
cdrecord --scanbus scan the bus to identify the scsi channel
dd if=/dev/hdc | md5sum verify the md5sum encoding of a device, such as a cd
network
command code notes
dhclient eth0 enable 'eth0' network device in dhcp mode
ethtool eth0 display traffic statistics for network card 'eth0'
host www.example.com find the host name to resolve the name and ip address and image
hostname show host name
ifconfig eth0 displays the configuration of an ethernet card
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control ip address
ifconfig eth0 promisc set 'eth0' to promiscuous mode to sniff packets (sniffing)
ifdown eth0 disable an 'eth0' network device
ifup eth0 enable a 'eth0' network device
ip link show displays the connection status of all network devices
iwconfig eth1 displays the configuration of a wireless network card
iwlist scan show wireless network
mii-tool eth0 shows the connection status of 'eth0'
netstat -tup show all enabled network connections and their pids
netstat -tup1 displays all listening network services and their pids in the system
netstat -rn display routing table, similar to the "route -n" command
nslookup www.example.com find the host name to resolve the name and ip address and image
route -n show routing table
route add -net 0/0 gw IP Gateway control preset gateways
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 controls static routes to the network '192.168.0.0/16'
route del 0/0 gw IP gateway delete static routes
echo “1”> /proc/sys/net/ipv4/ip_foward activate ip forwarding
tcpdump tcp port 80 show all http loopbacks
whois www.example.com find in whois database
microsoft windows network
command code notes
mount -t smbfs -o username=user,password=pass //WinClient/share/mnt/share mount a windows network share
nbtscan ip addr netbios name analysis
nmblookup -A ip addr netbios name analysis
smbclient -L ip addr/hostname show remote sharing of a windows host
smbget -Rr smb://ip addr/share like wget, you can download files from a windows host via smb.
IPTABLES(firewall)
command code notes
iptables -t filter -L show all links in the filter table
iptables -t nae -L show all links in the nat table
iptables -t filter -F clean all rules based on filter tables
iptables -t nat -F clean all rules based on nat table
iptables -t filter -X delete all links created by users
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 pop3 connections on forwarding links
iptables -t filter -A INPUT -j LOG --log-prefix record all packets seized in links
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE set a pat (port address translation) to mask out packets in eth0
iptables -t nat -A POSTROUTING -d 192.168.0.1 -p tcp -m tcp --dport 22-j DNAT --to-destination 10.0.0.2:22 transfer packets sent to one host address to another host
monitoring and debugging
command code notes
free -m list ram status in megabytes
kill -9 process id forcefully close the process and end it
kill -1 process id force a process to overload its configuration
last reboot show restart history
lsmod kernel modules that list states
lsof -p process id list a list of files opened by a process
lsof /home/user1 list the list of opened files in the given system path
ps -eafw list linux tasks
ps -e -o pid,args --forest list linux tasks in a hierarchical way
pstress show program in a tree diagram
smartctl -A /dev/hda monitor the reliability of hard drive devices by enabling smart
smartctl -i /dev/hda check if smart is enabled on a hard disk device
strace -c ls >/dev/null list the 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 kernel boot
tail /val/log/messages show system events
top list the linux tasks that use the most cpu resources
watch -nl ‘cat /proc/interrupts’ list real-time interrupts
other common commands
command code notes
alias hh='history' set an alias for the command history
apropos ...keyword list a list of commands that include program keywords, which is especially useful when you only know what the program does and don't remember commands.
chsh change shell command
chsh --list-shells good commands to find out if you have to connect to another machine remotely
gpg -c filel encrypt a file with gnu privacy guard
gpg filel.gpg decrypt a file using gnu privacy guard
Internet Business Promoter