Help: LINUX common SHELL commands
1 file and directory operation commands
1. 1 file content query command
grep、fgrep、egrep
Code: [Copy to Clipboard] Syntax: grep[ Options] [Search Mode] [File name 1, file name 2, ...]
Options:
Quote:
-E Each pattern is treated as an extended regular expression.
-F Each pattern is treated as a set of fixed strings instead of regular expressions.
-i is case insensitive.
-l displays the file names of the first matching string, separated by line breaks. When the matching string appears in the file many times, the secondary file name is not displayed repeatedly;
-x only shows the exact match of the whole line.
1.2 file search command to find and locate
Grammar:
Code: [Copy to Clipboard] Find and start directory search condition operation.
Find by name and file attributes
Quote:
-name' string' finds all files whose file names match the given string. Wildcards *,? 、[]。
-lname' string' finds all symbolic link files whose file names match the given string. Wildcards *,? 、[]。
-gid n Find all files belonging to the user group with id number n. ..
-uid n Find all files belonging to the user with id number n. ..
-group' string' finds all files belonging to a user group with a given string.
-user' string' finds all files with the given string as the user name.
-path' string' finds all files whose path names match the given string. Wildcards *,? 、[]。
-perm permission to find files and directories with specified permissions. The expression of permissions can be: 7 1 1, 644.
-type x finds files of type x,
Grammar: looking up related words
1.3 Commands for copying, deleting and moving files
File copy command
Code: [Copy to Clipboard ]CP[ Options] Source file or directory Target file or directory.
Options:
Quote:
-a is usually used when copying directories.
Stay connected when copying -d
-f Deletes the existing target file without prompting.
The -i and f options are opposite.
-p At this time, cp not only copies the contents of the source file, but also copies the modified time and access rights to the new file.
-r If the given source file is a directory file, cp will recursively copy all subdirectories and files in this directory, and the target file must be a directory name;
-I don't copy, I just link files.
File move command
Code: [Copy to Clipboard ]mv[ Options] Source file or directory Target file or directory.
Quote:
-I. Interactive operation
-f Disable interactive operations
File deletion command
Code: [Copy to Clipboard ]rm[ Options] file …
Quote:
-f Ignore files that don't exist and never give a prompt.
-r instructs rm to recursively delete all directories and subdirectories listed in the parameter.
-i interactive deletion
1.4 file link command
Code: [Copy to Clipboard ]ln[ Options] Destination [Link Name] or ln[ Options] Destination Directory.
Quote:
Options:
-s establishes symbolic links
1.5 Directory creation and deletion commands
Mkdir creates a directory.
Grammar:
Code: [Copy to Clipboard ]mkdir[ Options] dirname
Options:
-m Set access rights for the newly created directory.
-p can be a path name. At this time, if some directories in the path do not exist yet, using this option, the system will automatically create those directories that do not exist, that is, multiple directories can be created at one time.
Rmdir delete empty directory
Grammar:
Code: [Copy to Clipboard ]rmdir[ Options] dirname
Quote:
Options:
-p recursively deletes dirname, and when the parent directory is empty after the subdirectory is deleted, it is also deleted.
1.6 command to change working directory and display directory contents
1, change working directory:
Code: [Copy to Clipboard ]CD[ Directory]
2. Displays the absolute path of the current working directory:
Code: [Copy to Clipboard] Password
3. Display the contents of the directory:
Code: [Copy to Clipboard ]ls[ Options] [Directory or Document]
Quote:
Options:
-a displays all subdirectories and files in the specified directory, including hidden files.
-c Sort by file modification time.
-C Displays items in multiple columns.
-d If the parameter is a directory, only its name will be displayed, and the files under it will not be displayed.
-F is marked with "/"after directory name, "*" after executable file, "@" after symbolic link, "|" after pipeline (or FIFO) and "=" after socket file.
-l Displays the details of the file in a long format.
-L If the specified name is a symbolic link, the file that the link points to is displayed.
-t is displayed by modification time instead of name.
-u Displays the file by the time it was last accessed, not by name.
4, change the file or directory access command
Code:[ copy to clipboard] chmod [who] [+|-| =] [mode] file name?
Quote:
Who options:
-u represents the user, that is, the owner of files and directories.
-g indicates users in the same group.
-o (Other) indicates other users.
-a (all) means all users.
Quote:
Operation symbol:
+Add Permission-Remove Permission
= Grant the given permission and cancel all other permissions (if any).
Quote:
Mode options:
-r readable
-w writable
-x executable file
CODE:[ copy to clipboard ]chgrp [-R] group file name? Change the group to which a directory or file belongs.
Code: [copy to clipboard] chow [-RV] user or group file.
1.7 backup and compression commands
1, tar command creates archives for files and directories.
Grammar:
Code: [copy to clipboard ]tar[ primary option+secondary option] file or directory.
Quote:
U main option
Create a new archive file. Select this option if users want to back up directories or some files.
R Append the file to be archived to the end of the archived file.
T List the contents of archived files to see which files have been backed up;
U update file
X release files from archive files;
U auxiliary option
B This option is set by the tape drive, followed by a number to indicate the size of the block. The system default value is 20.
Use archive files or equipment. This option is usually required.
K save the existing file. For example, if a file is restored, the same file will not be overwritten during the restoration process;
M When restoring files, set the modification time of all files to now;
M. Create multi-volume archive files and store them on several disks;
V reports the file information processed by tar in detail.
Every step needs to be confirmed.
Z uses gzip to compress/decompress files.
2.gzip command compression/decompression command
Grammar:
Code: [Copy to Clipboard ]gzip[ Options] Compress (decompress) the file name.
Quote:
Options:
-c Write the output to standard output and keep the original file.
-d decompresses the compressed file.
-l displays the details of each compressed file.
-r recursively finds the specified directory and compresses or decompresses all files in it.
-t Test and check whether the compressed file is complete.
-v For each compressed and decompressed file, the file name and compression ratio are displayed.
3. Decompression command
Files compressed by winzip, a compression software under MS windows, are expanded under linux system.
Grammar:
Code: [Copy to Clipboard] Unzip [Options] Compressed file name.
Quote:
Options:
-x file list decompresses the file, but does not include the specified file.
-v View the compressed file directory, but do not extract it.
-t Test the file for corruption, but do not extract it.
-d directory unzips the compressed file into the specified directory.
-z only displays the comments of the compressed file.
-n Do not overwrite the existing file.
-o Overwrites the existing file without user confirmation.
-j Extract all files into the same directory without rebuilding the directory structure of the document.
1.8 Run DOS command in LINUX environment.
Linux system provides a set of portable tools called mtools, which allows users to easily read and write files and directories from standard DOS floppy disks.
Quote:
Mcd directory name change MSDOS directory.
Mcopy source file target file copies files between MSDOS and UNIX;
Mdel directory name delete MSDOS directory
Mdir directory name displays the MSDOS directory.
The mformat drive letter creates the MSDOS file system on a low-level formatted floppy disk.
Rnlabel drive letter generates MSDOS volume label.
Mmd Directory Name Delete MSDOS Directory
Mren Source File Target File Renames an existing MSDOS file.
The mtype file name displays the contents of the MSDOS file.
2 equipment management command
1)linux defines an IDE hard disk in the following form:
Code: [Copy to Clipboard ]/dev/HD[ Drive] [Partition]
2)SCSI hard disk is represented by the same mechanism:
Code: [copy to clipboard ]/dev/SD[ drive] [partition]
3) For a general LINUX partition, it can be formatted with mkfs to generate a file system. The command is as follows:
Code: [copy to clipboard] mk2fs–c <; Partition & gt;; & ltsize & gt;
4) Mount the file system:
Code: [copy to clipboard] mount–t ext 2 [-o optioms] partition mount point.
Among them,
Quote:
-t is the type of the specified mount file system;
-o Specify some options, such as read-only ro, readable and writable rw, etc.
Partition defines the partition name;
Mountpiont defines the name of the directory where the file system is mounted.
5) Mount the CD file system:
Code: [copy to clipboard] mount–t iso 9660–r/dev/cdrom/mnt/cdrom.
6) Install the floppy file system:
Code: [copy to clipboard] mount–t msdos–rw/dev/fd0/dev/mnt/floppy.
7) Unmount the file system
Code: [copy to clipboard ]umount /mnt/cdrom
Attention should be paid to the following points in the installation of belt equipment:
Quote:
1. First, select a unique SCSI ID number, and then link the device to the appropriate location.
2. Select the driver.
3. Generate the equipment file. SCSI tape devices have a primary device number of 9 and a secondary device number of 0. The file name of the device is usually /dev/nrst0 (a tape device that does not support rewinding) or /dev/nst0 (a tape device that supports rewinding).
Use ls /dev/*rst*
Check whether the tape device file exists, and if not, use the.
mknod–m 666/dev/nrst 0 c 9 9
MKNOD–M666/Dev/RST0C90 Generation
4. You can set some parameters, such as block length, cache and tape density, such as
Mt setblk 20 specifies a block length of 20.
Mt setblk 0 specifies that there is no limit to the blocking degree.
5. By checking the startup information of the system, you can determine whether the system recognizes the new tape device. Use the dmesg command to see if there is information similar to the following:
Aha 274 x:target 4 is now synchronized at 4.4 MB/s.
Supplier: TANDBERG Model: TDC 3800 Version: =05:
Type: sequential access ANSI SCSI version: 02
Scsi tape st0 was detected at scsi0, id4, lun0.
Scsi: A total of 1 SCSI tapes 1 SCSI crom 1 SCSI disks were detected.
3 package management command
3. 1 software installation steps
The steps of installing software on LINUX system are as follows:
Quote:
1. Locate the source file of the software to be installed.
2. Unzip the source file and put it in a directory. The command is as follows:
Tarzxvf < source file name >;
3. Configure the source files for this operating system. You can edit the make file or other files, or run the automatic configuration tools included with the software, such as. /configure。
4. make source files and run the make command at ordinary times, that is, execute make.
5. Install binaries and other supporting files, and run the command: make install.
6. Finally, complete all other necessary configurations.
3.2 Software Package Management Command
Quote:
rpm–IVH & lt。 Software package >;
//Install the specified software package, and indicate the installation progress with # during the installation process.
rpm–Uvh & lt; Software package >;
//Update existing or uninstalled packages and delete all old versions of packages.
rpm–e
//uninstall an rpm package.
Rpm-–quality assurance
//View the installed software packages in the system.
rpm–q & lt; Software package >;
//View the version number of a software package in the system;
rpm–qlp & lt。 Software package >;
//List all files in the package.
rpm–qf & lt; Software package >;
//Find out which package a file belongs to.
4 LINUX system common commands
4. 1 Commands related to system management
Wall (write all)
Quote:
To send information to all logged-in users, users can first write the information to be sent in a file, and then enter:
# wall & lt file name
Example: wall "Thank you!"
write
Send information to users.
Write xxq
hello
Enter Ctrl+C to terminate.
Close command
Code: [Copy to Clipboard] Shutdown [Options] [Time] [Warning Message]
Quote:
-k didn't really turn it off, just sent a warning message to all users.
-r Restart immediately after shutdown.
-h Do not restart after shutdown.
-f fast shutdown, skip fsck when starting.
-n Quick shutdown, no initialization procedure.
-c Cancel the shutdown that has been run.
Example: the system shuts down immediately: Shutdown -h now.
Free command
Check the current system memory usage,
Code: [copy to clipboard ]Free [-b] [-k] [-m]
Code: [Copy to Clipboard ]-b is displayed in bytes.
-k is displayed in units of k bytes.
-m is displayed in m bytes.
uptime
Quote:
Displays how long the system has been running: current time, how long the system has been running, how many logged-in users, and the average load of the system in the past 1 minute, 5 minutes and 15 minutes.
4.2 Commands related to users
Passwd command
Set and change user passwords.
Code: [Copy to Clipboard] Password [User Name]
Soviet Union (short for USSR)
Let an ordinary user have superuser privileges and leave an available exit command.
4.3 Other orders
Echo command
Display a paragraph of text on the display, usually as a reminder.
Code: [copy to clipboard ]echo [-n] string.
Calibration command
Calendar showing year and month.
Code: [Copy to Clipboard ]cal[ Options] [Month [Year]]
Quote:
Meaning of the option:
-j means that every day in a given month is a year and a few days (counting from 1+0).
-y displays the calendar for the whole year.
Date command
The function of the date command is to display and set the system date and time.
4.4 Disk management
Disk space management
Direction finding command
Check the disk space usage of the file system.
Code: [Copy to Clipboard ]Df[ Option]
Quote:
-a shows the disk usage of all file systems, including 0 file systems, such as /proc file system.
-k is displayed in units of k bytes.
-i displays I-node information instead of disk blocks.
-t Displays the disk space usage of each specified file system.
-x lists the usage of disks that are not in the specified file system (as opposed to t).
-T displays the file system type.
Du command
The original English meaning of du is disk usage, which means to display the usage of disk space. The function is used to count the disk space occupied by a directory (or file).
Code: [Copy to Clipboard ]du[ Options] [Name …]
Quote:
-s The total number of data blocks occupied by only the Names parameter per person.
-a recursively displays the total number of data blocks occupied by each file in the specified directory and each file in subdirectories.
-b Lists disk usage in bytes (by default, in K bytes).
-k Lists disk space usage in units of 1024 bytes.
-c Add total at the end (system default)
-l Calculate the size of all files, and for hard-linked files, calculate it multiple times.
-x skips directories on different file systems and is not counted.
Dd command
Copy the specified input file to the specified output file, and format conversion can be performed during the copying process. Grammar:
Code: [Copy to Clipboard ]DD[ Option]
Quote:
If = input file (or device name).
Of = output file (or device name).
Ibs = bytes reads bytes at a time, that is, the number of bytes read into the buffer.
Skip = blocks skips the ibs*blocks block at the beginning of the read buffer.
Obs = bytes Write bytes at a time, that is, the number of bytes written into the buffer.
Bs = bytes sets the number of bytes in the read/write buffer at the same time (equal to setting obs and obs).
Cbs = bytes converts bytes at a time.
Count = blocks copies only the entered blocks.
Conv = ASCII converts EBCDIC code into ASCII code.
Conv = EBCDIC converts ASCII code into EBCDIC code.
Conv = ibm converts ASCII code into EBCDIC code.
Conv = blick converts variable bits into fixed characters.
Conv = ublock converts fixed bits into variable bits.
Conv = ucase changes letters from lowercase to uppercase.
Conv = lcase changes letters from uppercase to lowercase.
Conv = notrunc does not truncate the output file.
Conv = swab swap each pair of input bytes.
Conv = noerror does not stop processing when an error occurs.
Conv = Synchronize the size of each input record to the size of ibs (filled with ibs).
Fdformat command
Low-level formatted floppy disk.
Code: [Copy to Clipboard] format [-n] device
Quote:
-n format, no need to check.
4.5 Common network commands
FTP command
Telnet command.
Netstat command
Quote:
-a shows all scoket, including listening and.
-c will be displayed again every 1 second until the user interrupts it.
-i displays information of all network interfaces in the same format as "ifconfig–e"
-n Replace the name with the network IP address to show the network connection.
-r displays the core routing table in the same format as "route–e:".
-t shows the connection of TCP protocol.
-u shows the connection of UDP protocol.
-v shows the work in progress.
The nslookup command.
Finger command, the function is to query the information of users.
Ping command.
(Users and groups can be managed by tools: TurboUserCfg or XturboUserCfg. )
4.6 Orders related to the process.
Process and start-up
Code: [Copy to Clipboard] at [-v] [-q] [-f file name] [-mldbv] time.
At–c homework [homework ...]
The process system started by the AT command is only executed once.
Batch [-V] [-q Queue] [-f File Name ][-mv][ Time]
It is executed when the system load is small and resources are idle.
Cron command
Execute orders regularly.
Crontab command
Table for installing, removing or listing cron daemons.
Process view
Code: [copy to clipboard ]who command.
W command
Is a more powerful order than the World Health Organization.
W-[husfV][ user]
-h Do not display the title.
-u Ignore the user name when listing the current process and CPU time.
-s uses short mode. Login time JCPU and PCPU time are not displayed.
-f Toggles the display of the FROM item (that is, the remote hostname item).
-V displays version information.
Users only display the situation of the specified users.
Ps command.
-e shows all processes.
-f full format
-h Do not display the title.
-l long format.
-w wide output.
Displays all processes on the terminal, including those of other users.
R Only the running processes are displayed.
X represents the process that does not control the terminal.
Supreme order
Dynamically display the current progress and other conditions of the system.
5 system startup process.
5. 1 initial startup
When the PC is started, the BIOS reads the Master Boot Record (MBR) from the designated boot device. The format of MBR is:
Address offset content size
+00 h executable code (startup module) may change.
+1BE h 1st partition table entry 16 bytes
+1CE h second partition table entry 16 bytes
+1DE h third partition table entry 16 bytes
+1 4th partition table entry 16 bytes
+1FE h executable tag (AA55 h) 2 bytes
The startup module contains enough code to load the operating system, or the location where the code is loaded in the second step. The startup module needs to use BIOS calls to load data from the disk. These interrupt calls, such as INT 13h, limit the maximum number of disk columns to 1023. This means that everything that needs to be loaded in the startup module, such as initial memory disk, kernel and startup time information, must be stored in 1024 cylinders.
There are only four partition table entries in MBR, and the format of each table entry is as follows:
Address offset content size
+00h partition status: 00 represents non-boot partition, 80h represents boot partition, 1 byte.
+0 1h Starting position of partition header 1 byte
Partition +02h cylinder and the starting position of sector 1 byte.
+04h partition type 1 byte
End position of +05h partition header 1 byte
End position cylinder and sector of +06h partition 1 byte
+08h The number of sectors between the main boot area and the first sector of the partition is 4 bytes.
The number of sectors in the +0Ch partition is 4 bytes.
5.2 Linux startup process
Command line parameters for 1 startup
When Linux starts, it will process all the command line parameters passed to it. This will affect the way Linux works. Command line parameters include:
Quote:
Mem=xxxM: determines the memory size that Linux can use. This is only necessary if the memory of the user's computer system exceeds 64MB. Because the previous motherboard only cached the first 64MB of memory, using more than 64MB of memory would reduce the performance of the whole computer, and all the memory would run at a speed without caching.
Single: causes Linux to start in single-user mode, and the default mode is multi-user.
Root=/dev/xxx: Specifies the device where Linux will be installed as the root file system.
Init =< file & gt;; : Specifies the file as the initialization process.
initrd = & ltdev & gt; : Specifies the device as the initial memory disk.
Ro: Specifies that the root file system is read-only.
Rw: Specifies that the root file system is readable and writable.
2 Initialization process
After the kernel initializes itself and the found hardware devices, it starts the process init(/sbin/init) in the background, and the init process number is 1.
There are many versions of the startup process in the UNIX world, some based on system V and some based on BSD. Most Linux versions use the implementation method of system V, which is introduced here.
Init is controlled by the contents and functions of the /etc/inittab file, depending on whether the startup mode is single-user or multi-user.
Quote:
Single user mode: the init process ignores the /etc/inittab file and calls /dev/console shell after executing some script programs. In this way, users can have a shell and perform certain tasks.
Multi-user mode: the init process takes the system to the run level specified in the /etc/inittab file. Init enters the specified progress level through standard Linux methods.
3. Level of progress
Like other UNIX operating systems, Linux can be at any running level at any time. These run levels provide different functions, mainly because they run different service programs (daemons). Linux*** has six running levels.
Quote:
0: Turn off the computer or terminate the computer operation. At this level, the system stops operating.
1: single-user startup level. Only one user in the system, namely root, logs in at the console.
2: Multi-user running level, but no network function. At this run level, the network function will not start, but the system allows multiple users to log in, whether through the virtual console or serial line.
3. Multi-user mode with network function. At this run level, all standard network services will be started.
4. It has not been realized yet.
5: X 1 1 running level. At this run level, the X server software runs and provides a graphical interface login mode.
6: System restart.
Query the current running level: runlevel;;
4 scripts run during startup
When the init process runs, it is responsible for viewing the default run level and entering it. This is achieved by a script program running in the directory /etc/rc.d/rcX.d, where x stands for run level, that is, one run level corresponds to one directory. Files with different letters have different functions. These include:
The script program starting with k is executed when the system leaves a certain running level, and its function is to stop a service. When the system switches from one support level to another, all k programs corresponding to the original running level must be executed first.
The script program starting with S is executed when the system enters a certain running level, and its function is to start a service. When the system changes to a certain running level, all S programs corresponding to the new running level need to be run.
5. Add the startup script.
Users may have some specific hardware devices to initialize, or need to initialize some other applications when the system starts. Users can add their own initialization scripts to accomplish these tasks. The usual steps are:
Copy an existing script so that you can get a common framework format.
Modify this script to meet your own requirements, and be careful to enable the program to handle startup and shutdown parameters, even though it may shut down without doing anything.
Copy this branch to the directory /etc/rc.d/init.d and name it "serv".
Establish an operation control link in the corresponding directory, as shown below:
Code: [copy to clipboard] ln–s ../init.d/serv/etc/rc.d/rc3.d/s99 server.
Conduct a test.
6 LILO and other startup modules
To start Linux, the startup module is necessary. The boot module commonly used in Linux is LILO, and LILO replaces the general main boot area with its own main boot area. Lilo can be configured by modifying the contents of the /etc/lilo.conf file, and the contents of the boot area can be updated by the LILO command.
The following is also the lilo.conf file of a computer with DOS, TurboLinux3.4.0 and RedHat 5.2 installed. The numerical symbols in the example are added by the user and will be explained in detail in this article.
Code: [copy to clipboard ]# more /etc/lilo.conf
Boot = development /had
map=/boot/map
instll/boot/boot.b
point out
# indicates that the startup disk is /dev/had, which is the main IDE hard disk.
Timeout =50
# indicates that the waiting time for user input is 50 seconds.
Default value =TL3.4
Others =dev/hda 1
# indicates that if there is no input within the above time, the default startup system is TL3.4, namely TurboLinux 3.4.0.
Label =dos
table=dev/had
# indicates that the user presses LILO.
image=/mnt/tl3.4/boot/vmlinuz
Label =TL3.4
root=/dev/hda3
read only
The startup file /mnt/tl3.4/boot/vmlinuz of TurboLinux is determined, and the root file system is in /dev/hda3, which is read-only.
Code: [copy to clipboard] image =/mnt/rh5.2/boot/vmlinuz-2.0.36-0.7.
label=RH5.2
root=/dev/hda4
read only
The startup files of RedHat are determined, /mnt/rh5.2/boot/vmlinuz-2.0, 36-0.7, and the root file system is in /dev/hda4, which can be read and written.