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

Summary of common commands in Linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

I briefly summarized it. I hope it will be helpful to all of you. Shutdown / restart shutdown poweroff # # immediate shutdown shutdown-h now # # immediate shutdown shutdown-h time # # automatic shutdown halt # # immediately shutdown init 0 # # shutdown system shutdown-c # # cancel timing shutdown logout # # logout # # briefly tell the difference between three immediate shutdowns: poweroff is a power off But in fact, it is also necessary to shut down the program before shutting down the computer. Halt is equivalent to shutodwn-h now. It just shuts down the system without power loss. The motherboard is powered on to restart shutdown-r now # # restart reboot # # immediately.

Note: both shutdown and restart operations require root permission

System information uname-r # # View system kernel version cat / proc/version # # display kernel version details arch # # View system processor is 32pm 64-bit uname-m # equivalent to arch cat / proc/cpuinfo # # View cpu details date # # display system time date + "time display format" # # display time in specified format clock-w # # write system time into hardware cal year # # View calendar of a certain year hostname # # View computer name After that, you can temporarily change the system name cat / etc/redhat-release # # View system version head / etc/issue # # View system version free-m # # View system memory usage df-h # # View system space usage du-sh # # View the size of the directory uptime # # View Department Unified Health ifconfig # # View network card information route-n # # View routing table netstat-anpt # # View established ports netstat-lnpt # # View all listening ports ps-ef # # View all processes top # # View cpu and processes in real time last # # View login log crontab-e # # create a task plan crontab-l # # View the current user's task schedule chkconfig-- list | grep on # # View which systems boot up the service program yum-y install package # # install the rpm software library automatically install the dependent library rpm-qa # # View all installed rpm programs iptables-L # # View the firewall settings file and Directory # when it comes to directories, you have to talk about absolute and relative paths. The absolute path is to write the path completely, that is to say, it starts from the root (/) directory; the relative location starts from the current directory, that is, from the current directory, the relative location represents ".."; cd # # enters the user's home directory cd. # # return one level cd directory name # # enter this directory pwd # # View the current working directory mkdir directory name # # create directory ls # # list all files in the current directory ls-a # # list all files including hidden files ls l = ll # # list the details of the files in the current directory tree # # tree Directory structure chart file touch file name # # create file rm-rf file / directory # # delete file or directory without prompting mv file / directory path / file / directory # # move files to another directory Rename cp file path / file name # # copy file to a directory cp-a directory / file path / file # # copy file or directory to a file ln-s file path / file # # create a connection ln-r directory path for a file or directory # # create a directory connection cat file # # View the file contents tac file # # View the contents of a file in reverse from the last line # # View the contents of a long file less file # # similar to the 'more' command But it allows reverse manipulation of head-2 file # # view the first two lines of a file tail-2 file # # view the last two lines of a file tail-f file # # dynamic display, real-time view the content added to a file vim file editor

Basic usage:

Vim file name

Basically, vi/vim is divided into three modes: command mode, input mode and bottom line command mode.

The default mode is command mode, which can only receive keyboard information and cannot change the file.

Use "I" to enter the input mode, which can make changes to the file

Enter input mode and enter ":" to enter bottom line command mode

Here are some simple vim shortcuts that I have summarized

Command mode: an insert An one bit after the cursor insert An at the end of the line I insert gg at the front of the line jump directly to the first line of the file G jump directly to the last line of the file dd delete line 3dd delete 3 lines yy copy line 3yy copy 3 lines p paste u undo v Enter character selection mode After selection, press y to copy, press p to paste ctrl+v to enter block selection mode, press y to copy, press p to paste shift+v to enter row selection mode, press y to copy, press p to paste to find and replace set null # # display line number set nonu # # hide line number / you # # find the you that appears in the keyword search file And locate the first place to find it. Press n to navigate to the next matching location (press N to navigate to the previous) s / character / replace with the character # # current line replacement operation% s/sad/bbb # # save and exit bottom line mode throughout the file: W # # save Q # # exit x # # save and exit wq # # save and exit Equivalent to x W # # set file password Q! # # force exit # # Note! If you exit without saving the settings after modification, you need to force the file to be unpacked, compressed, tar, packaged, tar cvf compressed, and the name to be compressed # # only the files that need to be appended to the tar rvf target file are not compressed. # # append the file to the target package file, tar unpack the tar xvf package file # # unpack the tar xvf package file- C target directory g # # unpack the package and extract it to the specified location gzip compressed gzip file # # compressed file using gzip compressed gzip decompressed gzip compressed package # # decompressed bzip2 compressed bzip2 file # # compressed file using bzip compressed bzip2 decompressed bunzip2 compressed package # unzipped zip compressed zip file # will Files are compressed in zip format unzip decompressed unzip decompressed directory zip compressed file # # decompressed zip package compressed tar zcvf packaged compressed file name to be packaged compressed file # # packaged and gzip compressed tar jcvf packaged compressed file name to be packaged compressed file # packaged and unzipped and unzipped using bzip2 method Tar zcvf file name # # unpack and decompress with-C specified file location tar jcvf file name # # unpack and extract with-C specified file location user and group 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 username # # create a new user userdel-r user # # Delete a user ('- r' also delete the home directory) passwd username # # modify the user password (note that this command requires root permission) chage-E time username # # set the expiration period of the user password The format is: Y-m-d useradd-g group name-d home directory-s / bin/bash user name # # create the user and set the group and home directory permission owner at the same time

Permissions are divided into the following three types of permissions:

R: readable w: writable x: executable example: drwxr-xr-x 2 root root 40 4 2019 a the above line is the first column that is viewed using ls to represent the permission column Don't say: d: identify the node type (d: folder -: file l: link) followed by permissions (three as a group): the first set of rwx represents the permissions owned by the owner this permission represents readable, writeable, executable, second, group permissions that belong to the group, and this permission indicates readable, executable, unwritable, third, except Permissions of others other than the group and the owner

Modify file permissions

Chmod g-rw file # # means to revoke the file's rw permission to the group to which it belongs. Chmod o-rw file # # means to revoke the file's rw permission to others. Chmod uplink file # # means to increase the file's permission to the user to which it belongs x chmod a+rwx file # # means that the file can also be used to add aux permission to the user to which it belongs. The following method (numbers represent permissions): chmod 777 file # # means to set full permissions to the file Equivalent to g o u with rwx permissions chmod-R permissions directory # # indicates that permissions will be set recursively, all of which are set for this file and the following subdirectories

Modify the file owner

Chmod user: user group file # # set user and user group chmod user file # # set user chmod: user group file # # set group RPM rpm-ivh software name # # installation package rpm-ivh-nodeeps software name # # installation package ignore dependency warning Rpm-U Software name # # Update the package without changing its configuration file rpm-F Software name # # Update the installed package rpm-e Software name # # Uninstall the package rpm-qa # # display all installed packages in the system rpm-qa | grep Software name # # shows all packages with the word "software" in the name rpm- Qg "group name" erases like a component's rpm package rpm-ql software name # # query an installed package rpm-Q software name-scripts # # query script rpm-qf configuration file directory # # View the software package rpm-qp software name to which the configuration file belongs-l # # query not Installed software package rpm-Vp software name # # check whether the package installs YUM

Yum is limited to operating systems with rhel kernels such as redhat, centos, Fedora, etc.

Yum install package name # # download and install a package yum update # # update all installed packages in the current system yum update software name # # update a rpm package yum remove software name # # uninstall a package yum list # # list all installation packages yum search software name # # find related packages yum clean packages # # clean the cache Delete the downloaded package yum clean all # # clear all package caches yum makecache # # mount the package cache mount mount the mount partition directory mount the partition # # mount the partition For example: mount / dev/sdb1 / opt/sdb1 mount floppy disk directory mount directory # # mount floppy disk mount CD directory mount directory # # mount CD mount-o loop iso file mount directory # # mount file or ISO image file mount-t vfat windows partition mount directory # # mount NTFS or FAT32 file system mount-t smbfs-o username= user name Password= password address mount directory # # Mount windows network share directory unmount umount partition name or mount directory name # # unmount mounted directory fuser-km partition directory # # Force unmount find file search find directory-name file name # # find the file find directory with this file name from this directory-user user name # # find the file or directory to which the user belongs from this directory find directory-name * file name # # find the file or directory find directory ending with this file name-type f-mtime-number of days # # find the find directory of files created or modified in this directory-type file type-atime + days # # in this directory Find files that have not been used in the past few days in the record

That's all for now, and we'll supplement it when we have time.

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