Linux basics,

Source: Internet
Author: User

Linux basics,

1. Directory

  • /: Root directory. Generally, only the root directory is stored. in Linux, there is only one root directory. Everything starts from here. When you enter "/home" in the terminal, you are actually telling the computer to start from/(root directory) and then go to the home directory.
  • /Bin,/usr/bin: directory of executable binary files, such as commonly used commands such as ls, tar, mv, and cat.
  • /Boot: some files used during linux Startup, such as the Linux Kernel File:/boot/vmlinuz and the System boot manager:/boot/grub.
  • /Dev: stores Device Files in linux. Accessing a file in this directory is equivalent to accessing a device. It is commonly used to mount/dev/cdrom/mnt the optical drive.
  • /Etc: directory where the system configuration file is stored. It is not recommended to store executable files in this directory. Important configuration files include/etc/inittab,/etc/fstab,/etc/init. d,/etc/X11,/etc/sysconfig,/etc/xinetd. d.
  • /Home: the default user home directory. When a user account is added, the user's home directory is stored in this directory ,~ Indicates the Home Directory of the current user ,~ Edu indicates the Home Directory of edu.
  • /Lib,/usr/lib,/usr/local/lib: directory of the function library used by the system. The function library is required to call some additional parameters during program execution.
  • /Lost + fount: When an error occurs due to a system exception, some lost fragments are stored in this directory.
  • /Mnt:/media: Default disk mount point. Generally, the disk is mounted to/mnt/cdrom, which is not necessarily available. You can choose any location for mounting.
  • /Opt: directory for additional software installation on the host.
  • /Proc: the data in this directory is in the memory, such as the system core, external devices, and network status. Because the data is stored in the memory, it does not occupy disk space, important directories include/proc/cpuinfo,/proc/interrupts,/proc/dma,/proc/ioports,/proc/net.
  • /Root: Home Directory of the system administrator root.
  • /Sbin,/usr/sbin,/usr/local/sbin: the executable commands used by the system administrator, such as fdisk, shutdown, and mount. Different from/bin, these directories are commands used by the system administrator root. Generally, users can only view these directories, but cannot set and use them.
  • /Tmp: the directory where files are temporarily stored by a user or a program being executed. Anyone can access the directory. Important data cannot be stored in this directory.
  • /Srv: The data directory to be accessed after the service is started. For example, the webpage data to be accessed by the www Service is stored in/srv/www.
  • /Usr: Application storage directory,/usr/bin storage application,/usr/share storage of shared data,/usr/lib storage cannot run directly, but some library files necessary for many programs to run. /Usr/local: store the software upgrade package. /Usr/share/doc: directory where the system instruction file is stored. /Usr/share/man: Specifies the directory where the file is stored.
  • /Var: stores files that are frequently changed during system execution, such as the log files/var/log,/var/log/message that are changed at any time, /var/spool/mail: directory where the email is stored./var/run: after the program or service is started, its PID is stored in this directory.

2. access permission

Users can control the access level of a given file or directory. a file or directory may have read, write, and execution permissions:

  • Read Permission (r) is used to read files and browse directories.
  • Write Permission (w): Permission to add and modify files; permission to delete and move files in directories.
  • Executable permission (x): indicates the permission to execute files. For a directory, the user has the permission to access the directory.

Note: In general, Unix/Linux systems only allow the owner (owner) or Superuser of a file to change the read/write permissions of the file.

Each user has its own read, write, and execution permissions.

  • The first group of permissions controls access to their own files, that is, the owner permission.
  • The second group of permissions controls the user group's permission to access one of the user's files.
  • The third group of permissions controls the permissions of all other users to access a user's files.

3. Create a link ln

Linux linked files are similar to shortcuts in Windows.

Links are divided into soft links and hard links.

Soft link: the soft link does not occupy disk space. If the source file is deleted, the soft link becomes invalid.

Hard link: hard links can only link common files, but cannot link directories.

Format:

Ln source file link file ln-s source file link file

IfNo-sOption indicates creating a hard link file. Two files occupy the same size of hard disk space. Even if the source file is deleted, the linked file still exists. Therefore, the-s option is more common.

4. find the file

Common usage

5. Copy files using cp

6. Editor God Vim

Vi has three basic working modes: Command mode, text input mode, and last line mode.

Command Line Mode

At any time, no matter what mode the user is in, just press the ESC key to enable Vi to enter the command mode. In the shell environment (the prompt is $), enter the command to start Vi, the editor is also in this mode. In this mode, you can enter various valid Vi commands to manage your own documents. At this time, any character entered on the keyboard is interpreted as an editing command. If the entered character is a valid Vi command, Vi completes the corresponding action after receiving the USER command. Note that the entered command is not displayed on the screen. If the entered character is not a valid command of Vi, Vi will ring an alarm.

 Text input mode

In command mode, Enter command I, attach command a, open command o, modify command c, replace command r, or replace command s to enter the text input mode. In this mode, any character entered by the user is saved as the file content by Vi and displayed on the screen. During text input, if you want to return to command mode, Press ESC.

Last Row Mode

The last row mode is also called the ex escape mode. In command mode, you can press the ":" key to enter the last line mode. At this time, Vi will display a ": as the last line prompt, waiting for the user to enter the command. Most file management commands are executed in this mode (for example, writing the content in the editing buffer to a file is moderate ). After the last-line command is executed, Vi automatically returns to the command mode.

Vim basic operations

1. Enter the insert mode

I: Insert a character before the cursor I: Insert A line first a: insert A character after the cursor a: insert A line not o: Open a line down, insert A line first O: Open a line up, insert the beginning of a row

2. Enter the command mode

ESC enters command mode from insert mode or last line mode

3. move the cursor

H: Move left j: Move down k: Move up l: Move right M: move the cursor to the middle line L: move the cursor to the first line of the screen G: Move to the specified line, row-Gw: move one word at a time B: move one word at a time {: move by segment, move up}: move by segment, move down Ctr-d: Flip down half screen Ctr-u: flip up half screen Ctr-f: Flip down screen Ctr-B: Flip up screen gg: move the cursor to the beginning of the file G: move the cursor to the end of the file

4. Delete

X: Delete the last character of the cursor, equivalent to Del X: Delete the first character of the cursor, equivalent to Backspacedd: Delete the row where the cursor is located, n dd Delete the specified row number D: delete all content of the row after the cursor, including the character d0 where the cursor is located: delete all content of the row before the cursor, excluding the character dw where the cursor is located: delete the word at the starting position of the cursor, including the character where the cursor is located

5. Undo

U: Undo Ctr-r step by step: undo

6. Text Movement

>>: Right shift of the text line <: Left shift of the text line

7. copy and paste

Yy: copy the current row, n yy copy n rows p: open a new row at the cursor position, paste

8. Visual Mode

V: move by character. selected text V: move by line. The selected text can be used in combination with d, y, >>,< to delete, copy, and move left and right text blocks.

9. Replace

R: Replace the current character R: Replace the character behind the cursor of the current row

10. Search

/: Str search n: Next N: Previous

Instance: replace abc with 123

In last row mode, replace abc of the row where the cursor is located with 123: % s/abc/123/g. In last row mode, replace abc between the first row and the second row with 123:1, 10 s/abc/123/g

7. Ubuntu software operation commands

Update Source

Https://mirrors.tuna.tsinghua.edu.cn/

3. Back up the default Source

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

4. Update

Command: sudo vi/etc/apt/sources. list

Replace all the copied data.

Then you can run sudo apt-get install to download the sudo apt-get update source.

Sudo apt-get update source sudo apt-get install package installation package sudo apt-get remove package Delete package sudo apt-cache search package sudo apt-cache show package get package related information, for example, sudo apt-get install package -- reinstall sudo apt-get-f install reinstall sudo apt-get remove package -- purge Delete package, including the configuration file and other sudo apt-get build-dep package installation-related compilation environment sudo apt-get upgrade Update installed package sudo apt-get dist-upgrade system sudo apt-cache depends package understand that using this package depends on those packages sudo apt-cache rdepends package to check which packages of this package depend on sudo apt-get source package to download the source code sudo apt-get clean & sudo apt-get autoclean clear useless packages sudo apt-get check to check for corrupted Dependencies

 Install SSH

sudo apt-get install openssh-server

SCP

Remote File copying

Format

Scp-r target username @ Target Host IP Address:/absolute path of the target file/absolute/relative path saved to the local machine example: scp-r derek@192.168.0.100:/home/derek/share /. /home/test

You can copy a single file without the-r parameter. You must add the-r parameter to the copy directory.

1. Copy local files to remote

scp FileName RemoteUserName@RemoteHostIp:RemoteFilescp FileName RemoteHostIp:RemoteFolderscp FileName RemoteHostIp:RemoteFile

2. Copy local directory to remote

scp -r FolderName RemoteUserName@RemoteHostIp:RemoteFolderscp -r FolderName RemoteHostIp:RemoteFolder

3. Copy the remote file to the local device.

scp RemoteUserName@RemoteHostIp:RemoteFile FileNamescp RemoteHostIp:RemoteFolder FileNamescp RemoteHostIp:RemoteFile FileName

4. Remote directory copy to local

scp -r RemoteUserName@RemoteHostIp:RemoteFolder FolderNamescp -r RemoteHostIp:RemoteFolder FolderName

Samba server Construction

Samba is a free software that implements SMB protocol on Linux and UNIX systems. It can access Shared Files in linux systems in windows and mac operating systems.

1. Install

sudo apt-get install samba samba-common

2. Configuration

(1) create a path to the shared folder and create it under/home.

mkdir /home/share

(2) modify its permissions

chmod 777 /home/share

(3) modify the samba configuration file

vi etc/samba/smb.conf

After opening, add the following content at the end.

[Share] path =/home/share available = yes browseable = yes writable = yes # public = yes # No Password required
[Need] # when accessing the Samba server in Windows, the directory name is displayed, and comment = need share is written in the top level. # For the description of the shared directory, write browseable = yes # Whether the shared directory is visible, no is invisible, yes or do not write the default visible path =/share # shared directory path strength create mask = 0777 # create File default permission directory mask = 0777 # create directory default permission valid users = tom # specify login User, if this option is left blank, the user is visible to all by default. force user = nobody # The specified user can log on. Other users do not have the permission to log on. nobody does not limit force group = nogroup, specify User Group public = yes # Whether to view writable = yes for all successfully logged-on users # Write Permission, directory permission must also be permitted available = yes # whether to set the shared directory to be visible
Reference

3. Create a samba account

touch /etc/samba/smbpasswd
Smbpasswd-a derek # add your users to samba users

4. Restart

/etc/init.d/smbd restart

5. log on

In windows, win + r, enter \ IP Address

\\192.168.0.100

You can upload and download files as needed by entering the user name and password.

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.