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

Commonly used Linux shell command collation

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "commonly used Linux shell command finishing". In daily operation, I believe that many people have doubts about the commonly used Linux shell command finishing problems. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "commonly used Linux shell command finishing"! Next, please follow the editor to study!

1 File and directory operation command

1.1 File content query commands grep, fgrep, egrep

Syntax: grep [options] [find mode] [file name 1, file name 2,...]

Options:

-E each pattern is treated as an extended regular expression

-F each pattern is treated as a set of fixed strings, not as a regular expression

-I is not case-sensitive when comparing

-l displays the file name that matches the string for the first time and separates it with a newline character. When a matching string appears multiple times in the file, the secondary file name is not repeated.

-x displays only rows that strictly match the entire row

1.2 File lookup commands find, locate

Syntax:

Find start directory search condition action to find by name and file attribute

Option:-name' string 'finds all files whose file names match the given string. Wildcards *,? are available in the string. 、 [] .

-lname' string 'finds all symbolic link files whose file names match the given string. Wildcards *,? are available in the string. 、 [] .

-gid n finds all files that belong to the user group with ID number n.

-uid n finds all files belonging to the user with ID number n.

-group' string 'finds all files that belong to the user group with the given string name.

-user' string 'finds all files that belong to the given string with the username.

-path' string 'finds all files whose pathnames match the given string. Wildcards *,? are available in the string. 、 [] .

-perm permission to find files and directories with specified permissions, which can be represented as 711,644.

-type x looks for files of type x

Syntax: locate related words

1.3 commands for copying, deleting and moving files

[option] Source file or directory destination file or directory

Options:

-an is usually used when copying directories

-d keep the connection when copying

-f Delete an existing target file without prompting

-I and f options are opposite

-p at this time, cp not only copies the contents of the source file, but also copies its modification time and access rights to the new file.

-r if the source file given is a directory file, cp will recursively copy all subdirectories and files under that directory, and the target file must be a directory name

-l does not make a copy, but only links the file move command

Mv [options] Source file or directory destination file or directory

-I interactive operation

-f disables interactive file deletion commands

[options] File...

-f ignores files that do not exist and never gives prompts

-r instructs rm to delete all directories and subdirectories listed in the parameter recursively

-I carry out interactive delete 1.4 file link command

Ln [option] destination [link name] or ln [option] destination directory

Options:

-s to establish symbolic links

1.5 create and delete a directory commands mkdir create a directory

Syntax: [options] dirname

Option:-m set access to the new directory

-p can be a path name. At this time, if some directories in the path do not already exist, add this option, the system will automatically establish those directories that do not already exist, that is, multiple directories can be established at a time.

Rmdir delete empty directory

Syntax: rmdir [options] dirname

Options:

-p the directory dirname is deleted recursively, and is also deleted when the parent directory is empty after the subdirectory is deleted.

1.6 change the working directory to display the directory contents command

1. Change the working directory: cd [directory]

2. Display the absolute path of the current working directory: pwd

3. Display directory contents: ls [option] [directory or file]

Options:

-a displays all subdirectories and files under the specified directory, including hidden files

-c sort by the modification time of the file

C is divided into multiple columns to display items

-d if the parameter is a directory, only its name is displayed, not the files under it

-F marks "/" after the directory name, "*" after the executable, "@" after the symbolic link, "|" after the pipe (or FIFO), and "=" after the socket file.

-l displays the details of the file in a long format

-L displays the file to which the link points if the specified name is a symbolic link

-t is sorted by modification time instead of name when displayed

-u is displayed, sorted by the time the file was last accessed rather than by name

4. Change the access permissions of a file or directory command chmod [who] [+ |-| =] [mode] filename?

Who options:

-u represents the user, that is, the owner of files and directories

-g represents the same group of users

-o (other) indicates other users

-a (all) represents all users

Action symbol: + add a permission-cancel a permission = grant a given permission and cancel all other permissions (if any)

Mode options:

-r readable

-w writable

-x executable chgrp [- R] group filename? Change the group to which the directory or file belongs

Chown [- Rv] user or group file

1.7 backup and Compression Command

1. The tar command creates an archive syntax for files and directories:

Tar [primary option + secondary option] file or directory: U primary option

-c create a new archive file. Select if the user wants to back up a directory or some files

-r append the file to be archived to the end of the archive file

-t list the contents of the archive files to see which files have been backed up

-u update the file

-x release the file from the archive

-u secondary option

-b this option is set for the tape drive, followed by a number to indicate the size of the block. The system default value is 20.

-f use archives or devices, this option is usually required

-k saves files that already exist. For example, if you restore a file, if you encounter the same file during the restore process, you will not overwrite it.

-m when restoring files, set the modification time of all files to now

-M creates multi-volume archives for storage on several disks

-v detailed report on file information processed by tar

-w confirmation is required at each step

-z use gzip to compress / extract files

2. Gzip command compress / decompress command

Syntax: gzip [option] compressed (unzipped) file name

Options:

-c writes the output to standard output and keeps the original file

-d decompress the compressed file

-l displays the details of each compressed file

-r recursively find the specified directory and compress all the files in it or decompress it

-t test and check whether the compressed file is complete

-v displays the file name and compression ratio for each compressed and unzipped file

3. Unzip command to expand the files compressed by winzip under MS windows under the linux system

Syntax: unzip [option] compressed file name. Zip

Option:-x file list unzips the file, but does not include the specified file file

-v View the directory of compressed files, but do not extract them

-t test the file for corruption, but do not extract it

-d directory unpack the compressed files to the specified directory

-z displays only comments for compressed files

-n does not overwrite existing files

-o overwrite existing files and do not require user confirmation

-j does not reconstruct the directory structure of the document, but decompresses all files to the same directory

Running DOS commands in LINUX the linux system provides a set of portable tools called mtools that allow users to easily read and write files and directories from standard DOS floppy disks.

Mcd directory name change MSDOS directory mcopy source files destination files copy files between MSDOS and UNIX

Mdel directory name deletion MSDOS directory mdir directory name display MSDOS directory mformat drive letter create MSDOS file system rnlabel drive letter on a low-level formatted floppy disk generate MSDOS volume label mmd directory name delete MSDOS directory mren source file destination file rename existing MSDOS file mtype file name display the contents of MSDOS file

2 device management commands

1) linux defines an IDE hard disk in the following form: / dev/hd [drive] [partition]

2) SCSI hard disk uses the same mechanism to express: / dev/sd [drive] [partition]

3) for a general LINUX partition, you can format it with mkfs and generate a file system, as follows: mk2fs-c

4) Mount the file system:

Mount-t ext2 [- o optioms] partition mountpiont

-t is the specified type of mounted 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 CD-ROM file system: mount-t iso9660-r / dev/cdrom / mnt/cdrom

6) Mount the floppy drive file system: CODE: [Copy to clipboard] mount-t msdos-rw / dev/fd0 / dev/mnt/floppy

7) Unmount the file system CODE: [Copy to clipboard] the installation of umount / mnt/cdrom tape devices should pay attention to the following:

1. First select a unique SCSI ID number, and then link the device to the appropriate location

2. Select the driver.

3. Generate device files. The primary device number of the SCSI tape device is 9 and the secondary device number is 0. The device file name is usually / dev/nrst0 (tape devices that do not support rewinding) or / dev/nst0 (tape devices that support rewinding) check whether the tape device file exists with ls / dev/*rst*, and if not, generate it with mknod-m 666 / dev/nrst0 c 9 9 mknod-m 666 / dev/rst0 c 90

4. You can set some parameters such as block length, cache, tape density and so on. For example, mt setblk 20 specifies the block length as 20 mt setblk 0 and specifies that there is no limit to the block degree.

5. By checking the startup information of the system, we can determine whether the system has identified the new tape device. Use the dmesg command to see if you have the following similar information: aha274x:target 4now synchronous at 4.4Mb/s Vendor:TANDBERG Model:TDC 3800 Rev: = 05: Type: Sequential-Access ANSI SCSI revision: 02 Detected scsi tape st0 at scsi0, id4, lun0 Scsi: detected 1 SCSI tape 1 SCSI crom 1 SCSI disk total

3 software package management commands

Software installation steps to install software on a LINUX system are:

1. Find the source file of the software you want to install

2. Unlock the source file and put it in a directory with the following command: tar zxvf

3. Configure the source file for this operating system. It can be editing make files or other files, or it may be an automatic configuration tool that comes with running the software, such as. / configure

4. Make source files, usually run the make command, that is, execute make

5. Install binaries and other supporting files, and run the command: make install

6. Finally, complete all other necessary configurations

The package management command QUOTE: rpm-ivh; / / installs the specified package and uses # to indicate the installation progress during the installation process rpm-Uvh; / / updates an existing or uninstalled package and removes all old versions of the package. Rpm-e / Uninstall a rpm package rpm-qa / / check the package rpm-Q that has been installed on the system; / / check the version number of a package in the system; rpm-qlp; / / list all the files in a package rpm-qf; / / find out which package a file belongs to

4 commands commonly used in LINUX system

4.1 the system administration-related command Wall (Write All) sends messages to all logged-in users. Users can first write the information to be sent and save it in a file, and then enter: # wall < FileName example: Wall 'Thank you!' Write sends a message to a user. Write xxq hello enter Ctrl+C combination to terminate the Shutdown command Shutdown [option] [time] [warning]

-k doesn't really turn it off, but just sends a warning message to all users.

-r restart immediately after shutdown.

-h do not restart after shutdown.

-f quickly shut down and skip fsck at startup.

-n shut down quickly without going through init program.

-c cancel a running shutdown example: system shutdown immediately: Shutdown-h now Free command to check the use of the current system memory, CODE: [Copy to clipboard] Free [- b] [- k] [- m] CODE: [Copy to clipboard]-b is displayed in bytes.

-k is displayed in K bytes.

-m is displayed in M bytes. Uptime QUOTE: shows how long the system has been running: the current time, the time the system has been running, how many logged in users are currently, and the average load of the system in the past 1 minute, 5 minutes, and 15 minutes.

4.2 user-related commands Passwd commands to set and change user passwords.

Passwd [user name] Su gives an ordinary user the right to superuser, leaving the available EXIT command. Other commands Echo commands display a piece of text on the monitor, which generally serves as a prompt.

The echo [- n] string Cal command displays the calendar for a certain month of a year.

Cal [option] [month [year]]

The meaning of the option:

-j also shows that each day of the given month is the day of the year and several days (from January 1).

-y shows the calendar for the whole year. The function of the Date command date command is to display and set the system date and time. The disk Management disk Space Management df command checks the disk space footprint of the file system.

Df [options]

"- a displays the disk usage of all file systems, including 0 (block) file systems, such as / proc file systems."

-k is displayed in K bytes.

"- I displays I node information, not disk blocks."

-t displays the disk space usage of each specified type of file system.

-x lists disk usage that is not of a specified type of file system (as opposed to t).

-T displays the file system type. The du command du means disk usage in English, which means to show the use of disk space. The function is to count the amount of disk space occupied by directories (or files).

Du [options] [Names...]

-s only gives the total number of blocks that are also occupied for each Names parameter.

-a recursively displays the total number of data blocks occupied by each file in the descendant directory for each file in the specified directory.

-b column in bytes is also used by disk users (default is K bytes)

-k columns in 1024 bytes are also disk space usage.

-c add a total at last (system default)

-l calculates all file sizes, and for hard-linked files, calculates multiple times.

-x directories skipped on different file systems are not counted. The dd command copies the specified input file to the specified output file, and the format can be converted during the copy process.

Syntax: dd (option) if = input file (or device name). Of = output file (or device name). Ibs = bytes reads bytes 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-in buffer. Obs = bytes writes bytes bytes at a time, that is, the number of bytes written to the buffer. Bs = bytes also sets the number of bytes in the read / write buffer (equal to setting obs and obs). Cbs = bytes converts bytes bytes at once. Count = blocks copies only the input blocks blocks. Conv = ASCII converts EBCDIC codes to ASCII codes. Conv = ebcdic converts ASCII codes to EBCDIC codes. Conv = ibm converts ASCII codes to alternate EBCDIC codes. Conv = blick converts variable bits to fixed characters. Conv = ublock converts fixers to 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 swaps each pair of input bytes. Conv = noerror does not stop processing when there is an error. Conv = sync adjusts the size of each input record to the size of ibs (filled with ibs). The fdformat command formats floppy disks at a low level.

Format [- n] device QUOTE:-n does not check after formatting

4.5 commonly used network commands FTP commands Telnet commands.

Netstat command

-a shows all scoket, including being monitored and.

-c is redisplayed every 1 second until the user interrupts it.

-I displays information about all network interfaces in the same format as "ifconfig-e"

-n the network IP address is used instead of the name to show the network connection.

-r displays the core routing table in the same format as "route-e:."

-t displays the connection of the TCP protocol.

-u shows the connection of the UDP protocol.

-v shows the work in progress. The nslookup command. Finger command, the function is to query the user's information. The ping command. (users and groups can be managed using tools: TurboUserCfg or XturboUserCfg. )

4.6 commands relating to the process. Process and start at [- V] [- Q] [- f file name] [- mldbv] time at-c job [job... .] The process system started by the AT command executes only once. Batch [- V] [- Q queue] [- f file name] [- mv] [time] is executed when the system load is small and resources are idle. The cron command executes commands at regular intervals. The crontab command installs, deletes, or lists tables used to drive cron background processes. Process View

The who command. W command is a more powerful command than who command w

-[husfV] [user]-h does not display the title.

-u ignores 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 entry, that is, the remote hostname entry.

-V displays version information. User displays only the situation of the specified user. The ps command.

-e displays all processes.

-f full format

-h does not display the title.

-l long format.

-w wide output. A displays all processes on the terminal, including those of other users. R displays only the running processes. X shows the process that does not control the terminal. The top command dynamically displays the current progress and other conditions of the system. (5) the startup process of the system.

When the PC starts, 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 (boot module) may change + 1BE h first partition table entry 16 bytes + 1CE h second partition table item 16 bytes + 1DE h third partition table item 16 bytes + 1EE h fourth partition table item 16 bytes + 1FE h executable flag (AA55 h) 2-byte boot module contains code sufficient to load the operating system, or the location of the second step load code. The boot module requires BIOS calls to load data from disk, and these interrupt calls, such as INT 13h, limit the maximum disk column number to 1023. This means that everything that the startup module needs to load, such as the initial memory disk, kernel, startup time information, etc., must be stored within 1024 cylinders. There are only four partition table entries in MBR, and each entry has the following format: address offset content size + 00h partition status: 00 represents a non-boot partition 80h represents boot partition 1 byte + 01h partition start position 1 byte + 02 h partition start position cylinder and sector 1 byte + 04h partition type 1 byte + 05h partition end position 1 byte + 06h partition end position cylinder and sector 1 byte + 08h number of sectors in the main boot area and the first sector of the partition 4 bytes + the number of sectors in the 0Ch partition 4 bytes

5.2 the startup process of Linux

When Linux starts, it handles all command-line arguments passed to it. This can affect the way Linux works.

The command-line arguments include: mem=xxxM: sets the amount of memory that Linux can use. This is only needed if the user's computer system has more memory than 64MB. Because the former motherboard only cached the first 64MB memory, using more than 64MB memory degrades the performance of the entire computer, and all memory runs at a cache-free speed. Single: enable Linux to start in single-user mode, and the default mode is multi-user mode. Root=/dev/xxx: specifies the device on which Linux is to be installed as the root file system. Init=;: specifies the file to use as the initialization process. Initrd=;: specifies the device that is 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 after the kernel initializes itself and finds the hardware device, the Init process starts the process init (/ sbin/init) in the background, and the init process number 1 runs. 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 of system V, as described here. Init is controlled by file / etc/inittab content and functionality, 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 a few scripts. In this way, users can have a shell and perform a limited number of tasks. Multi-user mode: the init process takes the system to the run level specified in the / etc/inittab file. Init enters a specified progress level through the standard Linux method.

3. Implementation level Linux, like other UNIX operating systems, can be at any running level at any time. The different functions provided by these runlevels are mainly due to the different server programs (background daemon) they run. There are six runlevels of Linux.

0: shuts down the computer or terminates the computer, which is the level at which the system stops running.

1: at the startup level of a single user, the system has only one user, that is, root, who logs in on the console.

2: multi-user run level, but no network function. At this runlevel, the network function is not enabled, but the system allows multiple users to log in through the virtual console or serial lines.

3: multi-user mode, with network function. At this run level, all standard network services are started.

4: it has not been realized at present.

5:X11 runlevel, at which the X server software runs, providing a graphical login interface.

6: the system restarts. Query current run level: runlevel

4 A script that runs during startup is responsible for viewing the default run level and entering it when the init process is running. This is achieved through scripts running in the / etc/rc.d/rcX.d directory, where X represents the level at which to run, that is, a run level corresponds to a directory. Files that begin with different letters have different functions. Among them: scripts that start with K are executed when the system leaves a run level to stop a service. When the system changes from one support level to another, all K programs corresponding to the original running level should be carried out first. A script that begins with S is executed when the system enters a run level and is used to start a service. When the system is changed to a certain run level, all S programs corresponding to the new run level will be run.

5 add 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 complete these tasks. The usual step is to copy an existing script so that you can get a common framework format. Modify the script to fulfill your requirements, taking care that the program can handle the startup and shutdown parameters, although the shutdown processing does not need to be done. Copy this tablet to the / etc/rc.d/init.d directory and name it "serv". Set up a run control link in the appropriate directory as follows: CODE: [Copy to clipboard] ln-s.. / init.d/serv/etc/rc.d/rc3.d/s99 serv to test.

6 LILO and other boot modules are required to start Linux. Generally, the boot module used in Linux is that LILO,LILO uses its own main boot area instead of the general main boot area. LILO can be configured by modifying the contents of the / etc/lilo.conf file, and updating the contents of the boot area is done through the lilo command. The next one is also equipped with DOS,TurboLinux3.4.0 and RedHat

At this point, the study of "commonly used Linux shell command arrangement" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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