21 Common Linux commands and use cases

Source: Internet
Author: User
Tags chmod control characters diff compressed file types egrep

Login Installation Class

Command one: Login

1. Role

Login's role is to log on to the system, and its use rights are for all users.

2. Format

Login [name][-p][-h host name]

3. Main parameters

-P: Notifies login to maintain the current environment parameters.

-H: Used to transfer user names between remote logins.

If you choose to log in to Linux in command-line mode, the first Linux command you see is login:.

The general interface is this:

Manddrake Linux Release 9.1 (Bamboo) for i586

Kennel 2.4.21-0.13MDK on I686/tty1

localhost login:root

Password

In the above code, the first line is the Linux release number, the second line is the kernel version number and login Virtual Console, we enter the login name on the third line, press "enter" key after password enter the account password, you can log in the system. For security reasons, the characters are not echoed on the screen when the account password is entered, and the cursor does not move.

You will see the following interface (in the case of Superuser) when you log in:

[Email protected] root]#

Last Login:tue, Nov 10:00:55 on VC/1

The above shows the logon week, month, day, time, and the Virtual Console used.

4. Application Tips

Linux is a true multi-user operating system that allows multiple users to log in at the same time, allowing one user to log in multiple times. This is because Linux, like many versions of UNIX, provides access to the Virtual console, allowing users to log in multiple times at the same time from the console (the system's console is a monitor and keyboard that is directly connected to the system). Each virtual Console can be viewed as a stand-alone workstation that can be switched between workstations. Virtual Console switching can be achieved by pressing the ALT key and a function key, typically using F1-F6.

For example, after a user logs in, clicking the "Alt+f2" key will allow the user to see the "login:" Prompt that appears above, stating that the user sees the second Virtual Console. Then simply press "ALT + F1" key to go back to the first Virtual Console. A newly installed Linux system allows users to use "ALT+F1" to "Alt+f6" keys to access the first six virtual consoles. The most useful thing about virtual consoles is that when a program fails to cause a system deadlock, you can switch to another virtual Console to work and close the program.

Command two: Shutdown

The role of the shutdown command is to shut down the computer, and its use rights are super users.

Shutdown [-H][-I][-K][-M][-T]

3. Important Parameters

-T: Tell the INIT program how long it will shut down before changing to another runlevel.

-K: Not really shut down, just send a warning signal to each login.

-H: Power off after shutting down the machine.

-c:cancel Current process cancels the currently executing shutdown program. So this option certainly does not have a time parameter, but you can enter a message to interpret, and this information will be sent to each user.

-F: Forces fsck to restart the computer.

-time: Set the time before shutting down the machine.

-M: Changes the system to single-user mode.

-I: Displays system information when shutting down.

4. Command description

The shutdown command can safely shut down the system. It is dangerous for some users to shut down the Linux system in a way that directly shuts off the power supply. Because Linux, unlike Windows, runs many processes in the background, forcing a shutdown can cause data loss to the process, leave the system in an unstable state, or even damage the hardware device (hard disk) in some systems. Using the shutdown command before the system shuts down, the system administrator notifies all logged-on users that the system is about to close, and the login command is frozen, that is, the new user can no longer log on.

5. For example

Shutdown-h 3:40

Description 3:40 start shutdown.

Command three: Halt

The function of the halt command is to shut down the system, and its usage rights are super users.

Halt [-N] [-W] [-d] [-f] [-i] [-p]

3. Main parameter description

-N: Prevents the sync system from being called, it is used after patching the root partition with fsck to prevent the kernel from overwriting the patched super block with the old version of the Super block.

-W: not a real restart or shutdown, just write Wtmp (/var/log/wtmp) record.

-F: No call to shutdown, but forced shutdown or restart.

-I: Turn off all network interfaces before shutting down (or restarting).

-F: Force shutdown, do not call shutdown this command.

-P: The way to turn off the power when the computer is turned off.

-D: Shuts down the system but does not leave a record.

Halt is called Shutdown-h. The halt executes, kills the application process, executes the system call of sync (which forces data stored in buffer to the hard disk), and stops the kernel after the file system writes are complete. If the operating level of the system is 0 or 6, the system is shut down, otherwise the shutdown instruction (plus the-h parameter) is replaced.

Command four: Reboot

The role of the reboot command is to restart the computer, and its use rights are system administrators.

Reboot [-n] [-W] [-d] [-f] [-I.]

-N: Do not write the memory data back to the hard drive before rebooting.

-W: does not really reboot, just write the record in the/var/log/wtmp file.

-D: Do not write the record into the/var/log/wtmp file (-n This parameter contains-D).

-I: Stop all network-related devices before rebooting.

Command five: Install

The install command works by installing or upgrading software or backing up data, and its use rights are for all users.

(1) Install [options] ... Source destination

(2) Install [options] ... Source... Directory

(3) install-d [options] ... Directory...

In the first two formats, the < source > is copied to < destination > or multiple < source > files are copied to the existing < directory, and both the permission mode and the owner/owning group are set. In the third format, all the specified directories and their home directories are created. The parameters that must be used for the long option are also required when using the short option.

--backup[=control]: A backup of each existing destination file.

-B: Similar to--backup, but does not accept any parameters.

-C: (This option is not processed).

-d,--directory: All parameters are processed as directories, and all home directories for the specified directory are created.

-D: Create all home directories < destinations >, and then copy < source > to < destinations >; in the first use format.

-g,--group= Group: Sets the owning group itself, not the group to which the process currently belongs.

-m,--mode= mode: Set your own permission mode (like chmod) instead of rwxr-xr-x.

-o,--owner= owner: Self-setting owner (for Superuser only).

-p,--preserve-timestamps: The time attribute of the corresponding destination file with the access/modification time of the < source > file.

-s,--strip: Remove the symbol table with the strip command only for the first and second use formats.

-s,--suffix= suffix: Specify the < suffix > for the backup file yourself.

-v,--verbose: Prints the name when each file/directory is processed.

--help: Displays this help message and leaves.

--version: Displays the version information and leaves.

Command six: Mount

The purpose of the Mount command is to load the file system with permissions that are allowed by superuser or/etc/fstab.

mount-a [-FV] [-t vfstype] [-n] [-RW] [-f] Device dir

-H: Displays auxiliary information.

-V: Displays information, usually and-F for debugging.

-A: Hang all file systems defined in/etc/fstab.

-F: This command is usually used with-a, which generates a stroke for each mount action. The speed of loading can be accelerated when the system needs to hang a large number of NFS file systems.

-F: Usually used for debugging. It causes mount to not perform the actual hanging action, but instead simulates the entire hanging process, which is typically used with-V.

-T Vfstype: Displays the type of file system being loaded.

-N: In general, Mount hangs on the/etc/mtab to write a piece of information, in the system does not have a writable file system, you can use this option to cancel this action.

On Linux and UNIX systems, all files are accessed as part of a large tree (or root). To access files on a CD-ROM, you need to attach a CD-ROM device to a hanging decoration in the file tree. If the distribution has an auto-mount package installed, this step can be done automatically.

In Linux, if you want to use a hard disk, CD-ROM and other storage devices, you have to load it, when the storage device hangs, it can be used as a directory to access. Hang up a device using the Mount command.

When using the Mount command, you need to know at least the following three kinds of information: The file system type to load the object, the name of the device to load the object, and the directory to load the device into.

(1) Linux recognizable file system

The FAT 32 file system commonly used in Windows 95/98: VFAT;

The file system of Win nt/2000: ntfs;

OS/2 file system: HPFS;

Linux file system: ext2, ext3;

File system for CD-ROM: iso9660.

Although VFAT refers to the FAT 32 system, it is also compatible with the Fat 16 file system type.

(2) Determine the name of the device

In Linux, the device name usually exists in/dev. The names of these devices are all rules, and you can use the "reasoning" method to find out the name of the device. For example,/dev/hda1 this IDE device, HD is hard disk (HDD), SD is SCSI DEVICE,FD is floppy device (or floppy disk?). A represents the first device, usually the IDE interface can connect to 4 IDE devices (such as 4 hard drives). So the way to identify the IDE hard disk is HDA, HDB, HDC, HDD. The "1" in hda1 represents the first hard disk partition (partition) of HDA, Hda2 represents the second primary partition of HDA, the first logical partition starts with HDA5, and so on. In addition, you can directly check the/var/log/messages file, in this file can find the computer after the system has been identified after the device code.

(3) Find Hang Point

Before deciding to hook up your device, check to see if your computer has an empty directory of/mnt, which is a directory dedicated to mount point. It is suggested to build several/mnt/cdrom,/mnt/floppy,/mnt/mo and other directories in/mnt, as the special mount point of the directory. For example, if you want to mount the following 5 devices, their execution instructions may be as follows (assuming all Linux ext2 systems, if Windows XX Please change ext2 to VFAT):

Floppy ===>mount-t Ext2/dev/fd0/mnt/floppy

CDROM ===>mount-t Iso9660/dev/hdc/mnt/cdrom

SCSI CDROM ===>mount-t Iso9660/dev/sdb/mnt/scdrom

SCSI CDR ===>mount-t iso9660/dev/sdc/mnt/scdr

However, most newer Linux distributions are available (including Red Flag Linux, Medium Soft Linux, Mandrake Linux, etc.)

can automatically mount file systems, except Red Hat Linux.

Command seven: Umount

The role of the Umount command is to unload a file system that uses permissions that are allowed by superuser or/etc/fstab.

umount-a [-FFNRSVW] [-t vfstype] [-n] [-RW] [-f] Device dir

3. Instructions for use

The Umount command is the inverse of the Mount command, and its parameters and usage are the same as the Mount command. After the Linux Mount CD-ROM, the CD-ROM is locked so that it cannot be ejected with the eject button on the CD-ROM panel.

However, when the disc is no longer needed, if you have/cdrom as a symbolic link, use Umount/cdrom to uninstall it. The command succeeds only if no user is using the disc. This command includes a terminal window with the current working directory as the directory on the disc.

Command eight: Chsh

The purpose of the CHSH command is to change the user shell settings, which are used by all users.

Chsh [-S] [-list] [--help] [-v] [username]

-L: Displays all shell types of the system.

-V: Displays the shell version number.

There are a variety of shells under Linux, usually the default is bash, if you want to change the shell type you can use the CHSH command. Enter the account password first, then enter the new shell type, and if the operation is correct the system will show "Shell change". The interface is generally as follows:

Changing fihanging shell for Cao

Password:

New Shell [/bin/bash]:/bin/tcsh

In the above code, [] is the shell currently in use. Ordinary users can only modify their own shell, the super-user may modify the entire user's shell. To query which shells the system provides, you can use the Chsh-l command.

Command nine: Exit

The function of the Exit command is to exit the system, and its use rights are all users.

Exit

3. Parameters

The exit command has no parameters and exits the system after running to enter the login screen.

Command 10: Last

The last command is used to show the recent user or terminal logon situation, and its use rights are all users. By the Last Life

To view the log of the program, the administrator can tell who has or attempted to connect to the system.

1ast[-n][-f file][-t TTY] [-h node][-i-ip][-1][-y][1d]

-N: Specifies the number of bars for the output record.

-F File: Specifies the log file used as the query for the file.

-T TTY: Displays only the specified Virtual Console login status.

-H node: Displays only the logon status on the specified node.

-I IP: Displays only the cases where the specified IP is logged on.

-1: Use IP to display the remote address.

-y: Displays the year, month, and day of the record.

-id: Knows the user name of the query.

-X: Shows the history of system shutdown, user login, and exit.

File Management Classes

Linux System information is stored in a file, and the file is similar to ordinary official documents. Each file has its own name, content, storage address, and other administrative information, such as the user of the file, the size of the file, and so on. A file can be a letter, an address book, or a source statement for a program, a program's data, or even an executable program or other non-body content. Linux file system has a good structure, the system provides a lot of file processing commands.

Command 11: File

File determines the type of files by probing the contents of the file, and the permission is used by all users.

file [options] File name

3.[options] Main parameters

-V: Displays the version information after the standard output and exits.

-Z: Detects compressed file types.

-L: Allow the connection to be met.

-F Name: Reads the list of file names to parse from the file NameFile.

4. Brief description

You can use the file command to know whether a file is a binary (elf-formatted) executable, a shell script file, or any other format. File types that can be identified include directories, shell scripts, English text, binary executables, C-language source files, text files, and DOS executable files.

5. Application examples

If we see a file with no suffix grap, you can use the following command:

$ file Grap

Grap:english text

At this point the system shows that this is an English text file. Note that the file command is not able to detect multimedia file types including graphics, audio, video, and so on.

Command 12: mkdir

The purpose of the mkdir command is to create a subdirectory named DirName, similar to the MD command under MS DOS, which is used by all users.

mkdir [Options] Directory name

-M,--mode= mode: Set permissions < mode, similar to chmod.

-P,--parents: Creates a top-level directory when needed, and is not considered an error if the directory already exists.

-V,--verbose: Displays information each time a new directory is created.

--version: Show version information and leave.

4. Application examples

You can set permissions for the directory at the time of catalog creation, and the parameters used are "-M". Assuming that the directory name you want to create is "tsk", so that all users have rwx (that is, read, write, execute), you can use the following command:

$ mkdir-m 777 Tsk

Command 13: grep

The grep command allows you to specify a file to search for specific content and to output the standard rows containing the content. The grep full name is global Regular expression Print, which represents the globally regular expression version, and its use rights are for all users.

grep [Options]

[Options] Main parameters:

-C: Outputs only the count of matching rows.

-I: Case insensitive (only for single-character).

-H: The file name is not displayed when querying multiple files.

-L: Only file names that contain matching characters are output when querying multiple files.

-N: Displays matching lines and line numbers.

-S: does not display error messages that do not exist or have no matching text.

-V: Displays all lines that do not contain matching text.

Pattern Regular Expression Main parameters:

\: Ignores the original meaning of special characters in regular expressions.

^: matches the start line of the regular expression.

$: Matches the end line of the regular expression.

\<: Starts from the line that matches the regular expression.

\>: End of line to match regular expression.

[]: A single character, such as [a], a meets the requirements.

[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.

. : all the individual characters.

*: There are characters, the length can be 0.

Regular expressions are a very important concept in the Linux/unix system. A regular expression (also known as "regex" or "regexp") is a pattern (pattern) that can describe a class of strings. If a string can be described with a regular expression, we say that the character matches the regular expression (match). This and the DOS user can use the wildcard character "*" to represent any character similar. On Linux systems, regular expressions are often used to find patterns in text, and to perform "search-and-replace" operations and other functions on text.

Querying the DNS service is one of the daily tasks, which means maintaining a large number of IP addresses that cover different networks. Sometimes there are more than 2000 IP addresses. If you want to see the NNN.NNN network address, but forget the rest of the second part, only know that there are two periods, such as nnn nn ... To extract all of the nnn.nnn IP addresses, use [0-9]\{3 \}\. [0-0\{3\}\. The meaning is that any number appears 3 times, followed by a period, followed by any number 3 times, followed by a period.

$grep ' [0-9]\{3 \}\. [0-0\{3\}\ ' Ipfile

To add, the grep family also includes Fgrep and Egrep. Fgrep is fix grep, which allows to find strings instead of a pattern; Egrep is an extended grep that supports both basic and extended regular expressions, but does not support the application of \q mode scope and some of the more canonical patterns corresponding to it.

Command 14: DD

The DD command is used to copy the file and convert and format the data according to the parameters.

DD [Options]

3.[opitions] Main parameters

bs= byte: Force ibs=< byte > and obs=< byte >.

cbs= bytes: Each conversion of the specified < bytes >.

conv= Keyword: Converts a file based on a comma-delimited representation of a keyword.

count= number of blocks: only the input data of the specified < block number > is copied.

ibs= Bytes: Reads the specified < bytes > each time.

if= file: Read < file > content, not standard input data.

obs= Bytes: Writes the specified < byte > each time.

of= file: Writes data to the < file, but not the standard output display.

Number of seek= blocks: first skip the output data for the specified < block number > in OBS units.

Number of skip= blocks: first skip the input data for the specified < block number > in IBS.

The DD command is often used to make Linux boot disks. Find a bootable kernel, point its root device to the correct root partition, and then use the DD command to write it to the floppy disk:

$ Rdev Vmlinuz/dev/hda

$DD If=vmlinuz of=/dev/fd0

The code above shows that using the Rdev command to point the root device in the bootable kernel vmlinuz to/dev/hda, replace "HDA" with its own root partition, and then write the kernel to a floppy disk using the DD command.

Command 15: Find

The function of the Find command is to search the directory for a file, and its use rights are for all users.

Find [Path][options][expression]

path Specifies the directory path from which the system starts to look down the file down the directory tree. It is a list of paths that are separated from each other by spaces, and if you do not write path, the current directory is assumed.

[Options] Parameters:

-depth: Use the Depth-level lookup process to prioritize file content in a specific level of the specified directory.

-maxdepth levels: Indicates that at most find the first level subdirectory of the start directory. Level is a non-negative number, and if level is 0, it is only found in the current directory.

-mindepth levels: Indicates that at least the level subdirectory of the start directory is found.

-mount: Not found in directories and files in other file systems (such as MSDOS, VFAT, etc.).

-version: Print version.

[Expression] is a matching expression and is an expression accepted by the Find command, and all operations of the Find command are for an expression. It has a lot of parameters, and here are just a few common parameters.

-name: Supports wildcard characters * and?.

-atime N: Searches for files that have been read in the last n days.

-ctime N: Searches for files that have been modified in the last n days.

-group Grpoupname: Search for all files with Grpoupname group.

-user User name: Searches for all files that belong to the primary user name (ID or name).

-size N: The file size of the search file is n blocks.

-print: Output search results, and print.

The Find command finds several ways to locate a file:

(1) Search by file name

For example, if we want to find a file with a filename of lilo.conf, you can use the following command:

Find/-name lilo.conf

The "/" after the Find command means that the entire hard disk is searched.

(2) Quickly find files

Finding files based on file names can have a real problem, which is to take a long time, especially when large Linux file systems and high-capacity hard disk files are placed in deep sub-directories. If we know that this file is stored in a directory, you can save a lot of time by looking down in that directory. such as the smb.conf file, from its file suffix ". conf" can be determined that this is a configuration file, then it should be in the/etc directory, at this time can use the following command:

Find/etc-name smb.conf

This way, you can shorten the time by using the Quick Find file method.

(3) Search method based on partial file name

Sometimes we know that only one file contains the 4 words of ABVD, then to find all the files in the system that contain these 4 characters, you can enter the following command:

Find/-name ' *abvd* '

After entering this command, the Linux system will look in the/directory for all files containing the ABVD 4 characters (where * is a wildcard character), such as Abvdrmyz and other eligible files can be displayed.

(4) Find a file using a hybrid lookup method

The find command can use a hybrid lookup method, for example, if we want to find a file that is larger than 500000 bytes in the/etc directory and modified within 24 hours, you can use-and (and) to link the two lookup parameters together into a mixed lookup.

Find/etc-size +500000c-and-mtime +1

Command 16: MV

The MV command is used to rename a file or directory, or to move a file from one directory to another, and its use rights are for all users. This command is like a combination of Ren and move in a DOS command.

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

-I: Interactive mode operation. If the MV operation will result in overwriting an existing target file, then the system asks whether to overwrite it, asking the user to answer "y" or "n", which avoids overwriting the file by mistake.

-F: Disables interactive operation. MV operation to overwrite an existing target file without giving any indication, after specifying this parameter the I parameter will no longer work.

(1) Move all files in the/USR/CBU to the current directory (".") Representation) in:

$ mv/usr/cbu/*.

(2) Rename the file Cjh.txt to Wjz.txt:

$ mv Cjh.txt Wjz.txt

Command 17: LS

The LS command is used to display directory contents, similar to the dir command under DOS, which is used by all users.

LS [options][filename]

3.options Main parameters

-A,--all: Do not hide any items that begin with the "." Character.

-A,--almost-all: list except ". "and". "Any item other than the".

--author: The author of each document is printed.

-B,--escape: The non-printable character is represented by an octal overflow sequence.

--block-size= Size: The block is in bytes that specify < size >.

-B,--ignore-backups: Do not list any items that end with the ~ character.

-F: Do not sort,-au parameter is valid,-LST parameter is invalid.

-F,--classify: plus an indicator of the file type (*/[email protected]| one).

-g:like-l, but does not list owner.

-G,--no-group:inhibit display of group information.

-I,--inode: Lists the inode number for each file.

-I,--ignore= style: Do not print any items that conform to the shell Universal Character < style >.

-K: that is--block-size=1k.

-L: Lists information in a longer format.

-L,--dereference: When displaying the file information of a symbolic link, displays the object indicated by the symbolic link, not the information of the symbolic link itself.

-M: All items are separated by commas and fill the entire row width.

-N,--numeric-uid-gid: Similar to-L, but lists the UID and GID number.

-N,--literal: Lists the names of the unprocessed items, such as control characters that are not handled specifically.

-P,--file-type: plus an indicator of the file type (/[email protected]| one).

-Q,--quote-name: Enclose the project name in double quotation marks.

-R,--reverse: in reverse order.

-R,--recursive: Lists all subdirectory tiers at the same time.

-S,--size: The block size is the order.

4. Application examples

The LS command is the most frequently used command in a Linux system, and its parameters are the largest of the Linux commands. There are several different colors when using the LS command, where Blue is the directory, green means executable, red is compressed, light blue is a linked file, bold black indicates a symbolic link, and gray is another format file. LS is most commonly used in ls-l.

The file type begins with a 10-character string. Where the first character represents a file type, it can be one of the following types:-(normal file), D (directory), L (symbolic Link), B (block device file), C (character device file). The following 9 characters represent the access rights of the file, divided into 3 groups and 3 bits per group. The first group represents the permissions of the file owner, the second group represents the permissions of the same group of users, and the third group represents the permissions of the other users. The three characters of each group represent the read (R), write (w), and Execute permissions (x) of the file respectively. For the directory, the access permission is indicated. s indicates that the UID or GID of the file is assigned to the UID (user ID) or GID (group ID) of the executing process when the file is executed. T indicates that the flag bit is set (left in memory, not swapped out). If the file is a directory, the files in that directory can only be deleted by the superuser, the directory owner, or the file owner. If it is an executable file, the pointer to its body segment remains in memory after the file executes. This will enable the system to load the file more quickly when it is executed again. The file size, build time, file, or command name are then displayed.

Command 18: Diff

The diff command is used for comparisons between two files, and indicates the difference between the two, and it uses permissions for all users.

diff [Options] source file destination file

-A: treats all files as text files.

-B: Ignores the difference caused by whitespace.

-B: Ignores the difference caused by empty rows.

-C: Use the schema output format.

-H: Use heuristics to accelerate searches of large files.

-I: Ignores case changes.

-N--rcs: Output RCS format.

Command 19: CMP

The CMP ("compare" abbreviation) command is used to briefly indicate whether there are differences between the two files, and its use rights are for all users.

Cmp[options] File name

-L: Outputs bytes in decimal mode and facilitates the output of different two files in eight binary.

Command 20: Cat

The Cat ("concatenate" abbreviation) command is used to connect and display information about one or more of the files specified, and its use rights are for all users.

Cat [Options] file 1 file 2 ...

-N: The number of rows for all outputs, starting with the first line.

-B: Similar to-n, except that blank lines are not numbered.

-S: A blank line that is substituted for a row when there are more than two consecutive lines of blank rows.

(1) One of the simplest uses of the cat command is to display the contents of a text file. For example, we want to take a look at the contents of the Readme file at the command line and use the command:

$ cat README

(2) Sometimes several files need to be processed into a single file, and the results of such processing will be saved to a separate output file. The cat command accepts one or more files on its input and prints them as a separate file to its output. For example, after adding a line number (blank line) to the file contents of the Readme and install, append the contents to a new text file File1:

$ cat README INSTALL File1

(3) Another important feature of cat is the ability to number rows, as shown in Figure 2. This functionality is convenient for programming documentation, as well as legal and scientific documentation, and printing on the left line number makes it easy to reference a portion of a document, which is important in programming, scientific research, business reporting, and even legislative work.

The line numbering function has a-B (can only be numbered for non-blank lines) and-n (can be numbered for all rows) two parameters:

$ cat-b/etc/named.conf

Command 21: LN

The ln command is used to create a link between files, and its use rights are for all users.

ln [options] source file [link name]

-F: The source file is deleted when the link is closed.

-D: Allows system administrators to hard-link their own directories.

-S: Soft link (symbolic link).

-B: Files that will be overwritten or deleted at the time of the link are backed up.

There are two types of links, one called hard links, and the other called Symbolic links (symbolic link).

By default, the LN command produces a hard link.

A hard join refers to a connection made through an index node. In a Linux file system, a file saved in a disk partition, regardless of the type, assigns a number to it, called the index node number (Inode index). In Linux, multiple file names point to the same index node that exists. In general, this connection is a hard connection. The purpose of a hard connection is to allow a file to have multiple valid pathname, so that users can establish a hard connection to important files to prevent "accidental deletion" of the function. The reason for this is as above, because there is more than one connection to the index node that should be the directory. Deleting only one connection does not affect the index node itself and other connections, and the connection to the file's data block and directory will be released only if the last connection is deleted. In other words, the file is actually deleted.

In contrast to a hard connection, there is another connection in the Lnux system, called a symbolic connection (SYMBILC link), also known as a soft connection. A soft link file is a bit like a shortcut to Windows. It is actually a kind of special file. In a symbolic connection, a file is actually a text file that contains location information for another file.

Little Practice

1. Run multiple commands at once

You can execute multiple commands on one command line, separating the commands with semicolons, for example:

#last-x;halt

The above code indicates that the computer is turned off after displaying the system shutdown, user logon, and exit history.

2. Accessing the Windows system with Mount Mount file system

Many Linux distributions can now automatically load VFAT partitions to access Windows systems, and Red Hat versions do not automatically load VFAT partitions, so manual action is required.

Mount can attach the Windows partition to an empty folder in Linux as a "file" of Linux, linking the Windows partition to the/MNT directory. As a result, accessing this folder is equivalent to accessing the partition. First, create the Winc folder under/mnt and enter the following command at the command prompt:

#mount-T Vfat/dev/hda1/mnt/winc

This means that the C partition of Windows is attached to the Liunx/mnt/winc directory. In this case, you can see the contents of the C drive in Windows in the/mnt/winc directory. Use a similar method to access the D, E drives of the Windows system. The Linux system displays the Windows partition in general order such as: Hda1 for C, Hda5 for D, Hda6 for E drive ... And so on

The above method can view the Windows system has a big problem, that is, all the Chinese file name or folder name in Windows is all displayed as a question mark "? , while English can be displayed normally. We can make it appear in Chinese by adding some parameters. Also take the above action as an example, enter the command at this time:

#mount-T Vfat-o iocharset=cp936/dev/hda1/mnt/winc

Now it can display Chinese as normal.

3. Using the file system on Mount Plus on the flash drive

Using a flash drive under Linux is very simple. Linux has a good support for USB devices, and when the flash drive is inserted, the flash drive is recognized as a SCSI disk, usually by entering the following command:

# MOUNT/DEV/SDA1/USB

will be able to attach the file system on the flash drive.

4. Quick access to key directories with symbolic links

Symbolic links are a very useful feature. Suppose there are directories or files that need to be used frequently, but because of the file and directory structure of Linux, this file or directory is in a very deep subdirectory. For example, the Apache Web server document is in the/usr/local/httpd/htdocs of the system and does not want to enter such a long path every time from the home directory (in fact, this path is very difficult to remember).

To solve this problem, you can create a symbolic link in the home directory so that you only have to enter the link when you need to enter the directory.

For easy access to the directory where the Web server (/usr/local/httpd/htdocs) document is located, the following commands can be used in the home directory:

$ ln-s/usr/local/httpd/htdocs GG

This way, every time you enter the GG directory, you can access the Web server's documents, and if you no longer have access to the Web server's documents, delete GG, and the real Web server's documentation is not deleted.

5. Use the DD command to import root.ram content in INIT.RD format into memory

DD if=/dev/fd0 OF=FLOPPY.FD

DD If=root.ram OF=/DEV/RAM0 #

6.grep Command System call

grep is one of the most widely used commands in Linux/unix, which can be called inside many Linux systems.

(1) If you want to query the directory in the directory list, the method is as follows:

$ ls-l | grep ' ∧d '

(2) If you are querying a directory for all files that do not contain a directory, the method is as follows:

$ ls-l | grep ' ∧[∧d] '

(3) Use the Find command to invoke grep, such as "Chinput" in all c source code, by doing the following:

$find/zhxwin-name *.c-exec grep-q-s Chinput {} \;-print

21 Common Linux commands and use cases

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.