I believe that many people who have no system knowledge of Linux will be like me, when following the tutorial to do some environment configuration work, there are some seemingly confusing Linux commands composed of English abbreviations, and they are often confused about the organization structure and operation mode of Linux system. So in order to have more understanding of The Linux system, I went to see the relevant information, found that many people recommend this book on Douban, I also think that as a Linux system is very good for entry, recommend similar friends can read it.

chap01-03

01 introduction

The Linux system stands for ‘freedom’ and can give you a computer without any secrets, you can know everything about it.

Why you should learn the command line:

  1. “The graphical user interface makes simple tasks easier to complete, while the command-line interface makes complex tasks possible.”
  2. Learning the Linux command line is hugely rewarding and rewarding. If you think you’re a master by now. Don’t worry. You don’t know what a master is yet. Unlike some other computer skills, which may become obsolete after a while, command line knowledge is not behind The Times. Anything you learn today will be useful ten years from now. The command line has stood the test of time.

Chap02 What is a shell

When the shell is started, [me@linuxbox ~]$appears, usually containing the user name, host name, working directory, and $sign. If it is not $but #, the current user has super administrator rights

Copy and paste tips:

If you highlight text by holding down the left mouse button and dragging the mouse along the text (or double-clicking on a word), the highlighted text is copied into a buffer managed by X. Then press the middle mouse button and the text is pasted into the cursor position.

The command

Thu Oct 25 13:51:54 EDT 2007

CAL – Outputs the current month calendar

Df — Indicates the remaining disk space

Free: Displays the amount of free memory

Chap03 Jump in the file system

The command

PWD — print Working directory Prints the current directory path

cd — change directory

ls — list direcotry contents

Absolute path relative path

Relative path:.. Represents the parent directory,. Represents the current directory, and. Can be omitted

shortcuts

CD – Switch to the user’s home directory

CD – — Switch to the previous working directory

CD ~user_name — Switches to the user’s home directory. For example, CD ~ Bob switches to Bob’s home directory

Chap04 Explores the operating system

4.1 command:

ls:

Ls -t Output in the order of file modification time. Ls -lt ls -t --reverse Displays all files in reverse order. Hidden file at the beginning; Ls -lh Displays file size in human-readable format. Ls -s sorts files by size. Ls /usr lists files in other directories. Ls ~ /usr lists files in multiple directoriesCopy the code

-rw-r–r– 1 root root 358374 2007-04-03 11:05 Ubuntu sax.ogg -r -r–r– 1 root root 358374 2007-04-03 11:05 symlink

PNG: PNG Image data, 64 x 64, 8-bit/color RGBA, Interlaced

Less — Browse text file content q Exit, /a search a character page scheduler program that allows easy browsing of long text documents in a page by page manner

4.2 File System

The /boot directory contains the Linux kernel, the initial boot loader, and other /bin binaries. Folders named after bin are for binary executables. /bin is for binary programs needed to run the system. /usr/bin The executable program installed on the system /etc is stored in the configuration file /home assigned to the user. Common users can only change the home directory of the root account in their own home directory. The administrator's home directory /sbin s stands for system. It contains binary "system" files, programs for critical system tasks, and is usually reserved for temporary files stored in/TMP for superusersCopy the code

/usr Unix system resource, /usr is probably the largest. It contains all the programs and files that the average user needs

/usr/bin System installed executable program /usr/lib shared by all programs on the library /usr/localThe directory where the user installs the program. Programs compiled from the source code are installed at /usr/localA new system/bin directory, this directory is empty before the installer/usr/share/usr/bin in the program using Shared data, including, ICONS, audio configuration file/usr/share/doc installation package contains some documents, stored classified according to the package of documents. /var stores dynamic files, various databases, spoolers, user emails, and more. Except for the/TMP and /home directories, the above directories are static and the contents do not change. /var/logContains log files, records of various system activities, which are important and should be monitored from time to time. One of the most important files is /var/log/ messages. Sometimes only superusers can view these log files.Copy the code

The complete Linux file system hierarchy standard can be found at:! http://www.pathname.com/fhs/

/etc/cetercetera This is an older way of saying that bits and pieces of any data or files that do not belong in other directories are stored in the /etc directory. Alternatively, “Editable Text Configuration” : Many people also think of the /etc directory as a place to put the Configuration files for our system programs. So often see such a directory introduction

4.3 Symbolic Links

LRWXRWXRWX 1 root root 11 2007-08-11 07:34 LIBc-2.6.so -> libc-2.6.so -> libc-2.6.so When multiple programs reference a file, the maintainer version number in the file name needs to be modified when the file is upgraded. You can use a soft link to delete the original soft link and create a soft link with the same name that references the new version file. The link is called libc.so.6 and actually points to the libc-2.6.so file.

Chap05 Operation file and directory

Common commands

Cp - Copy files and directories options:-aCopy attributes at the same time; -r recursively copies the contents of the directory. -i interactive replication. If the file is to be overwritten, a prompt is displayed. -u more modern replication; -v Display operation details mv - Move/rename files and directories option: -i -u -v mkdir - Create directory rm - Delete files and directories option: -i interactive; -r recurrence;-fMandatory; -V Redundant ** Note: ** RM deletion cannot be restored, so be careful. When using RM to delete a directory with wildcards, an operation to avoid incorrect deletion is to use ls to test the wildcards before running RM. Ln - Create hard links and symbolic links create hard links: 'ln file link' Create soft links: 'ln-s file link`
Copy the code

A hard link – cannot be associated with a file outside of its own file system, i.e. it cannot be associated with a file on another disk partition – cannot be associated with a directory – a hard link itself is no different from a file, a hard link itself is a file. – Each file will have a hard link by default

Soft links – the Windows equivalent of shortcuts; – A symbolic link points to a file; – When something is written to a symbolic link, the associated file is also written; – When deleting a symbolic link, only the link is deleted, not the file itself; – If you delete the file before the symbolic link, the link still exists, but does not point to anything. In this case, the link is called a bad link.

The wildcard

\* - Match any character? - Matches characters belonging to the character set ABC. [a-z][a-z][! ABC] - Matches all characters except a, b, and C. [[:class:]] - Matches the character classCopy the code

Character classes

[[: alnum:]] - match any letters or Numbers [[: alpha:]] - match any letters [[: digit:]] - match any number of [[: lower:]] - match any lowercase letter [[: upper:]] - match as a capital letterCopy the code

Chap06 Use the command

Command documentation help commands

type- Displays the type of the command: executable program, shellbuiltinCommands, shell functions, aliaseswhich- Show the program path location of executable program type commands man - Show the manual of commands: 'man ls'. ` man 5 passwd ` : View chapter 5 of the passwd command manual. Apropos - Search the manual for the given keyword. 'apropos XXX' is equivalent to 'man -k XXX' info - Display the program's INFO entry, similar to man, using the info reader program to display the content. The Info page is in the form of a hyperlink, much like a web page: 'info coreutils' whatis - displays a concise description of the commandhelp- according to the shellbuiltinHelp manual for type commands:help cd, will output 'cd: cd[- L | - P] [dir] ` with vertical lines | said exclusive -- help - some executable support a type of commandhelpOption: mkdir --helpalias- Create command alias:alias foo='xxxxxxx'. With no parametersaliasAll aliases for the system are printedunalias- Delete command alias:unalias foo
Copy the code

README documentation: Many programs have their own documentation files under /usr/share/doc/, most of which are text files that can be viewed using the less program. The. Gz file is a gzip compressed file, and the text file can be viewed using Zless. Zless is a special less version of the gzip package that displays the contents of the gzip compressed text file.

Info reader program command:

? - Display command Help PgUp - Display previous page PgDn - Display next page N-next Displays next node p-prev displays previous node U-up displays the parent node, usually a menu q-quit to exit the readerCopy the code

Hyperlinks are identified by the asterisk at the beginning of them, which can be activated by placing the cursor over them and pressing enter

Create your own commands using Alias

Type foo= => bash: type: foo: not found alias foo=’ CD /usr; ls; cd -‘ foo

This will execute CD /usr; ls; CD – The three commands type foo ==> foo is aliased to ‘CD /usr; ls ; cd -‘

Aliases defined on the command line disappear when the shell session ends

Chap07 redirect

The I/O redirection

“I/O redirection “can redirect the input and output of a command. The input of a command comes from a file, and the output is stored in a file. It can connect multiple commands to form a powerful command pipe.

Standard input, output, and error

The program produces two kinds of output: 1. The result of the program, that is, the function to be accomplished by the program; 2. 2. The status and error messages we get, which tell us how the program is progressing. Consistent with the Linux theme “Everything is a file,” a program such as LS sends the results of a run to a file called standard output (stdout) and sends error messages to a standard error file (stderr). By default, both standard output and standard error are connected to the screen rather than saved to disk. In addition, many programs get information from a standard input device (STDIN), which is connected to the keyboard by default. Redirection commands can change the location of input and output. Generally from the keyboard input, output to the screen, through the command can be changed to input from the file output, or from the command result of the input source.

The command

Cat Concatenate Files reads one or more files and copies them to standard output. -cat reads the file: 'cat < file1. TXT' changes the input source to file1. TXT, which is the same as' cat file1. TXT '==' to display the contents of file1. TXT. 'cat out*.txt > out. TXT' == "Merges the contents of the TXT file that meets the conditions into the out. TXT file. 'cat > dog. TXT' will write the user's input to the dog. TXT file. add-dShow lines repeated grep prints match: - ` ls/bin/usr/bin | sort | uniq | grep zip ` display file contains'zip'List of files - ` ls/bin | grep -i zip ` ignore case when search matches - ` ls/bin | grep -v zip ` display item does not match the wc word count, the number of rows in a display file, file size: - ` wc file1. TXT ` display file file1. TXT data, the number of words - ` wc ` if with no arguments, it accepts the standard input, the keyboard input - ` ls/usr/bin | wc-lHead prints the first ten lines of the file by default, - 'head -n 5 file1.txt' + -n, Can be set to print a few lines - ` ls/usr/bin | head - n 5 ` also can be used in the pipe line tail ten lines after the default print file, - ` tail - n 5 file1. TXT ` -n parameter, can be set to print a few lines - ` tail-f /var/log/ message ` added-fTee reads data from the standard input and writes to the standard output as well as the file: - ` ls/usr/bin | tee teeFile. TXT | grep zip ` = = > the contents written to teeFile. TXT, then pass the data to the grep command \ > change the output to a file, such as ` ls-l/usr/bin > output. TXT ' '> output. TXT' can empty the contents of output. TXT \>\> add the output to the end of the file instead of rewriting the file: 'ls-l/usr/bin >> output. TXT '2\> Output program error information to the file:' ls-l/bin/usr 2> error. TXT '&\> Writes the output and error information to the same file:' ls-l/bin/usr &> output.txt '\>/dev/null throws unwanted output. /dev/null is a special file called a' bit bucket 'that accepts input and does nothing with itCopy the code

The pipe line

The ability of commands to read data from standard input and send it to standard output is exploited by a shell feature called the pipe line. Using pipeline operators “|” (vertical bar), a command’s standard output can be sent through a pipe to another command’s standard input, pipeline can complete complex operations on data:

ls -l /usr/bin | less

Ls -l/bin/usr/bin | sort | less: the/bin and/usr/bin under the content of the list after the merge sort output to less

ls -l /bin /usr/bin | sort | uniq | less

: Add uniq to delete duplicate rows

Ls -l/bin/usr/bin | sort | uniq – d | less: uniq to add the -d option can check duplicate rows

Chap08 The world through the eyes of the shell — various expansions and references

Characters in

Echo * does not print an asterisk (*). This is because * is a wildcard character that the shell expands into something else before the echo command is executed

Pathname expansion

echo D*

echo [[:upper:]]

echo /usr/*/share

Echo * The display result does not contain the display of hidden files

Ls-a Displays all files, including hidden files

Wavy line expansion

Echo ~ ==> /home/tianmiao185 is displayed

Echo ~tianmiao185 ==> /home/tianmiao185 is displayed

Arithmetic expression expansion

Format is $((expression))

Echo $((2+2))

Echo $(((2+2) ** 2)) output 16, ** is a power

Curly bracket unwrapping

Echo Front-{a,b,c}-back Output front-a-back front-b-back front-c-back

echo Number-{2.. 5} Outputs number-2 number-3 number-4 number-5

echo {a.. Z} will print 26 letters in sequence

mkdir {2007.. 2009} – 0 {1.. 9} {2007.. 2009} – {10.. 12} curly braces can be nested, and the left side will create a series of year-named folders

Parameters on

Echo $USER will output Tianmiao185, USER is a variable in the system environment variable configuration file.

Printenv | less view all effective variables

Command substitution

Command substitution allows us to use the output of a command as an expansion mode

The echo $(ls) command replaces the $(ls) command by wrapping the $(ls) in parentheses to pass the result as an argument to another command: $(ls)

The file $(ls/usr/bin / * | grep zip) = = > command substitution is more complex

Older versions of the shell also supported the format of wrapping commands with ‘ ‘symbols:

ls -l `which cp`

quotes

Double quote wrapping prevents space, ~, curly brace, pathname, character expansion. It does not prevent expansion involving $(argument expansion, variable substitution, arithmetic expression). It does not prevent \ (backslash), and ‘(backquote).

Single quotes prevent all expansions, including those involving $

escape

You can use \ to escape special characters in the command

\\b BackSpace \\n NewLine \\ an Alert, cause the computer beep \\r Return \\t Table TABCopy the code

Echo -e “Time is up \a” will parse \a into a buzzer, equivalent to echo “Time is up”$’\a’

Chap09 Advanced keyboard skills

Keep in mind a few that can be used frequently:

The clear screen clearing CTRL-lClear the screen and move the cursor to the top left cornerhistoryDisplay history command list CTRL-aMove the cursor to the top of the line with CTRL-eMove to the end of the line Ctrl-K Cuts the text at the end of the line Ctrl-U Cuts the cursor at the beginning of the line Ctrl-y Pastes the text in the cutting ring to the cursor position TAB can be automatically completed. Press TAB twice to output all the content that meets the requirementsCopy the code

The history command

history| less browsing history commandhistory| grep/usr/bin search command specifies the pattern of history, will be similar: ` 88 ls-l/usr/bin > ls-output. TXT 88 Apply the specified line command. The up arrow applies the previous history command. The down arrow applies the next history commandCopy the code

Incremental search

Ctrl-r starts the incremental search command, then type the search keyword, press Enter to execute the command, or Ctrl-j to copy the line from the history list to the current command line, type Ctrl-R again to find the next match, type Ctrl-G or Ctrl-C to exit the search

Chap10 permissions

The Linux system has multiple users. Each user can only operate the directories and files under its own permission.

The command

Id displays the user id. The UID, GID, and group respectively indicate the user ID, user group ID, and user group to which the user belongs. The user account information is defined in the /etc/passwd file, and the user group information is defined in the /etc/group file. -g group, which indicates the user group to which the user belongs. -o others, which indicates other users. -a all, -chmod u+x file1. TXT Adds executable permission to the user. -chmod u-x file1. TXT -chmod +x file1. TXT is equivalent to chmod a+x adds x permission to all TXT "=", indicating that only the specified permission is available and all other permissions are deleted. -u +x,go=rw Gives the execute permission to the file owner and the read and execute permission to the group and others. Multiple Settings can be separated by commas. Chown changes the owner of the file, and the chown argument instance: -bob changes the owner of the file from the current owner to the user Bob. -bob :users Changes the file owner to user Bob and the file user group to user group users. - :admins Change the user group of the file to admins. The owner of the file remains the same. -bob: The file owner is changed to Bob, and the file user group is changed to the group that Bob belongs to when he logs in to the system. CHGRP changes the ownership of a file groupumaskSet the default file permission su 'su [-[l]] [user]' su command to start the shell as another user"exit", returns to the original shell sudo to execute the command as another user. One important difference between - and su is that sudo does not restart a shell or load another user's shell environment - the shell does not prompt for a password for a short time after the first sudo command is used, because, in most configurations, The sudo command will trust you for a few minutes until the clock runs outCopy the code

-rw-r– 1 me me 0 2008-03-06 14:52 foo.txt

-rw-rw-r– The first letter is: – file, d directory, l soft link, followed by three groups, which are the permission of the user on the file, the permission of the user’s group on the file, and the permission of all other people on the file