20165230 preparatory work 3 Linux installation and learning

Source: Internet
Author: User
Tags gz file parent directory rar readable system log line editor

20165230 pre-Job 3 Linux installation and learning install Linux operating system

Through the learning practice based on the VirtualBox virtual machine installed Ubuntu Graphics tutorial, started the installation of virtual machines, according to the tutorial step by step to complete.

    • Problems encountered:

      1. In the installation of Ubuntu system software, click on the official website download page error occurred, the download did not succeed

      2. When the boot disk is selected, there is no direct selection of the package, but the selected file after decompression, there is an installation error

    • Workaround:

      1. By turning to classmates, we got the download resources of Ubuntu system software and successfully downloaded

      2. By re-downloading Ubuntu system software and re-selecting it, the final installation is successful.

      Learning of the Linux commands one. Learn the ingenious method of learning Linux commands

      Understand that Linux is also an operating system, as well as the architecture and learning path of this operating system.
      At the beginning of the study, the Linux command, the Man command and the cheat command of the understanding is not deep, do not understand how they apply to the actual and what the meaning, just follow the text of the shortcut keys and commands to practice, the three kinds of core commands have a superficial understanding.

      Two. Practice Learning Linux Basics in the lab Building (new) Course section I Introduction to Linux systems
    • The Linux operating system includes the system call and the kernel two layers in the computer system.

    • Learn about the history of Linux and the different points of Windows and Linux. Windows is closer to our daily lives, easy to use, wide application-oriented, compatible, and Linux operating systems are more intrinsic, more secure, and support open source.

Section II Basic concepts and operations
    • Linux itself does not have a graphical interface.
    • We work with the Linux system through the shell program, which in the graphical interface allows us to complete user input and display output in a single window.
    • Linux defaults to 6 virtual consoles for users to log in. You can use Ctrl+Alt+F1~F6 to switch and press to Ctrl+Alt+F7 switch back to the graphical interface.
    • The shell is a program that accepts user input commands and hides the underlying details of the operating system. There are bash, zsh, Ksh, CSH, and so on, the Ubuntu terminal uses bash by default, the default desktop environment is GNOME or unity, the lab building uses ZSH,XFCE.
    • Important Shortcut keys
    1. TabKey to complete the command, complete the directory, fill the command parameters
    2. Ctrl+cForcibly terminates the current program
    3. Ctrl+dKeyboard input end or exit terminal
    4. Ctrl+sPause the current program, pause and press any key to resume running
    5. Ctrl+zPut the current program in the background to run, restore to the foreground for command FG
    6. Ctrl+aMove the cursor to the input wardrobe
    7. Ctrl+eMove the cursor to the end of the input line
    8. Ctrl+kRemove from cursor position to end of line
    9. Alt+BackspaceDelete a word forward
    10. Shift+PgUpScroll the terminal display up
    11. Shift+PgDnScroll down the terminal display
    12. Direction key restore previously entered command
    • Wildcards are used to implement fuzzy matching of strings (such as file names, parameter names)
    • Create multiple files at once:

    • You can get a detailed description of a command and how to use it with the Man command.
    • The man manual has a lot of content and is divided into 8 partitions
    1. General Command
    2. System calls
    3. Library functions, covering the C standard function library
    4. Special files (usually devices in/dev) and drivers
    5. File formats and conventions
    6. Games and Screensavers
    7. Miscellaneous
    8. System administration Commands and Daemons

The following sections are generally included: name, Synopsis (summary), DESCRIPTION (description), EXAMPLES (example), see ALSO

    • Homework

Section III User and file Rights Management Linux user management view users
    1. whoamiView the user name of the currently logged on user
    2. who -aPrint all that you can print
    3. who -dPrint the Dead process
    4. who -mWith AM I,mom likes
    5. who -qPrint the current number of logged-in users and user names
    6. who -uPrint current logged in user login information
    7. who -rPrint Run level
Create user

In the Linux system, the new/add user needs root privileges, to use sudo This command, there are two prerequisites: one is to know the current login user's password, and the second is the current user must be in the sudo user group.

su <user>Can switch user, need to enter a password (Linux input password is not shown)

sudo <cmd>You can run the cmd command at a privileged level, require that the current user belongs to the sudo group, and require the current user password to be entered. For example: sudo adduser lilei create a user named Lilei.

su - <user>The user is also switched, and the environment variable is changed to the target user's environment variable. For example: You su -l lilei can switch to Lilei user login.

You can use exit and shortcut keys as you exit the current user and exit the terminalctrl+d

User groups
    • See which user groups you belong to

Method One: Use the groups command

Where the colon is preceded by the user, followed by the user group that the user belongs to. Here you can see that the Shiyanlou user belongs to the Shiyanlou user group, and each time a new user does not specify a user group, the default is to automatically create a user group with the same user name.

Method Two: View/etc/group file

The cat command reads the contents of the specified file and prints it to the terminal output. | sortindicates that the text to be read is sorted in a dictionary and then output. At the bottom you can see the user group information for Shiyanlou. It can also be filtered and then output in the following ways.

    • Add other users to the sudo user group

      Use usermod the command to add a user group to a user, which must have root privileges.
      You can use the root user to add user groups to other users, or use the sudo command for other users who are already in the sudo user group to execute the command.

Delete User

Linux file permissions view file permissions

Use the LS command to view$ ls -l

    • lsOther uses of the command

ls -AShow except '. ' (current directory), ' ... ' All files that contain hidden files except the ones above the previous directory (the file that starts with '. ' In Linux is a hidden file)

ls -dl< directory name > View the full properties of a directory instead of displaying the file attributes in the directory

ls -AsShDisplays all file sizes and renders in a way that ordinary people can understand, where small s is the size of the display file and big S is sorted by file size

Change file Owner
    • The problem I encountered: Because the previous command to delete the Lilei user was executed, the user was re-created, not added to the sudo user group, and failed to change the owner of the file:

Came uplilei is not in the sudoers file

    • WORKAROUND: Re-execute the Lilei join the Sudu User Group command sudo usermod -G sudo lilei and change the file owner

Modify file Permissions

Three sets of permissions for each file (owner, user group, other user, remember this order is certain) corresponds to a "rwx", that is, a "7"

If I want to change the permissions of the file "Iphone6" to only I can do so:

$ chmod 700 iphone6

Homework

Add a user loutest, use sudo Create file /opt/forloutest , set to user loutest can read and write. And the operation process is written into the experimental report.

Fourth Linux directory structure and file basic operation Linux directory structure
    • Linux is a tree-shaped directory structure to build the entire system, logically, Linux disk is "hung in" (mounted) directory, each directory can not only use the local disk partition of the file system, can also use the file system on the network.

      FHS Standard
    • FHS (file system hierarchy Standard)
    • FHS defines the two-tier specification, the first layer is / what file data should be placed in each of the following directories, such as/etc should be placed in the settings file,/bin and/sbin should be placed executable files and so on.

    • The second layer is defined for the subdirectories /usr /var of the two directories. For example,/var/log places system log files,/usr/share places shared data, and so on.

Directory path Path

Use the cd command to switch directories, in Linux use . represents the current directory, the first .. level of the directory (to . start with the file is a hidden file, you can use the ls -a command to view hidden files), to - indicate the last directory, typically represents the home directory of the current user. Use the pwd command to get the current path (absolute path).

Absolute path
    • The full path from the root "/" directory to the end of the directory you want to go to
      /usr/local/binA directory that represents a directory in the directory under the root directory usr local bin .

      Relative path
    • Relative to the path to your current directory, the relative path starts at the current directory and . ends with the directory you want to go to, in the form of:
      usr/local/bin
      usrDirectory is a subdirectory / under the directory, you can omit it, . if it is the current directory of the previous level of directory, you need to use .. , such as your current directory as a home directory, the root directory should be represented as the top level directory ../../ ( home directory) of the previous level directory ( c14/> directory).

    • In the process of directory switching can be more use of Tab key auto-completion, to avoid input errors, press two consecutive Tab to display all candidate results

      Basic operations for Linux files new
    • Create a new blank file

      touchCreate a blank file with a command
      $ touch test
    • New Catalog

      Use the Make mkdir directories command to create an empty directory or to specify permission properties for creating a directory
      $ mkdir 文件名
      Create a multilevel directory: using -p parameters to create a parent directory at the same time, you can create a multilevel directory at once (this is useful when installing the software and configuring the installation path at times):
      $ mkdir -p father/son/grandson

Copy
    • Copying files

      Use cp the (copy) command to copy a file or directory to the specified directory.

$ cp test father/son/grandson

    • Copy Directory

      To successfully replicate a directory requires -r a plus or -R a parameter that represents recursive replication:

$ cp -r father family

Delete
    • deleting files

      rmDelete a file or directory using the (remove files or directories) command: (can be forced to delete using the-f parameter)
      $ rm test
      $ rm -f test
    • Delete Directory

      As with the copy directory, to delete a directory, you also need to add -r or -R parameter:
      $ rm -r family

      Moving files and renaming files
    • Moving files

      Use mv the (move or rename files) command to move the file (cut). Move the file "File1" to the "documents" directory MV source directory file destination directory:
      $ mkdir Documents
      $ mv file1 Documents
    • Renaming files

      Rename the file "File1" to "myfile" mv old filename new file name:
      $ mv file1 myfile
    • Batch Rename

      With the rename command

View Files
    • Use cat , tac and nl commands to view files

      catis displayed in reverse order, and the tac nl command adds the line number and prints it.
      If we want to see the passwd file that was copied from the "/etc" directory, $ cat passwd You can add the -n parameter to display the line number.$ cat -n passwd
    • Open a file with a more tool passwd
      moreAnd less is the content that is inherently used to "read" a file.
      $ more passwd
      When turned on, only one screen is displayed by default, and the bottom of the terminal shows the current reading progress (percentage). You can use the ENTER key to scroll down a line, use the space key to scroll down one screen, press H to display Help, and Q to exit.
    • Use head and tail commands to view files

      Head only looks at the first few lines of the file (the default is 10 lines, and less than 10 lines show all) tail only a few lines.
      You can look at a line more directly, plus a parameter, followed by the -n number of rows:$ tail -n 1 /etc/passwd

View File types
    • Use the file command to view the types of files:$ file 文件名

      Edit File
    • Editing files under Linux usually we use a dedicated command line editor like (Emacs,vim,nano)

Section fifth environment variables and file lookup environment variable variables

A variable is a symbol in your computer that is used to record a value (not necessarily a number, or a character or a string).

    • Create: Use declare the command to create a variable named tmp:
      $ declare tmp
    • Assignment: Use the = number assignment operator to assign the variable tmp value to Shiyanlou:
      $ tmp=shiyanlou
    • Read the value of a variable: use echo commands and $ symbols ( $ symbols are used to denote values that refer to a variable):
      $ echo $tmp

    • Note: Not all types of variable names are available, the variable name can only be English letters, numbers, or underscores, and cannot begin with a number.

Environment variables
    • The scope of the environment variable is larger than the custom variable, such as the Shell environment variable acting on itself and its child processes. By default, when a process is created, it inherits most of the environment settings of its parent process. The shell program also runs on the operating system as a process, and most of the commands we run in the shell will run as a child process of the shell.
    • Three environment variables:
    1. The current shell process private user-defined variable, valid only in the current shell.
    2. The built-in variables of the Shell itself.
    3. An environment variable exported from a custom variable.
    • Three commands:
    1. Set: Displays all environment variables for the current shell
    2. ENV: Displays the environment variables associated with the current user and allows the command to run in the specified environment
    3. Export: Displays a variable that is exported from the shell to an environment variable, and can also be exported to the environment variable by the custom variable
    • With regard to environment variables, it is simple to understand whether the child processes in the current process are valid or not, and the environment variables are valid.
    • It is often customary to set the environment variable name to uppercase .
    • Permanent effect

      According to the lifetime of the variables, the Linux variables can be divided into two categories:
      1. Permanent: Need to modify the configuration file, the variable is permanently effective;
      2. Temporary: Using the Export command-line declaration, the variable is invalidated when the shell is closed.

      If you want to add a permanently active environment variable, just open/etc/profile, and at the end add the environment variable you want

      The search path and order of the command
    • Search through the environment variable path in the shell. When we execute a command in the shell, the system will go through the directory in the order followed by the path set in the path, and if there is a command with the same name, execute the one found first.

    • Back to the top level of the directory, that is, the Shiyanlou home directory, when you want to run the two programs, you will find that the prompt command can not be found, unless the full path of the command, but it is inconvenient, how do you want to use the same system command to execute the script file or program you created? Then add the path of the command to the paths environment variable.

Add a custom path to the "path" environment variable
    • The paths inside the path are: as delimiters:
      $ PATH=$PATH:/home/shiyanlou/mybin
      Note that absolute paths must be used here.
      Appending the path in the PATH environment allows you to execute the two commands in any directory, taking care to remove the preceding.

    • The command to add a custom path to path is automatically executed each time the Shell is started.
      You can simply use the following command to add content directly to .zshrc the:
      $ echo "PATH=$PATH:/home/shiyanlou/mybin" >> .zshrc
      The above command >> indicates that the standard output is redirected to a file in an append manner, noting that the previous use is to redirect to > a file in a way that is overwritten and must be distinguished when used. A new file will be created if the specified file does not exist.

      Modifying and deleting existing variable variables

Variable deletion

To unset Delete an environment variable using a command:
$ unset temp

How to make an environment variable effective immediately
  • Use source commands to make them effective immediately, such as:
    $ source .zshrc
  • sourceThe command also has an alias that is . , notice that the point area that represents the current path is separate, although the form is different, but in the same way, the above command if replaced . by the way it should be:
    $ . ./.zshrc
    Note that the first point is followed by a space, and the subsequent file must specify a complete absolute or relative pathname , which is source not required.

    Search for files
  • Whereis Simple and fast

    The search was quick because it did not look up from the hard disk, but instead queried directly from the database. Whereis can only search binaries (-B), man Help Files (-m), and source code files (-s).

  • Locate Fast and full

    Through the "/var/lib/mlocate/mlocate.db" Database lookup, but this database is not updated in real-time, the system will use a timed task to automatically perform the updatedb command update once a day, so sometimes just add the file, it may not be found. It can be used to find different file types under the specified directory.

    If you want to only count the number can be added to the-c parameter, the-i parameter can ignore the case to find, Whereis-b,-m,-s can also be used.

  • which small and fine

    Which itself is a shell built-in command, and we typically use which to determine if a specified software is installed because it only searches for commands from the path specified by the PATH environment variable

  • Find fine and fine

    Can be found by file type, filename and can be searched according to the properties of the file (such as the file's timestamp, file permissions, etc.)
    Such as$ find /etc/ -name interfaces

    Note the path to the Find command is the first parameter, and the basic command format is find [path] [option] [action].

Digital Rain

Challenge: Finding a file target
    1. Locate Sources.list File
    2. Change the file owner to yourself (Shiyanlou)
    3. Modify the permissions to only be readable and writable

Problems encountered in the course of the experiment
    1. Enter only find commands to prompt for insufficient permissions
    2. No full name entered when searching by name
    3. No path entered when accessing file permissions
Solutions
    1. Modify inputsudo find
    2. Input command-name sources.list
    3. You should enter the full path of the file/etc/apt/sources.list
The sixth section document packing and compress concept explanation

Real-Combat ZIP compression Packaging Program

-rThe parameter indicates that the recursive package contains the entire contents of the subdirectory, and the -q parameters are expressed in quiet mode, that is, not outputting information to the screen, -o indicating the output file, followed by packaging the output filename immediately thereafter. Later use du the command to view the size of the packaged file

    • Set the compression level to 9 and 1 (9 max, 1 min), RePack:

Visible default compression level should be the highest

Note: Only absolute paths can be used here, otherwise it will not work

    • Create an encrypted ZIP package

Use -e parameters to create an encrypted compressed package:

$ zip -r -e -o shiyanlou_encryption.zip /home/shiyanlou

If you want to create a zip file on Linux that has no problem after extracting it on Windows, then you need to make some changes to the command:

$ zip -r -l -o shiyanlou.zip /home/shiyanlou
The need to add -l parameters will be LF converted to achieve the CR+LF above purpose.

Extracting a ZIP file using the unzip command
    • Unzip the shiyanlou.zip to the current directory:
      $ unzip shiyanlou.zip
    • Use Quiet mode to extract the files to the specified directory:
      $ unzip -q shiyanlou.zip -d ziptest
    • No pressure to view only the contents of the compressed package can use -l parameters:
      $ unzip -l shiyanlou.zip
    • Use -O the (English letter, capital O) parameter to specify the encoding type:
      unzip -O GBK 中文压缩文件.zip

      RAR Packaging Compression Command
    • To create a compressed package or add a file to a compressed package from a specified file or directory:
      $ rm *.rar
      $ rar a shiyanlou.rar .

Note: RAR command parameters do not-if added will error.

    • To delete a file from the specified compressed package file:
      $ rar d shiyanlou.rar .zshrc
    • To view the unresolved files:
      $ rar l shiyanlou.rar
    • Extracting RAR files using Unrar
    1. Full path Decompression:
      $ unrar x shiyanlou.rar
    2. Remove Path Decompression:
      $ mkdir tmp
      $ unrar e shiyanlou.rar tmp/
Tar Packaging tools
    • Create a tar package:
      $ tar -cf shiyanlou.tar ~

-cRepresents creating a Tar package file that -f specifies the name of the file to be created, noting that the file name must immediately follow the -f parameter.

    • Unpack a file ( -x parameter) to an existing directory (parameter) of the specified path -C :
      $ tar -xf shiyanlou.tar -C tardir
    • To view only the unresolved package file -t parameters:
      $ tar -tf shiyanlou.tar
    • Keep file attributes and follow links (symbolic links or soft links), sometimes we use tar to back up files when you restore to other hosts you want to keep the attributes (parameters) of the file -p and the source file that the backup link points to instead of the link itself ( -h parameters):

      $ tar -cphf etc.tar /etc
    • To create a file in a different compressed format, we only need to add parameters based on the creation of the tar file -z , using gzip to compress the file.

      $ tar -czf shiyanlou.tar.gz ~
    • Unzip the. tar.gz file:
      $ tar -xzf shiyanlou.tar.gz
    • We want to use other compression tools to create or unzip the corresponding file only need to change one parameter:

compressed file format Parameters
*.tar.gz -Z
. tar.xz -j
*tar.bz2 -j
Section seventh file system operations and Disk Management basic Operations view disk and directory capacity
    • To view disk capacity using the DF command

      $ dfOr$ df -h
    • To view the capacity of a directory using the du command

      $ duOrdu -h
      The-d parameter specifies the depth of the view directory
      1. View information for Level 1 directories only
        $ du -h -d 0 ~
      2. View Level 2
        $ du -h -d 1 ~
    1. Du-h #同--human-readable to improve the readability of information by K,m,g.
    2. Du-a #同--all Displays the size of all files in the directory.
    3. Du-s #同--summarize only displays totals, listing only the last added value.

      Simple Disk Management Create a virtual disk
    • To create a virtual image file using the DD command

Create an empty file with a capacity of 256M from the/dev/zero device

$ dd if=/dev/zero of=virtual.img bs=1M count=256

$ du -h virtual.img

    • Format a disk with the MKFS command

      $ sudo mkfs.ext4 virtual.img

    • Mount a disk to a directory tree using the Mount command

      mount [options] [source] [directory]

Common operations:mount [-o [操作选项]] [-t 文件系统类型] [-w|--rw|--ro] [文件系统源] [挂载点]

The problem I'm having

Displays only the root user to perform when mounting a real disk to the directory tree

Solutions

Try to use$ sudo mount -o loop -t ext4 virtual.img /mnt
was still unsuccessful, and then learned to learn that due to the environment of the Experimental Building (the Linux kernel used in the environment did not add support for Loop device at compile time), it cannot be mounted successfully

    • Uninstalling mounted disks using the Umount command

      $ sudo umount /mnt
    • Partitioning a disk using Fdisk

      $ sudo fdisk virtual.img
    • Using the Losetup command to establish an association between a mirror and a loopback device section eighth Linux help commands built-in commands and external commands

      The built-in commands are actually part of the shell program, which contains some of the simpler Linux system commands that are written in the bash source Builtins and are identified by the shell program and run inside the shell program, usually in Linux When the system loads the runtime, the shell is loaded and resides in system memory. and parsing the internal command shell does not need to create a child process, so it executes faster than an external command. For example: History, CD, Exit and so on.

      External commands are part of the utilities in a Linux system, because the utility is usually powerful, so it contains a large number of programs that are not loaded into memory with the system when the system is loaded, but instead call memory when needed. Although it is not included in the shell, its command execution process is controlled by the shell. External commands are installed outside of Bash, usually on/bin,/usr/bin,/sbin,/usr/sbin, and so on. For example: LS, vi and so on.

    • Differentiate between built-in commands and external commands

With the type command

    1. The results show that the built-in commands are builtins in the xxx is a shell builtin bash source. def
    2. xxx is /usr/sbin/xxxThe result is an external command, an external command in/usr/bin Or/usr/sbin, etc.
    3. If the xxx is an alias for xx --xxx result is obtained, it indicates the name set by the command alias;

      Help commands for using the Assist command

      help ls

The help command can only be used to display information about the built-in commands
To display external commands, use thels --help

Man command

man ls

Info command

info ls

20165230 preparatory work 3 Linux installation and learning

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.