Linux basic commands

Source: Internet
Author: User
Tags touch command

Linux basic commands

The system used to manage files in the operating system is called the "file system" and the file system manages the files in a grouped manner, specifically through directories (or folders) to manage thousands of files. The Linux file system has only one root directory (/) and the Windows file system can have several root directories (for example, C, D, E). Directories are described by directory path, can be easily divided into two types of description, one is the absolute path, the second is the relative path.

The current working directory of the terminal window can be modified at any time, the user has a current working directory at all times, when the user first logged in using the initial current directory is ~
WhoAmI command to know who the current user is;

The PWD command can know the current working directory, and PWD displays the current working directory with the absolute path of the directory;

Most of the directories and files in the Linux system are given in the form of a path description string.

An absolute path describes a directory path, such as/home/libin, starting at the root of the file system. All absolute paths are paths that begin with the root directory (/)
A relative path begins by describing a directory path from a directory (typically the current directory).
The use of relative paths is more common, typically:
. Represents the current directory itself
.. Represents the parent directory of the current directory.
Temp indicates a subdirectory named temp in the current directory

Note: "Directory" is a directory, is a Windows is called a folder, "directory path" is a "path description string", which describes the path from one directory to another directory, which describes the absolute path and the relative path of two ways.


Example: File structure

Xyz

/        \

ABC def

So

If the current directory is XYZ, the relative path describes the Def directory to write def directly

If the current directory is ABC, the relative path description of the XYZ directory can be written directly.
If the current directory is ABC, the relative path description of the Def directory can be written as follows: /def


Clear command to erase everything on the screen

The LS command can be used to directly display files in the current directory.
The LS STANDARDC command can display files in directories with the path STANDARDC, and the general usage is LS directory
The LS-A Directory command can display all files in directories that are path directory
The Ls-l Directory command can display files in directory directories in detail
As can be seen, the LS command can view the files in the specified directory, using LS < directory path >, if you want to view the contents of the current directory, you can omit the path.
The LS command supports the-A and-l options, and the-a option allows you to display everything in the specified directory, the-l option to list details, and the-A and-l options can be combined into-al

The CD command can adjust any directory to the current directory, using the following method
cd < directory path >

The mkdir command can create a directory using the following method
mkdir < directory path > Note: The directory path endpoint here must be a directory name that does not already exist, otherwise the mkdir command prompts for an error.

The current directory is/home/libin/standardc,ls command view after the discovery of subdirectories day01,ls day01 view found Day01 No subdirectories, then the role of command mkdir day01/note Day01/code?

A: Create a subdirectory for the directory day01 Note and code


The current directory is/home/libin/standardc/day01,ls. When the command is viewed, only the subdirectory day01 is found, then mkdir-p. /day02/note. What is the role of/day02/code?

A: Create a subdirectory day02 for the parent directory of the directory Day01 STANDARDC and create a subdirectory of day02 note and code

rmdir command can delete directory, it can only delete empty directory, Usage:rmdir < directory path >
Rmdir-p a/b/c is equivalent to continuous execution of commands rmdir a/b/c rmdir A/b rmdir A is also equivalent to executing commands rmdir a/b/c A/b


The RM command can be used to delete a non-empty directory, USAGE:RM-RF < directory path >

Touch < file path > You can create an empty file, such as Touch abc.txt. The touch command has two functions: one is to create an empty file, and the other is to update the modified time of an existing file, of course, the file path given after the touch should describe a file that already exists.


RM command can be used alone to delete an existing file, Usage:rm < file path >
CP command can copy a file, USAGE:CP < file path 1> < file path 2>
The MV command can be used to cut the file, usage:mv < file path 1> < file path 2>
The tar command can be used to package and archive several files or directories. Usage:tar zcvf archive.tar.gz <directory> <directory> <directory> ....
The TAR command was originally created to pack files or directories, in short, the function is to merge several files or directories, and then the tar command added compression, so the tar command is often packaged to archive several files or directories and then compression (such as the GZ compression algorithm), So we tend to see the tar command packed archive created file naming is *.tar.gz
The tar command can also decompress compressed files, USAGE:ZXVF archive.tar.gz

The shell script file can contain multiple operations commands, and executing the script file is equivalent to executing all internal command commands in sequence.


The ln command can be used to create a linked file using the following method:
ln file path 1 file path 2
The file path 1 represents an already existing file, and the file path 2 represents a file that does not yet exist.
The link created by using the LN command is called a hard link. There is also a "soft link" that corresponds to a hard link, and a link made by the command ln-s file path 1 file path 2 is called a soft link.
(PS: Each file is composed of two parts: one is the file content, the second is the file name, file name and file content in the middle there is a connection, the file content is the existence of the file name and valid requirements, that is, can be hastily said "file" = "file name, file content." General operating system in order to improve the efficiency of disk operation, the deletion of file operations is only delete the file name, the file name and file content is canceled, the file content will not be immediately cleaned up.
Then you can experiment,
The ln hard link only makes the file name, creating a new file name that connects it to the file contents of the original file.
ln Soft link made a file name, but also made a new file content, the new file contents of the original file name is recorded in the connection, so the soft link depends on whether the original file name is valid.
As you can see, the "Shortcut" authoring operation available in the Windows operating system is essentially the production of ln soft links.
The CP command creates a new file (including both the file name and the file content), and the CP command executes the file contents and filename simultaneously;
)

PS command, the PS command is used alone in the terminal, you can view all the programs running at the current terminal, each program will have a process ID, display the results will show the command of the PID TTY and command

See common options for process command PS:

-a lists all processes.

-W Displays more information when the process is listed as widened.

The-au displays more detailed information.

-aux shows more detailed information about all processes, including the processes of other users.

Attached: ps-aux or ps-au command execution results each column means:



The KILL command terminates the operation of a program, which is used to indicate the process ID of the program.

Kill can add the option-s to send a signal to the operating system. For example, kill-9 can send a signal codenamed 9 to the operating system to force the finalization of the specified process.


Kill-l can list the signals of the Linux system. The signals, called 1~31, that are supported by traditional UNIX, are known as unreliable signals (not real-time), and are later augmented by 32~63, known as reliable signals (real-time signals).

Cat, cat commands can be used to display the contents of the entire file, Usage:cat <directory>
Head, the head command can display several lines from the file header, with a default of 10 rows. Usage:head-n <directory>
The Tail,tail command can display a file up to several lines from the tail, with a default of 10 rows. Usage:tail-n <directory>
More, the more command can be used to display the entire contents of the file, but only one screen at a time, tapping the spacebar to display the next screen.

The Find, find command, for example: "Find Standardc-name note.txt" looks for a file named "Note.txt" under the directory described in directory path "STANDARDC".

The Find command is based on a file's external property lookup, such as file size, file name, and so on. In this way, she is not able to find the file content. Usage:find < start looking for directory > Find options (-name option means file name-perm option means file other properties)

(The grep command is available in P.S. Linux, which can be used to find content inside a file.) To mention is windows,windows in the Find command can be based on the internal content of the file lookup Oh, such as find/i diary.txt "I love You" can be implemented in the Diary.txt file to find I Love you line)

The command Options-name command Find are most commonly used, and other more flexible command options are available, as described in the Find command options:

-name finds files by file name.

-perm finds files according to file permission properties.

-depth first locates in the currently specified directory and then finds its subdirectories.

-prune Use this option to not find in the currently specified directory. When the Find command has both-prune and-depth two options, the-prune option is automatically ignored by the Find command.

The-mtime-n +n implementation is looked up according to the file change time. -n means that the file change time is less than n days, and +n indicates that the file changed time before n days

-user Search files According to the file owner.

-group Find files According to the file group.

-nouser finds a file without a valid owner, that is, the file owner does not exist in the/etc/passwd.

-nogroup finds files with no valid genus, that is, the group of files does not exist in the/etc/groups.

-newer file1!file2 Find newer than file file1 but older files than file file2.

-type is found by file type.

B is a block device.

C is a character device.

P is a pipeline file.

D is the catalog file.

L is a symbolic link (symbol) file, also a "soft link"

F is an ordinary file.

-size N: [c] Find files with a file length of n blocks. Plus C means that the file length is measured in bytes.


grep, grep command. grep (Global search Regular expression (RE) and print out of the line, full search of regular expressions and print lines) is a powerful search tool based on file content, She can search for text through regular expressions and print the line.

grep command options:

-? Indicates that the row in which the print is printed also needs to print the row up and down the row, for example grep-5 version Mysql-5.0.45/makefile

-C,--count means that only the number of matching rows is printed and the matching content is not printed.

-N,--line-number indicates that the line number of the matching row needs to be printed.

-V,--revert-match, prints only rows that do not match.

grep Command Example: "grep versions Mysql-5.0.45/makefile" is found in the file path "Mysql-5.0.45/makefile" describes the contents of the file containing the string "versions" The line. grep command is a search for the contents of a file. Usage:grep the string file path to find




In the command line, you can use wildcards to describe the rules of a path to simplify the writing of commands, and we do not pursue strictly to say:
? Represents an arbitrary letter or number
* represents any length of string, that is, any number of arbitrary letters or numbers
[] denotes a range of letters or numbers, such as [2-4] representing 2, 3, 4 one of the characters.
As you can see,? * and [] are actually a collection, that is, a set of any character, * is a set of any number of characters, [2-4] is a set of elements 2, 3, 4.

Input and output redirection. The Linux system has a default standard input device (stdin) and a default standard output device (STDOUT). We can change the input/output device with input/output redirection. which
< can change input device
> or >> can change the output device
Pipeline. Using Piping ' | ' Multiple commands can be connected, piping ' | ' The output of the preceding command is used as input to the command following the pipeline, for example: Ls-l | grep day01

Multiple commands can be executed at one time on the command line, and the command must be written with '; ' , the command executes after hitting the ENTER key. Example: Pwd;ls

At the command line, you can write a command in multiple consecutive lines by using ' \ ', and when the command is written, the command is executed after hitting the ENTER key.


The basic shell statements are known above, and it is important to note that:

The operating system can divide two parts of "kernel" and "shell". Kernel is commonly known as the kernel, complete the management of computer resources, mainly including CPU management, memory management, file management and other I/O equipment resource management. Shell is commonly known as the shell, she is a programming language, she can interactively explain the execution of commands. As a programming language, she also has her own language character set, has its own control flow statement to control the execution sequence of each operation (control flow structure includes 1, Sequence structure 2, branch structure 3, loop structure). Of course she also allows to define variables.

The Echo $SHELL in the terminal allows you to see the type of shell the current user is using. The shell is divided into several, introduction:

<1>bourne Shell

BSH (Bourne Shell) is the first and most well-known Unix shell written by Bourne (Bourne) at/T Unix, referred to as b-sh (read as B-shell or Bourne shell). If you are using the Bourne Shell, the command prompt is often on the terminal (Terminal). The next version of the Bourne shell is the Bourne shell again, called bash

<2>c Shell

CSH (C Shell) is VI author Jon at the University of California, Berkeley, created for BSD Unix. She is more like C than the Bourne Shell. Note that the syntactically C shell is not compatible with the Bourne shell. If you are using C Shell, then at the terminal (Terminal) The command prompt is often%. The C shell also has an enhanced version called TCSH (TC Shell)


Note: The General UNIX System Terminal (Terminal) root user command prompt is always #.


Next, a god-like tool VI will be coming out, come to you again and again through the Vimtutor Practice VI use. Basically through the vi editing code (measured by the speed of the code) speed can be in 15 minutes/hundred lines can be said skilled use of VI.


VI still have this operation, you know?

(1) The English character of the cursor, and a wave can change the case of the English characters.
(2) Tapping on a capital J you can merge the next line to the end of the current line and become the same row.
(3)
1,2co3 copy 1, 2 lines to the third row.
1,2M3 moves 1, 2 lines after the third row.
1,2d Delete 1–2 rows.
1,2Y copy 1, 2 lines.

Linux basic commands

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.