Home  >  Article  >  Operation and Maintenance  >  Linux--common commands and basic knowledge

Linux--common commands and basic knowledge

PHP中文网
PHP中文网Original
2017-06-20 09:22:311809browse

Linux common basic commands

1.ls(list list)

ls: List all files in the current directory (not Contains hidden files)

 ls-a: Lists all files in the current directory (contains hidden files)

 ls-l: Lists all files in the current directory and displays detailed information

 ls-a-l ls-l-a ls-al ls-la: The above four types all mean to list the current All files in the directory and display detailed information (including hidden files)

2.cd(change directory Modify/switch directory)

 cd: Switch directory

(***When you create a new folder, two hidden files will be generated by default: (1). (2).. The two hidden files are stored in the current directory and The path to the upper-level directory. When executing cd. and cd.., the actual principle is to enter the directory path stored in the file***)

3.pwd (print work directory prints the current path/absolute path)

pwd: displays the current path (displayed starting from the root path)

4.mkdir (make directory Create a new empty folder)

mkdir: create a new empty folder

mkdir -p: cascade create folders (example: mkdir - p abc/def)

5.mv (move moves files between directories and changes file names)

mv source file pathname target file pathname: move the source file Go to the target file path (only modify the file path without renaming the file)

 (Example: mv abc/1.txt ./1.txt)

mv source file name target file name: Rename the file (modified the file but did not move the file/modify the file path)

  (Example: mv 1.txt 2.txt)

 ( ***Relative path and absolute path***)

 Full path (pathname)---------D:\winshare\enume.c

Path (path)----------D:\wishare

File name----------enume.c

6.touch(Create a new empty file Touch:Create a new empty file

(Example: touch 1.txt )

7.cp (copy Copy files or folders)

cp Source file pathname Target file pathname: Copy the source file to the target file (copy Ordinary file)

 (Example: cp 1.txt ../../abc/1.txt)

 cp -r Source file pathname Target file pathname: Copy the source file Go to the target file (copy folder)

 cp -f Source file pathname Target file pathname; force copy (overwrite)

 (Generally speaking, cp is generally used in actual operations -f or cp -rf)

 

8.rm (remove remove files or folders)

 rm pathname: delete files

 rm -r pathname: Delete folder

rm -f pathname: Forced deletion of files or folders (reduce error messages)

9.cat (directly on the command line Display the content of the file under the command line and enter the content into the file)

Cat name: Display the content of the file directly under the command line (practical and when the file content is small)

10.rmdir(remove directory delete empty folder)

rmdir pathname:delete empty folder

11.ln(link connection file)

(***The shortcut in Windows and the file it points to are two independent files. Both occupy hard disk space. However, when the user accesses the shortcut, the effect is equivalent to accessing the pointed file***)

***Two kinds of link files in Linux***

  (1.) Soft link (symbolic link): The effect is equivalent to the shortcut in Windows

 ln -s Source file name Symbolic link file name: Create a symbolic link file for the source file

 (Example: ln -s src.c link.c That is, link.c is src.c a symbolic link file)

(2.) Hard link (not available in Windows): A hard link is actually the same file on the hard disk. The effect is similar to a file on the hard disk. Every time a file is deleted, as long as it has other hard links, As long as the connection exists, the file will not be truly deleted. Only when all connection files are deleted will the file be truly deleted from the hard disk.

ln source file name connection file name: Create a hard link for the source file

(Example: ln a.c b.c creates a hard link file b.c for a.c)

 (***The difference between hard links and soft links is that after the soft link deletes the source file, the linked file will also become invalid, while after the hard link deletes the source file, the linked file will not be affected, that is, there is no master-slave relationship. ***

12.man (query the man manual to get help information)

 man 1 xxx: 1 means querying Linux Command (xxx here represents the Linux command)

 (Example: man 1 ls Query all Linux commands of ls)

man 2 xxx: 2 means the query is Linux api (here xxx represents Linux api)

man 3 xxx: 3 represents that the query is a c library function (xxx here represents a c library function)

13.apt- get (a program to install and uninstall software in ubuntuonline)

apt-get install xxx: install software xxx

apt-get remove xxx: uninstall software xxx

(Note: The release version, kernel version, and customization of the Linux operating system have caused the incompatibility of software in Linux. Installing software in Linux is a difficult task, and the installed software may not necessarily work. Ubuntu solves this problem. Ubuntu makes a list of all software suitable for a certain distribution. Then the user installs the software through apt-get install and will connect to the Ubuntu server. The server will follow Ubuntu's version, download the appropriate software for you to install, thus ensuring the compatibility of the software)

14. history (history command, used to display used commands)

(***bash retains a certain number of commands that have been entered in the shell through the history command file. When bash executes a command, it will not immediately write the command into the history command list, but The command is now placed in the memory buffer, which is called the historical command list. Wait until bash exits and then write the command list into the historical command price ***)

History (without parameters): Display the contents of the entire history list

History [n]: Display the last n commands

Quickly execute history commands:

history - !n: Re-execute the nth command

history -!-n: Repeat the n-th command

history !!: Re-execute the previous command

history -a: Append the current history command list to the history command file

history -c: Clear the current history command list

history -r: Replace the contents of the history command file with the current history

in the command list History -w: Write the current history command list to the history command file and replace the content in the original history command file.

15. alias (get an alias, give an alias to a command)

alias: Query the currently defined alias list

alias Alias=xxx Command: Give the xxx command an alias

unalias Alias: Cancel the alias setting

(***alias command is only valid for this login system, if you want to If you use this command alias to log in to the system, you need to modify the "~/.bashrc" file (root user is /root/.bashrc, ordinary user is /home/*/.bashrc), add the following command to the file: alias alias = "Terminal command"; save the file, log out and log in again to use this command)

 


Linux Basics

1. The first ten characters (--rw-r--r--) in the file details displayed by ls -l represent The meaning of

##Character 1: Represents the file type

 -: Ordinary file (.txt .out)

 d (directory): Folder

 l(link):Indicates the symbolic link file (you will use -> to type the file it points to later)

 s(socket):Indicates the socket file

p (pipe): represents the pipeline file

The remaining 9 characters are divided into 3 groups, indicating file permissions (r (read): readable w (write): writable x (execute): Executable)

The first three characters: Indicates the permissions of the owner of this file on the file

The middle three characters: Indicates the permissions of the owner's group on the file

The last three characters: Indicate the permissions of other users on the file

2. The meaning of some symbols in the Linux command line

. Directory

/ Representative Root Catalog

## $ The command line of ordinary user command line reminder one or more characters)

? Matches any single character

[ ] Matches any single character contained in brackets (brackets usually give characters or character ranges connected with '-')

(* **Host directory: The default directory designed by the operating system for the current user to store files and work. It is equivalent to the 'My Documents' directory in Windows. This directory is the host directory designed by Windows for users. Every directory in Linux Users have their own home directories. The root user's home directory is in the /root/ directory, and the ordinary user's home directory is in the /home/username/ directory. You can directly return to the host directory by using 'cd ~'*** )

3. Ordinary users and privileged users

The privileged user in Windows is Administrator, ordinary users There can be many users. Privileged users are the administrators of the system and have operating permissions on all files in the system. For ordinary users, each user can only handle their own inquiries and cannot access other users' files, let alone access them at will. System Files.

There is also a difference between ordinary users and privileged users in Linux. The privileged user is the root user, and the rights of ordinary users are restricted. For example, ordinary users cannot enter the cd/root directory. Ordinary users cannot use apt-get install to install software.

Use the su directory to switch between users

su (su root): switch directly to the root user (you can not add root)

su username: switch to the username user Next

sudo: Temporarily obtain root user permissions

(Switch from the root user to the ordinary user and use the command directly without entering a password, but you need to enter the password to switch from the ordinary user to the root user) , you also need to enter the password when switching from ordinary user to ordinary user)

The above is the detailed content of Linux--common commands and basic knowledge. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn