May 28, 2021 Article blog
2. Shutdown (system shutdown, restart, and log-out)
8. Permissions for files - Set permissions with "plus" and use "-" to cancel
9. Special properties of the file - set permissions with the "plus" and use "-" for cancellation
10.. Package and compress files
11.. RPM Package - (Fedora, Redhat and similar systems)
12.. YUM Package Upgrader - (Fedora, RedHat and similar systems)
13.. DEB packages (Debian, Ubuntu and similar systems)
14.. APT software tools (Debian, Ubuntu and similar systems)
15.. View the contents of the file
17.. Character settings and file format conversions
Linux is known to be short and powerful, and this article introduces you to Linux's commands.
Arch shows the processor architecture of the machine
uname -m shows the processor architecture of the machine
uname -r shows the version of the kernel in use
dmidecode -q display hardware system components - (SMBIOS / DMI)
hdparm -i/dev/hda lists the schema characteristics of a disk
hdparm -tT/dev/sda performs a test read operation on disk
Cat/proc/cpuinfo displays information about CPU info
Cat/proc/interrupts show interrupts
cat/proc/meminfo checks memory usage
Cat/proc/swaps show which swaps are being used
Cat/proc/version shows the version of the kernel
Cat/proc/net/dev displays network adapters and statistics
cat/proc/mounts shows the loaded file system
lspci -tv lists PCI devices
lsusb -tv displays USB devices
date shows the system date
cal 2007 shows the calendar for 2007
date 041217002007.00 Set date and time - monthly hour year by year. s econd
clock -w saves time modifications to the BIOS
Shutdown -h now shuts down the system
Init 0 shuts down the system
Telinit 0 shuts down the system
Shutdown -h hours:minutes - Shut down the system at a predetermined time
Shutdown -c Cancel shutting down the system at the scheduled time
Shutdown -r now restart
Reboot restart
Logout logout
cd/home enters the 'home' directory'
cd .. R eturn to the previous level of the directory
cd .. / .. R eturn to the upper two levels of the directory
cd Go to your personal home directory
cd - user1 enters the personal home directory
cd - Returns to the last directory in which it was located
pwd shows the work path
ls View the files in the directory
ls -F View the files in the directory
ls -l Displays details of files and directories
ls -a displays hidden files
ls .
Tree displays the tree structure of files and directories starting with the root
lstree displays the tree structure of files and directories starting with the root directory
mkdir dir1 creates a directory called 'dir1'
mkdir dir1 dir2 creates two directories at the same time
mkdir -p /tmp/dir1/dir2 creates a tree
rm -f file1 deletes a file called 'file1'
rmdir dir1 deletes a directory called 'dir1'
rm-rf dir1 deletes a directory called 'dir1' and deletes its contents at the same time
rm -rf dir1 dir2 deletes both directories and their contents at the same time
mv dir1 new_dir rename/move a directory
cp file1 file2 copies a file
cp dir/* . C opy all files from one directory to the current working directory
cp -a /tmp/dir1 . C opy a directory to the current working directory
cp -a dir1 dir2 copies a directory
cp -r dir1 dir2 copies a directory and subdirectory
ln -s file1 lnk1 creates a soft link to a file or directory
ln file1 lnk1 creates a physical link to a file or directory
touch -t 0712250000 file1 modifies the timestamp of a file or directory - (YYMMDDhmm)
file file1 outputs the mime type of the file as text
iconv -l lists known encodings
iconv -f fromEncoding -t toEncoding inputFile > outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.
find . - maxdepth 1 -name *.jpg -print -exec convert "{}" -resize 80x60 "thumbs/{}" \; b atch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)
Find / - name file1 starts with '/' and enters the root file system to search for files and directories
Find / -user1 searches for files and directories that belong to the user 'user1'
Find/home/user1 -name..bin search for files with the end of '.bin' in directory '/home/user1'
Find/usr/bin -type f -atime .100 searches for execution files that have not been used in the last 100 days
Find/usr/bin -type f -mtime -10 searches for files that have been created or modified within 10 days
find / -name \*.rpm -exec chmod 755 '{}' \; S earch for files that end in '.rpm' and define their permissions
Find / -xdev -name ..rpm search for files ending in '.rpm', ignoring removable devices such as optical drives, shortcuts, etc
locate.ps look for files that end with '.ps' - run the 'updatedb' command first
Whereis halt shows the location of a binary, source, or man
the halt shows the full path of a binary or executable
Mount /dev/hda2 /mnt/hda2 mounts a disk called hda2 - make sure that directory '/ mnt/hda2' already exists
umount /dev/hda2 unloads a disk called hda2 - exit first from the mount point '/ mnt/hda2'
Fuser -km/mnt/hda2 force uninstalls when the device is busy
umount -n/mnt/hda2 runs an 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 mounts a floppy disk
Mount /dev/cdrom/mnt/cdrom mount a cdrom or dvdrom
Mount /dev/hdc /mnt/cdrecorder mounts a cdrw or dvdrom
Mount /dev/hdb /mnt/cdrecorder mounts a cdrw or dvdrom
Mount -o loop file .iso /mnt/cdrom mount a file or ISO mirror file
Mount -t vfat/dev/hda5/mnt/hda5 mounts a Windows FAT32 file system
Mount /dev/sda1 /mnt/usbdisk mounts a usb shortcut or flash memory device
mount -t smbfs -o username-user, password-pass//WinClient/share/mnt/share mount a windows network share
df -h displays a list of partitions that have been mounted
ls -lSr |more arranges files and directories by size
du -sh dir1 estimated directory 'dir1' used disk space'
du -sk * | s ort -rn displays the size of files and directories in turn, based on capacity size
rpm -q -a --qf '%10{SIZE}t%{NAME}n' | s ort -k1,1n displays, in order of size, the space used by the installed rpm package (fedora, redhat class system)
dpkg-query -W -f='${Installed-Size; 1 0}t${Package}n' | s ort -k1,1n displays the space used by the installed deb package based on size (ubuntu, debian class system)
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 Last" -g admin -d /home/user1 -s/bin/bash user1 creates a user who belongs to the "admin" user group
Useradd user1 creates a new user
userdel -r user1 deletes a user ('-r' excludes home directory)
usermod -c "User FTP" -g system -d/ftp/user1 -s/bin/nologin user1 modifies user properties
Passwd modifies the password
Passwd user1 modifies a user's password (root execution is only allowed)
chage -E 2005-12-31 user1 sets the expiration date of the user password
pwck checks the file format and syntax corrections of '/etc/passwd' as well as the users that exist
Grpck checks the file format and syntax corrections of '/etc/passwd' as well as the groups that exist
newgrp group_name log in to a new group to change the preset group of newly created files
ls -lh display permissions
ls /tmp | p r -T5 -W$COLUMNS divides the terminal into 5 columns
Chmod ugo-rwx directory1 sets permissions for everyone (u), group (g), and others (o) of the directory to read (r), write (w), and execute (x).
chmod go-rwx directory1 removes group (g) and others (o) from reading and writing permissions for the directory
chown user1 file1 changes the owner properties of a file
Chown -R user1 directory1 changes the owner properties of a directory and changes the properties of all files in the directory at the same time
Chgrp group1 file1 changes the group of files
chown user1:group1 file1 changes the owner and group properties of a file
Find / -perm -u-s lists all files in one system that are controlled by SUID
Chmod u-s/bin/file1 sets 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 disables the SUID bit of a binary file
Chmod g-s/home/public sets the SGID bit of a directory - similar to a SUID, but this is for the directory
chmod g-s/home/public disables the SGID bit of a directory
Chmod o-t/home/public sets the STIKY bit of a file - only legitimate owners are allowed to delete the file
chmod o-t /home/public disables the STIKY bit of a directory
Chattr-a file1 only allows you to read and write files as an append
Chattr sc file1 allows this file to be automatically compressed/unzipped by the kernel
The dump program ignores the file when chattr sd file1 makes a file system backup
Chattr-i file1 is set to immutable files and cannot be deleted, modified, renamed, or linked
Chattr s file1 allows a file to be safely deleted
As soon as the application writes to the file, the system immediately writes the results of the modification to disk
If the file is deleted, you will be allowed to recover the deleted file later
lsattr displays special properties
Bunzip2 file1.bz2 unzips 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 for maximum compression
Rar a file1 .rar test_file create a package called 'file1 .rar'
rar a file1.rar file1 file12 dir1 simultaneously compresses 'file1', 'file2' and directory 'dir1'
Rar x file1.rar Unzip the rar package
unrar x file1.rar Unzip the rar package
Tar -cvf archive .tar file1 to create an uncompressed tarball
tar-cvf archive .tar file1 file2 dir1 to create an archive containing 'file1', 'file2' and 'dir1'
The tar-tf archive .tar displays the contents of a package
Tar -xvf archive .tar releases a package
Tar -xvf archive .tar -C/tmp releases the package to the /tmp directory
tar -cvfj archive .tar.bz2 dir1 to create a compression package in bzip2 format
tar -jxvf archive.tar.bz2 unzipping a compression package in bzip2 format
Tar -cvfz archive .tar.gz dir1 to create a gzip-formatted compression package
Tar -zxvf archive .tar.gz unzip a gzip-formatted compression package
Zip file1 creates a zip-formatted compression package .zip file1
Zip -r file1.zip file1 file12 dir1 compresses several files and directories into a zip-formatted package at the same time
unzip file1.zip unzip a zip-format compression package
rpm -ivh package.rpm install an rpm package
rpm -ivh --nodeeps package .rpm install an rpm package and ignore the dependency warning
rpm -U package .rpm update an rpm package without changing its profile
rpm -F package .rpm update an rpm package that determines that it has been installed
rpm -e package_name.rpm remove an rpm package
rpm -qa shows all the rpm packages installed in the system
rpm -qa | G rep httpd displays rpm packages with the word "httpd" in all names
rpm -qi package_name get special information about an installed package
rpm -qg "System Environment/Daemons" displays the rpm package for a component
rpm -ql package_name displays a list of files provided by an installed rpm package
the rpm -qc package_name displays a list of profiles provided by an installed rpm package
rpm -q package_name -- whatrequires displays a list of dependencies on an rpm package
rpm -q package_name --whatprovides shows the volume occupied by an rpm package
rpm -q package_name --scripts show script l executed during installation/deletion
rpm -q package_name --changelog shows the history of modification of an rpm package
rpm -qf/etc/httpd/conf/httpd.conf confirms which rpm package provides the file
rpm -qp package .rpm -l displays a list of files provided by an rpm package that has not yet been installed
rpm --import/media/cdrom/RPM-GPG-KEY imports the public key digital certificate
rpm --checksig package .rpm confirm the integrity of an rpm package
rpm -qa gpg-pubkey confirms the integrity of all installed rpm packages
rpm-V package_name Check file size, license, type, owner, group, MD5 check, and final modification time
rpm - Va check all installed rpm packages in the system - use with care
rpm -Vp package .rpm confirm that a rpm package has not been installed
rpm2cpio package.rpm | C pio --extract --make-directories.bin?runs executables from an 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 code
yum install package_name download and install an rpm package
yum localinstall package_name.rpm installs an rpm package that uses your own software repository to resolve all dependencies for you
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 remove an rpm package
yum list lists all packages installed in the current system
yum search package_name search for packages in the rpm repository
Yum clean packages clean up the rpm cache to remove downloaded packages
Yum clean headers deletes all header files
yum clean all deletes all cached packages and header files
dpkg -i package .deb install/update a deb package
dpkg -r package_name remove a deb package from the system
dpkg -l displays all installed deb packages in the system
dpkg -l | G rep httpd displays a deb package with the word "httpd" in all names
The dpkg-s package_name gets information that a special package has been installed in the system
The dpkg-L package_name displays a list of files provided by a deb package that is already installed in the system
The dpkg-contents package .deb displays a list of files provided by a package that has not yet been installed
DPkg -S/bin/ping confirms which deb package provides the file
apt-get install package_name install/update a deb package
apt-cdrom install package_name install/update a deb package from a CD
Packages in the apt-get update upgrade list
apt-get upgrade upgrades all installed software
apt-get remove package_name remove a deb package from the system
apt-get check confirms that the software repository on which you depend is correct
apt-get clean clean cleans the cache from downloaded packages
apt-cache search searched-package returns the name of the package that contains the string to be searched
Cat file1 views the contents of the file forward from the first byte
tac file1 reverses the contents of a file from the last line
more file1 to view the contents of a long file
less file1 is similar to the 'more' command, but it allows the same reverse operation in a file as in a forward operation
Head -2 file1 looks at the first two lines of a file
tail -2 file1 looks at the last two lines of a file
tail -f/var/log/messages view in real time what is added to a file
cat file1 file2 ... | c ommand <> file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT
cat file1 | c ommand (sed, grep, awk, grep, etc...) > results.txt merge the detailed text of a file and write the introduction to a new file
cat file1 | c ommand (sed, grep, awk, grep, etc...) >> results.txt merge the detailed text of a file and write the introduction to an existing file
Grep Aug/var/log/messages look for the keyword 'Aug' in file '/var/log/messages'
Grep s Aug/var/log/messages look for words that start with "Aug" in the file '/var/log/messages'
Grep (0-9) /var/log/messages select all the lines in the 'var/log/messages' file that contain numbers
Grep Aug-R/var/log/?searches for the string 'Aug' in the directory '/var/log' and subsequent directories
sed's/stringa1/stringa2/g' example.txt replaces "string1" in the .txt file with "string2"
The sed'/'$/d' example .txt remove all blank lines from the .txt file
sed '/ *#/d; / '$/d' example.txt remove all comments and blank lines from the .txt file
echo 'esempio' | t r':lower:'' '' Merges the contents of the upper and lower cells
sed -e '1d' result .txt excludes the first line from the file .txt
The sed -n'/stringa1/p' view contains only the line of the word "string1"
sed -e's/ s$//' example .txt removes the last blank character from each line
sed -e's/stringa1//g' example .txt removes only the word "string1" from the document and retains all remaining
sed -n '1,5p; 5 q' example .txt view content from the first line to the fifth line
sed -n '5p; 5 q' example.txt View line 5
sed -e's/00*/0/g' example .txt replace multiple zeros with a single zero
Cat -n file1 indicates the number of lines in the file
cat example.txt | a wk 'NR%2'1' deletes all even lines in the example .txt file
echo a b c | A wk ''print$1'' view the first column of a line
echo a b c | a wk ''print $1,$3'' view the first and third columns of a line
Paste file1 file2 merges the contents of two files or columns
Paste -d'''file1 file2 merges the contents of two files or columns, distinguished between them by "plus"
sort file1 file2 sorts the contents of both files
sort file1 file2 | u niq takes out the union of two files (duplicate rows are kept only one copy)
sort file1 file2 | u niq -u deletes the intersection, leaving a different line
sort file1 file2 | u niq -d Takes out the intersection of the two files (leaving only the files that exist in both files)
comm -1 file1 file2 compares the contents of both files to remove only what 'file1' contains
comm -2 file1 file2 compares the contents of both files to remove only what 'file2' contains
comm -3 file1 file2 compares the contents of two files to delete only the parts that are common to both files
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 .. H TML < page .txt > page .html convert a text file to html
recode -l | m ore shows all allowed conversion formats
Badblocks -v /dev/hda1 checks for bad magnets on disk hda1
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 repair/check the integrity of the fat file system on the hda1 disk
fsck.msdos/dev/hda1 repair/check the integrity of the dos file system on the hda1 disk
Dosfsck/dev/hda1 repair/check the integrity of the dos file system on the hda1 disk
mkfs /dev/hda1 creates a file system in the hda1 partition
mke2fs /dev/hda1 creates a linux ext2 file system in the hda1 partition
mke2fs -j /dev/hda1 creates a linux ext3 (log type) file system in the hda1 partition
mkfs -t vfat 32 -F/dev/hda1 creates a FAT32 file system
fdformat -n /dev/fd0 formats a floppy disk
mkswap/dev/hda3 creates a swap file system
mkswap /dev/hda3 creates a swap file system
Swapon/dev/hda3 enables a new swap file system
Swapon/dev/hda2/dev/hdb3 enables two swap partitions
dump -0aj -f/tmp/home0.bak/home makes a full backup of the '/home' directory
dump -1aj -f /tmp/home0.bak/home makes an interactive backup of the '/home' directory
Restore -if/tmp/home0.bak restore an interactive backup
rsync -rogpav -delete/home/tmp syncs the directories on both sides
rsync -rogpav -essh -delete/home ip_address:/tmp via SSH channel rsync
rsync -az -e ssh --delete ip_addr:/home/public/home/local syncs a remote directory to the local directory through ssh and compression
rsync -az -e ssh -delete/home/local ip_addr:/home/public syncs the local directory to the remote directory through ssh and compression
dd bs=1M if=/dev/hda | g zip | s sh user@ip_addr 'dd of'hda.gz' to perform a backup of the local disk on the remote host via ssh
dd if/dev/sda of/tmp/file1 backs up disk contents to a file
The tar-Puf backup .tar/home/user perform an interactive backup of the '/home/user' directory
( cd /tmp/local/ && tar c . ) | s sh-C user@ip_addr 'cd/home/share/ s3 x -p' copies a directory content in a remote directory via ssh
( tar c /home ) | s sh-C user@ip_addr 'cd/home/home/home-home-tar x-p' copies a local directory in the remote directory via ssh
tar cf - . | ( cd /tmp/backup ; t ar xf - ) Copy one directory locally to another, retaining the original permissions and links
find /home/user1 -name '*.txt' | x args cp -av -target-directory-/home/backup/--parents find and copy all files ending in '.txt' from one directory to another
find /var/log -name '*.log' | t ar cv --files-from=- | b zip2 > log.tar.bz2 find all files ending in '.log' and make a bzip package
dd if/dev/hda of/dev/fd0 bs-512 count-1 does an act of copying MBR (Master Boot Record) content to a floppy disk
dd if/dev/fd0 of/dev/hda bs s/512 count-1 recovers MBR content from backups that have been saved to floppy disks
cdrecord -v gracetime-2 dev-/dev/cdrom-eject blank-fast-force empty a rewrote disc content
mkisofs/dev/cdrom > cd.iso create an iso image file of a disc on disk
mkisofs /dev/cdrom | g zip > cd_iso.gz create a compressed disc iso mirror file on disk
mkisofs -J -allow-leading-dots -R-V "Label CD" -iso-level 4 -o ./cd.iso data_cd Create an iso mirror file for a directory
cdrecord -v dev?/dev/cdrom cd.iso burn an ISO mirror file
gzip -dc cd_iso.gz | c drecord dev/dev/cdrom - Burn a compressed ISO mirror file
Mount -o loop cd.iso /mnt/iso mounts an ISO mirror file
cd-paranoia -B transfers from a CD to a wav file
cd-paranoia -- "-3" from a CD to a wav file (parameter-3)
cdrecord -- scanbus scans the bus to identify the scsi channel
dd if=/dev/hdc | m d5sum verifies a device's md5sum code, such as a CD
Ifconfig eth0 shows the configuration of an Ethernet card
Ifup eth0 enables an 'eth0' network device
Ifdown eth0 disables a 'eth0' network device
Ifconfig eth0 192.168.1.1 netmask 255.255.255.0 control IP address
Ifconfig eth0 promisc sets 'eth0' into a promised mode to sniff packets (sniffing)
dhclient eth0 enables 'eth0' in dhcp mode
route -n show routing table
route add -net 0/0 gw IP_Gateway configura default gateway
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network '192.168.0.0/16'
route del 0/0 gw IP_gateway remove static route
echo "1" > /proc/sys/net/ipv4/ip_forward activate ip routing
hostname show hostname of system
host www.example.com lookup hostname to resolve name to ip address and viceversa
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
ip link show show link status of all interfaces
mii-tool eth0 show link status of 'eth0'
ethtool eth0 show statistics of network card 'eth0'
netstat -tup show all active network connections and their PID
netstat -tupl show all network services listening on the system and their PID
tcpdump tcp port 80 show all HTTP traffic
iwlist scan show wireless networks
iwconfig eth1 show configuration of a wireless network card
hostname show hostname
host www.example.com lookup hostname to resolve name to ip address and viceversa
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa
whois www.example.com lookup on Whois database
The jps (Java Virtual Machine Status Process Tool) is a command provided by JDK 1.5 that shows all current java process pids, making it easy to look at some of the current java processes on the linux/unix platform.
I think a lot of people have used the ps command in the unix system, which is mainly used to show the progress of the current system, what processes, and their ids. T he same is true of jps, which displays the java process of the current system and its id number. We can use it to see how many java processes we have started (because each java program has an exclusive instance of a java virtual machine), and their process numbers (preparing for the following programs), and to see the detailed startup parameters for those processes through opt.
How to use: Hit jps on the current command line (requires JAVA_HOME, if not, to the directory of the changer).
jps are stored in JAVA_HOME/bin/jps and when used for convenience please add JAVA_HOME/bin/to Path.
$> jps
23991 Jps
23789 BossMain
23651 Resin
More commonly used parameters:
-q shows only pid, not class name, jar file name, and parameters passed to the main method
$> jps -q
28680
23789
23651
The -m output is passed to the parameters of the main method and may be null on the embedded jvm
$> jps -m
28715 Jps -m
23789 BossMain
23651 Resin -socketwait 32768 -stdout /data/aoxj/resin/log/stdout.log -stderr /data/aoxj/resin/log/stderr.log
-l Output the full package name of the application main class or the full path name of the application's jar file
$> jps -l
28729 sun.tools.jps.Jps
23789 com.asiainfo.aimc.bossbi.BossMain
23651 com.caucho.server.resin.Resin
The -v output is passed to the parameters of the JVM
$> jps -v
23789 BossMain
28802 Jps -Denv.class.path=/data/aoxj/bossbi/twsecurity/java/trustwork140.jar:/data/aoxj/bossbi/twsecurity/java/:/data/aoxj/bossbi/twsecurity/java/twcmcc.jar:/data/aoxj/jdk15/lib/rt.jar:/data/aoxj/jd
k15/lib/tools.jar -Dapplication.home=/data/aoxj/jdk15 -Xms8m
23651 Resin -Xss1m -Dresin.home=/data/aoxj/resin -Dserver.root=/data/aoxj/resin -Djava.util.logging.manager=com.caucho.log.LogManagerImpl -
Djavax.management.builder.initial=com.caucho.jmx.MBeanServerBuilderImpl
Sudo jps sees the most complete number of processes
jps 192.168.0.77
Lists all jvm instances of the remote server 192.168.0.77 machine, using the rmi protocol, with a default connection port of 1099
(provided that the remote server provides jstatd service)
Note: The jps command has a bad place, as if it can only show the java process of the current user, to show other users or only use the unix/linux ps command.
Reprinted: https://www.cnblogs.com/yjd_hycf_space/p/7730690.html
Linux's usual commands are complete
That's all the editor-in-chief has to offer you about Linux's common commands.