Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands in Linux system

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you what commonly used commands in the Linux system, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

System information

Arch # displays the processor architecture of the machine (1) uname-m # displays the processor architecture of the machine (2) uname-r # shows the kernel version in use dmidecode-Q # displays hardware system components-(SMBIOS / DMI) hdparm-I / dev/hda # lists the architecture characteristics of a disk hdparm-tT / dev/sda # performs tests on disk Sex read operation cat / proc/cpuinfo # display CPU info information cat / proc/interrupts # display interrupt cat / proc/meminfo # check memory use cat / proc/swaps # show which swap is used cat / proc/version # display kernel version cat / proc/net/dev # display network adapter and statistics cat / proc/mounts # display loaded files System lspci-tv # lists PCI devices lsusb-tv # displays USB devices

Date displays the system date

Cal 2007 # shows the 2007 calendar date 041217002007.00 # sets the date and time-month, day, hour, year. Second clock-w # saves time changes to BIOS

Shutdown (shutdown, restart and logout of the system)

Shutdown-h now # shuts down system (1) init 0 # shuts down system (2) telinit 0 # shuts down system (3) shutdown-h hours:minutes & # shuts down system at predetermined time shutdown-c # cancels shutdown system shutdown-r now # restarts at predetermined time (1) reboot # restarts (2) logout # logout

Files and directories

Cd / home # enter the'/ home' directory'cd.. # return to the previous directory cd.. /.. # return to the upper two-level directory cd # enter the personal home directory cd ~ user1 # enter the personal home directory cd-# return to the last directory pwd # display the working path ls # View the files in the directory ls-F # View the files in the directory ls-l # display the details of the files and directories ls-a # Show Show Hidden File ls * [0-9] * # Show file and directory names containing numbers tree # display the tree structure of files and directories starting from the root directory (1) lstree # display the tree structure of files and directories starting from the root directory (2) mkdir dir1 # create a directory called 'dir1'' mkdir dir1 dir2 # at the same time Two directories 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 rm-rf dir1 dir2 # delete both directories and their contents Mv dir1 new_dir # rename / move a directory cp file1 file2 # copy a file cp dir/*. # copy all files in 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 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) file file1 outputs the mime type of the file as text iconv-l # column Give the known code 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/ {}"\; batch resize files in the current directory and send them to a thumbnails directory (requires convert from Imagemagick)

File search

Find /-name file1 # enter the root file system from'/'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 files with' .bin 'ending in the directory' / home/user1' find / usr/bin-type f-atime + 100# search has been done Search the unused executable find / usr/bin-type f-mtime-10 # for files find /-name\ * .rpm-exec chmod 755'{} 'that were created or modified within 10 days. # search for files ending with '.rpm' and define their permissions find /-xdev-name\ * .rpm # search for files ending with '.rpm' Ignore locate for removable devices such as CD-ROMs, Agile drives, etc. Ps # find files ending in '.ps'-first run the 'updatedb' command whereis halt # to display the location of a binary file, source code, or man which halt # shows the full path of a binary file or executable file

Mount a file system

Mount / dev/hda2 / mnt/hda2 # Mount a disk called hda2-make sure the directory'/ mnt/hda2' already exists umount / dev/hda2 # Unmount a disk called hda2-first exit fuser from the mount point'/ mnt/hda2'-km / mnt/hda2 # Force unmount umount-n / mnt/hda2 # when the device is busy Operation without writing to the / etc/mtab file-very useful when the file is read-only or when the disk is full 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 userusername=user Passpassword=pass / / WinClient/share / mnt/share # Mount a windows network share

Disk space

Df-h # displays a list of mounted partitions ls-lSr | more # arranges files and directories by size du-sh dir1 # estimates the disk space used by dir1''du-sk * | sort-rn # displays the size of files and directories based on capacity rpm-Q-a-qf'{SIZE} t% {NAME} n' | | sort-K1Power1n # displays the space used by the installed rpm package according to the size (fedora) | Redhat type system) dpkg-query-W-favored ${Installed-Size 10} t ${Package} n'| sort-K1 Person1n # displays the space used by installed deb packages based on size (ubuntu, debian system)

Users and groups

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' excluding home directory) usermod-c "User FTP"-g system-d / ftp/user1-s / bin/nologin user1 # modify user attributes passwd # modify password passwd user1 # change a user's password (only root is allowed) chage-E 2005-12-31 user1 # set the expiration period of the user password pwck # check'/ etc / passwd' file format and syntax correction and existing user grpck # check'/ etc/passwd' file format and syntax correction and existing group newgrp group_name # login to a new group to change the default group of newly created files

Permissions for the file

Use "+" to set permissions Use "-" to cancel ls-lh # display permissions ls / tmp | pr-T5-W$COLUMNS # divide the terminal into five columns showing the owner (u), group (g) and others (o) of the chmod ugo+rwx directory1 # setting directory to read (r), Write (w) and execute (x) permissions chmod go-rwx directory1 # Delete group (g) and others (o) read and write permissions to the directory chown user1 file1 # change the owner property of a file chown-R user1 directory1 # change the owner attribute of a directory and change the properties of all files in the directory at the same time chgrp group1 file1 # change the text Group chown user1:group1 file1 # change the owner and group properties of a file find /-perm-UBSs # list all files in a system that use SUID control chmod Utility / 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 Umurs / bin/file1 # disable the SUID bit of a binary file chmod genders / home/public # set the SGID bit of a directory-similar to SUID However, this is to disable the SGID bit of a directory for chmod Gmurs / home/public # to set the STIKY bit of a file-only legitimate owners are allowed to delete the file chmod Omurt / home/public # disable the STIKY bit of a directory

Special properties of a file

-use "+" to set permissions, use "-" to cancel chattr + a file1 # only allow appending chattr + c file1 # allow this file to be automatically compressed / decompressed by the kernel chattr + d file1 # when backing up the file system, the dump program will ignore the file chattr + I file1 # and set it to an immutable file Cannot be deleted, modified, renamed or linked chattr + s file1 # allows a file to be safely deleted chattr + S file1 # once the application writes to the file, the system immediately writes the modified results to disk chattr + u file1 # if the file is deleted, the system will allow you to restore the deleted file lsattr # to display special properties

Package and compress files

Bunzip2 file1.bz2 # decompress a file called 'file1.bz2' # compress a file called' file1' gunzip file1.gz # extract 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 # simultaneously compress' file1' 'file2' and directory' dir1' rar x file1.rar # extract rar package unrar x file1.rar # extract rar package tar-cvf archive.tar file1 # create an uncompressed tarball tar-cvf archive.tar file1 file2 dir1 # create a file containing 'file1' The archives of 'file2' and' dir1' tar-tf archive.tar # show the contents of a package tar-xvf archive.tar # release a package tar-xvf archive.tar-C / tmp # release the package to the / tmp directory tar-cvfj archive.tar.bz2 dir1 # create a bzip2 format archive tar-jxvf archive.tar.bz2 # extract a bzip2 format Tar-cvfz archive.tar.gz dir1 # create a gzip format package tar-zxvf archive.tar.gz # decompress a gzip format package zip file1.zip file1 # create a zip format package zip-r file1.zip file1 file2 dir1 # compress several files and directories into a zip format at the same time unzip file1.zip # extract a zip format package

RPM package-(Fedora, Redhat and similar systems)

Rpm-ivh package.rpm # install a rpm package rpm-ivh-- nodeeps package.rpm # install a rpm package while ignoring dependency warnings rpm-U package.rpm # Update a rpm package without changing its configuration file rpm-F package.rpm # Update a confirmed installed rpm package rpm-e package_name.rpm # Delete a rpm package rpm-qa # display All installed rpm packages in the system rpm-qa | grep httpd # display 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" # display a component's rpm package rpm-ql package_name # display a list of files provided by the installed rpm package rpm-qc Package_name # displays a list of configuration files provided by the installed rpm package rpm-Q package_name-- whatrequires # shows a list of dependencies with a rpm package rpm-Q package_name-- whatprovides # shows the volume occupied by a rpm package rpm-Q package_name-- scripts # shows the script l rpm-Q package_name-- executed during installation / removal Changelog # displays the modification history of a rpm package rpm-qf / etc/httpd/conf/httpd.conf # confirm which rpm package provided the file rpm-qp package.rpm-l # displays a list of files provided by an uninstalled rpm package-- import / media/cdrom/RPM-GPG-KEY # Import public key digital certificate rpm-- checksig package.rpm # confirm one Integrity of rpm packages rpm-qa gpg-pubkey # verify the integrity of all installed rpm packages rpm-V package_name # check file size, License, type, owner, group, MD5 check and last modification time rpm-Va # check all installed rpm packages in the system-carefully use rpm-Vp package.rpm # to confirm that a rpm package does not have rpm2cpio package.rpm installed | cpio-- extract-- make-directories * bin* # run the executable file rpm-ivh / usr/src/redhat/RPMS/ `arch` / package.rpm # from a rpm package Source code installs a built package rpmbuild-- rebuild package_name.src.rpm # builds a rpm package from a rpm source code

YUM package upgrader-(Fedora, RedHat and similar systems)

Yum install package_name # download and install a rpm package yum localinstall package_name.rpm # will install a rpm package Use your own software repository to solve all dependencies for you 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 the rpm repository Find package yum clean packages # Clean rpm cache delete downloaded package yum clean headers # delete all header files yum clean all # delete all cached packages and header files

DEB package (Debian, Ubuntu and similar systems)

Dpkg-I package.deb # install / update a deb package dpkg-r package_name # Delete a deb package dpkg-l # display all installed deb packages in the system dpkg-l | grep httpd # display all deb packages with the word "httpd" in their names dpkg-s package_name # get a letter that has been installed in a special package in the system Dpkg-L package_name # displays a list of files provided by a deb package that has been installed in the system-- contents package.deb # shows a list of files provided by a package that has not been installed dpkg-S / bin/ping # confirm which deb package provides the files

APT software tools (Debian, Ubuntu and similar systems)

Apt-get install package_name # install / update a deb package apt-cdrom install package_name # install / update a deb package apt-get upgrade # in the upgrade list apt-get upgrade # upgrade all installed software apt-get remove package_name # remove a deb package from the system apt-get check # confirm the correct apt of the dependent software repository -get clean # Clean the cache from the downloaded package apt-cache search searched-package # returns the name of the package containing the string you want to search

View the contents of the file

Cat file1 # View the contents of a file forward from the first byte tac file1 # reverse view the contents of a file from the last line more file1 # view the contents of a long file less file1 # similar to the 'more' command But it allows the reverse operation head-2 file1 # to view the first two lines of a file tail-2 file1 # to view the last two lines of a file tail-f / var/log/messages # to view the contents added to a file in real time

Text processing

Cat file1 file2... | command file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT cat file1 | command (sed, grep, awk, grep, etc...) > result.txt # merge the detailed description text of a file and write the introduction to 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 to an existing file grep Aug / var/log/messages # look for the keywords "Aug" grep ^ Aug / var/log/messages # in the file'/ var/log/messages' find the word grep [0-9] / var/log/messages # Select'/ var/log/messages' file that starts with "Aug" in the file'/ var/log/messages' The line grep Aug-R / var/log/* # searches the directory'/ var/log' and subsequent directories for the string "Aug" stringa1 stop stringa2 example.txt # to replace "string1" in the example.txt file with "string2" sed'/ ^ $/ d 'example.txt # to delete all blank lines sed' / * # / d from the example.txt file / ^ $/ d 'example.txt # remove all comments and blank lines from the example.txt file echo' esempio' | tr'[: lower:]'[: upper:]'# merge the contents of the upper and lower cells sed-e '1d' result.txt # exclude the first line sed-n' / stringa1/p' # from the file example.txt to see the line containing only the word "string1" Sed-e's / * $/ / 'example.txt # Delete the white space character sed-e's sed at the end of each line sed-e's UniqqStringa1 and delete only the word "string1" from the document and retain all remaining sed-n '1Jue 5p 5q' example.txt # View the content from line 1 to line 5 sed-n'5p 5q' example.txt # View line 5 sed-e's file1 # replace multiple zero cat-n file1 # lines of the marked file with a single zero | 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 columns paste-d'+ 'file1 file2 # merge the contents of two files or columns Use "+" to distinguish between 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 is retained) sort file1 file2 | uniq-u # delete the intersection Leave other lines sort file1 file2 | uniq-d # take out the intersection of two files (only files that exist in both files) comm-1 file1 file2 # compare the contents of the two files delete only the contents contained in 'file1' comm-2 file1 file2 # compare the contents of the two files delete only the contents contained in' file2' comm-3 file1 file2 # compare two Delete only the common parts of the two files

Character setting and file format conversion

Dos2unix filedos.txt fileunix.txt # converts a text file format from MSDOS to UNIX unix2dos fileunix.txt filedos.txt # converts a text file format from UNIX to MSDOS recode.. HTML

< page.txt >

Page.html # converts a text file to html recode-l | more # displays all allowed conversion formats

File system analysis

Badblocks-v / dev/hda1 # check bad blocks on disk hda1 / dev/hda1 # repair / check integrity of linux file system on hda1 disk fsck.ext2 / dev/hda1 # repair / check integrity of ext2 file system on hda1 disk e2fsck / dev/hda1 # repair / check integrity of ext2 file system on hda1 disk e2fsck-j / dev/hda1 # repair / check the integrity of ext3 file system on hda1 disk fsck.ext3 / dev/hda1 # repair / check the integrity of ext3 file system on hda1 disk fsck.vfat / dev/hda1 # repair / check the integrity of fat file system on hda1 disk fsck.msdos / dev/hda1 # repair / check the integrity of dos file system on hda1 disk dosfsck / dev/hda1 # repair / check the integrity of the dos file system on hda1 disk

Initialize a file system

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) file system mkfs-t vfat 32-F / dev/hda1 # in hda1 partition create a FAT32 file system fdformat-n / dev/fd0 # format a soft Disk mkswap / dev/hda3 # creates a swap file system

SWAP file system

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

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 rsync-rogpav-e on both sides Ssh-- delete / home ip_address:/tmp # synchronizes a remote directory to a local directory through the SSH channel rsync rsync-az-e ssh-- delete ip_addr:/home/public / home/local # via ssh and compression rsync-az-e ssh-- delete / home/local ip_addr:/home/public # synchronizes a local directory to a remote directory dd bs=1M if=/dev/hda through ssh and compression | Gzip | ssh user@ip_addr'dd of=hda.gz' # perform a backup of the local disk on the remote host through ssh dd if=/dev/sda of=/tmp/file1 # backup the disk contents to a file tar-Puf backup.tar / home/user perform an interactive backup of 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 (tar c / home) via ssh | ssh-C user@ip_addr'cd / home/backup-home & & tar x-p'# copy a local directory tar cf -. | (cd / tmp/backup) Tar xf -) # copy one directory to another locally Retain the original permissions and link find / home/user1-name'* .txt'| xargs cp-av-- target-directory=/home/backup/-- parents # find and copy all files ending in '.txt' from one directory to another directory find / var/log-name'* .log'| tar cv-- files-from=- | bzip2 > log.tar.bz2 # find all texts ending in '.log' And make a bzip package dd if=/dev/hda of=/dev/fd0 bs=512 count=1 # do an action of copying MBR (Master Boot Record) content to a floppy disk dd if=/dev/fd0 of=/dev/hda bs=512 count=1 # restore MBR content from a backup that has been saved to a floppy disk

Optical disk

Cdrecord-v gracetime=2 dev=/dev/cdrom-eject blank=fast-force # clear a rewritable disc content mkisofs / dev/cdrom > cd.iso # create a disc iso image file mkisofs / dev/cdrom on disk | gzip > cd_iso.gz # create a compressed disc iso image file mkisofs-J-allow-leading-dots-R-V "Label CD"-iso-level on disk 4-o. / cd.iso data_cd # create a directory iso image file 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 # transcribe audio track from a CD CD to wav file cd-paranoia-"- 3" # transcribe audio track from a CD CD to wav file (parameter-3) cdrecord-scanbus # scan bus to identify scsi channel dd if=/dev/hdc | md5sum # verify the md5sum encoding of a device For example, a CD

Network-(Ethernet and WIFI Wireless)

Ifconfig eth0 # shows the configuration of an Ethernet card ifup eth0 # enable a 'eth0' network device ifdown eth0 # disable a' eth0' network device ifconfig eth0 192.168.1.1 netmask 255.255.255.0 # control IP address ifconfig eth0 promisc # set 'eth0' into promiscuous mode to sniff packet (sniffing) dhclient eth0 # enable 'eth0' route-n # in dhcp mode to view the routing table route add-net 0 gw IP_Gateway # configure the default gateway route add-net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 # configure a static route to the network' 192.168.0.0 route del 0 gw IP_gateway # Delete static route hostname # Look at the machine name host www.example.com # to resolve a host name to an Internet address or an Internet address to a host name. Nslookup www.example.com # is used to query DNS records to check whether domain name resolution is normal, and to diagnose network problems in case of network failure. Ip link show # View network card information mii-tool # used to view and manage the status of the network interface of the media ethtool # used to query and set up the network card configuration netstat-tupl # used to display TCP/UDP status information tcpdump tcp port 80 # shows the traffic of all http protocols

JPS tool

Jps (Java Virtual Machine Process Status Tool) is a command that displays the pid of all current java processes provided by JDK 1.5. It is simple and practical, and is very suitable for simply viewing some simple situations of the current java process on the linux/unix platform.

I think many people have used the ps command in the unix system, which is mainly used to show the process of the current system, what processes there are, and their id. The 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 started (because each java program will own an instance of the java virtual machine), and their process numbers (in preparation for the following programs), and we can view the detailed startup parameters of these processes through opt.

How to use it: type jps under the current command line (if you need JAVA_HOME, if not, type it in the directory of the modified program).

Jps is stored in JAVA_HOME/bin/jps. For convenience, please add JAVA_HOME/bin/ to Path. $> parameters commonly used in jps 23991 Jps 23789 BossMain 23651 Resin: #-Q displays only pid, not class name, jar file name and parameters passed to main method $> jps-Q 28680 23789 23651 #-m outputs parameters passed to main method On embedded jvm, it may be null $> 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 jar file pathname of the application $> jps-l 28729 sun.tools.jps.Jps 23789 com.asiainfo.aimc.bossbi.BossMain 23651 com.caucho.server.resin.Resin #-v output parameters passed to 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 jps 192.168.0.77 # list the jvm instances owned by the remote server 192.168.0.77 Using rmi protocol, the default connection port is 1099 (if the remote server provides jstatd services) # Note: the jps command has a very bad place, it seems that it can only show the current user's java process, to show that the above are all the contents of this article, "what are the common commands in the Linux system?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report