Simple Command Linux
ls
List files in the current file directory (only file names are displayed)
pwd
Displays the path of the current action
cd
Jump path
ls -a
The hidden file can be displayed, and the command to create a hidden file is to touch.123.txt
add a "dot" to the file name.
ls -h
can display the size of the created file, an automatic statistic is performed
ls -l
Display the file information in the form of a linked list, a line of output, in fact, is detailed
ls -a -l -h
Integrated above is a list of three ways to output in the form of a chain
ls -alh
And ls -a -l -h
the role is the same
clear
is to clear the screen
touch
Create a file
mkdir
Create a folder
rm
To delete a file or a folder, it is worth noting that when deleting a folder, write it rm 文件夹名 -r
. -r
The meaning of this is recursion. Whether the folder is empty will be deleted!!
rmdir
Delete folder (folder is empty to delete)
rm / -rf
Delete from the root directory (all Evil commands ~ ~ ~ ~)
gedit
Editing files using the Linux default editor
cat
You can view the full contents of a file (not editable) and view the contents of two or more files at the same time, for example:
cat 1.txt 2.txt
And cat
can be redirected >
or used >>
, for example:
cat 1.txt 2.txt > xxx.txt
Then you can do it. 1.txt and 2.txt are written to the new Xxx.txt file. That's the realization.文件的合并
more
You can view the contents of a file (displayed as a percentage), and you can press the or key to turn the page to view if you want to continue viewing the following content f
b
.
A few simple shortcut keys
Tab
Keys can be auto-complete
b
can go back (flip screen)
f
can go down (flip screen)
q
If no ' command ' is displayed, press the Q key to exit the operation
ctrl + shift + t
Create a new label in the same terminal
alt + 1
Switch to the terminal of the first label, and so on
上箭头
And you 下箭头
can find the previous or next command so that you can quickly use the command without having to re-write the command.
Help Document View
命令的名字 + --help
can display the help of this command, or can be used to man + 命令的名字
achieve the same effect, for a chestnut: we want to see ls
the usage, you can use the following two methods to achieve: ls --help
or man ls
.
Use of wildcard characters
- Wildcard
*
: Can replace multi-bit (0-n) characters, for Fuzzy query operation, for example, in the directory of files 123.txt 234.txt 245.txt 134.txt ls 2*
After the execution of this command will be filtered out the file 234.txt 245.txt, which means 2
filter with the beginning of the file.
- Wildcard
?
: Can be used in place of a single character, for fuzzy query operations, for example: In the directory has a file 23.txt 234.txt execution ls 2?
command, will only display 23.txt. Similarly, if executed ls 2??
, 234.txt is displayed at this time.
- Wildcards
[]
can specify the scope of a fuzzy query. For example, in the directory downstream file 123.txt,456,txt,213.txt,143.txt execution ls 1[23]3
will only display 123.txt []
This wildcard character only one bit . Of course []
, it can also be written in [1-4]
this case, the value in brackets can be selected in 1,2,3,4, as long as there is one, you can.
redirect
For redirection, the main use is with >
>>
these two symbols. Here's an example: if we've created the Ers.txt sda.txt 123.txt three files in the directory
ls ers.txt sda.txt 123.txtls > xxx.txtlsers.txt sda.txt 123.txt xxx.txtgedit xxx.txt-----------------------------------下面是xxx.txt 显示的内容-----------------------------------ers.txt sda.txt 123.txt xxx.txt
With the code above, you can draw a few small effects on redirects.
1. When the redirect file is, a file is automatically created in this example to automatically generate the file xxx.txt
.
2. Redirection will send the information just displayed (including the generated xxx.txt) 写
to the "redirected file" that was just automatically generated. In this case, you can see ers.txt sda.txt 123.txt xxx.txt
the result with the Gedit command.
ls -alh >> xxx.txtlsers.txt sda.txt 123.txt xxx.txt gedit xxx.txt -----------------------------------下面是xxx.txt 显示的内容-----------------------------------ers.txt sda.txt 123.txt xxx.txtxxx.txt{此处是ls -alh 所显示的信息}
Through the above section of code, you can know that >>
can be appended and written, but if only >
, will be the original delete, write only the latest LS
LS and CD additions, relative paths, and absolute paths
- A line generally write only one command, if you have to write a lot of commands, remember to use
;
the two command to separate.
|
This symbol is similar to the concept of "plumbing", for example: ls -alh | more
This enables split-screen display of the content to be displayed.
- The basic explanation for the relative path and the absolute path is not explained much. In Linux,
.\A
This command represents the directory under the folder of a in the current directory. This means that a point can represent an absolute path . Instead, the ..
path to the previous layer is returned for example: Under directory \home\python\a, the result of using a command is cd ..
to return to the previous directory, which is the Python directory. Of course, there's a .
and ..
. There are no three or more points. In this case, in order to return to the home folder, the command should write: so that the cd ..\..
home folder, of course, you can also use absolute path.
cd -
is to quickly return the last path and can only be performed once.
cd ~
is to quickly return to the home directory. It's \home\yaojianlong\ on my machine.
MkDir's Supplement
- If we write a section with a command, write it wrong, or do not want to execute the command, we can write and
Ctrl + C
jump to the next line. We'll be able to re-write the order.
- For multi-layered folder creation, you can use the CD command and mkdir to create it, but that's a lot more hassle. Can be created in a simple way. For example: To create a/a/b/c/d to create a nested folder, you only need to use the following command:
mkdir /A/B/C/D -p
The creation of the above nested files is completed. -p
once the command executes, it is created first with the dependent file.
Attention
1. ls -a -l -h
The ls -l -a -h
effect is the same as the implementation, or it is not related to the order, for example, ls -alh
and the ls -hal
effect is the same; 2. Do not forget the space between LS and-ALH.
Soft links, hard links, grep,cp,mv
A Linux link file is similar to a shortcut under Windows. Linked files are divided into 软链接
and 硬链接
.
- Soft Link: Soft link does not occupy disk space, the source file is deleted and the soft link is invalid.
- Hard Links: Hard links can only link to normal files and cannot be linked to directories. Use format:
ln 源文件 链接文件ln -s 源文件 链接文件
If the 没有-s
option represents the creation of a hard-link file, two files occupy the same size of disk space, even if the source file is deleted, the link file still exists, so the-s option is more common form.
* * NOTE: * * If the soft connection and source files are not in the same directory. The source file uses an absolute path and cannot use a relative path. Soft links equivalent to the Windows system ' shortcuts ' and hard links in the equivalent of the file is another name, under Linux, can be seen as a number of names, for the new hard link is equivalent to the file of another name, if said, this file as long as there is a ' name ' exists, It can really exist.
- grep search: Equivalent to search lookups such as:
grep "ntsd" xxx.txt
The above code means to find fields containing these letters in the Xxx.txt file ntsd
.
If you include in the option, it -n
indicates a lookup field and displays the field's position (line number) in the file. The command is as follows:
grep -n "ntsd" xxx.txt
If you include a -v
lookup field and display the remaining fields that do not contain the field in the option, the command is as follows: (Displays information that does not contain the field)
grep -v "ntsd" xxx.txt
If you want to find a field in a file that starts with a ntsd
field, command the following: (Displays information that does not contain the field)
grep "^ntsd" xxx.txt
If you want to find a field at the end of a field in a file, ntsd
command the following: (Displays information that does not contain the field)
grep "ntsd$" xxx.txt
mv
Rename file (or folder)/move (cut and paste)
mv 1.txt 111.txt//把1.txt 重命名为111.txtmv 111.txt laowang/ //把111.txt 移动到laowang 文件夹中
cp
Copy files/folders (and paste)
cp 2.txt A //复制 2.txt 文件到 A 文件夹中
cp A laowang/ -r //只要是文件夹不能操作,加一个-r 就可以了。
find
The command can find the file, and the grep
difference is that grep is looking for content inside the file. This must not be confused. Find has the name and size options, and here's a simple example to illustrate the use of this command.
find /tmp -name ts //查找tmp目录下的 名字为 ts 的文件find /tmp -name "*ts*" //查找tmp目录下的文件名中含有 ts 的文件find /tmp -size 2M //查找tmp 目录下 文件大小为2M的文件
Compression and decompression
Compression format (i)
This method compresses the file relatively small OH
Compression Format (ii)
This method of compressing the file is relatively large oh (although it is nonsense, but I would like to say ~ hum)
Linux System-related commands
cal
(Show the calendar, do not write call, day by day to xxx crazy call)
For a chestnut: View the Calendar for the year 2018
cal -y 2018
date
Check the current time (very specific OH). date "+%Y年%m%d"
in this small command, the result is January 3, 2018 . That is, after the date command with double quotation marks, you can do it according to your own format, and there is a point to note that in this small command %Y
and %y
The effect is not the same, small y is only the last two digits of the year, for example, 2018 if you use small y, just show "18" Oh.
ps -aux
Show All Processes Now
top
command to display the current computer display process, but not all displayed
htop
Show process (very detailed, very bull X)
kill
For example: Kill 9822 kills a process with ID 9822, but if you can't kill it, 1 is not dead! woc! Unexpectedly not die, do not matter, with kill-9 9822 强制杀死
, so, he hung off. This ID can be used ps -aux
for viewing.
reboot
Restart
shutdown -h now
Turn off the machine at once; close the machine shutdown +10
after ten min. shutdown 20:20
20:20 on time
df
Used to view the usage of the system's total drive
du
Used to view the current path usage
ifconfig
Used to display network information and set up networks on the current computer
ping
Ping plus an IP to see the connection condition.
sudo useradd root123 -m
Create a new user (root is a custom user name), which means that -m
after creating a user, create a directory folder with the same name as the user at home
sudo userdel root123
Delete a user named root123
su root
Switch to the root123 user (this is still in the original user's directory). If you su - root
switch to the root user and switch to Root123 's home directory at the same time.
sudo passwd root123
Set the password for the root123 user, or change the user's password
whoami
View the name of the user who logged in to the current operation and display
who
View the names of all logged-in users and show
exit
Exit Current User
ssh [email protected]
The remote connection name is root (user IP is 172.100.2.2), window does not have this command
sudo -s
Enter into the root
Super Admin interface, one thing to note is, do not use su root
this you are not going to go (limited to Linux), do not believe you try Ha (you will not know the password of the hahahah~)
sudo groupadd
Create a user group
sudo delgroup
Delete a user group
cat /etc/passwd
To see if a user was created successfully
cat /etc/group
To see if a user group was created successfully
添加sudo权限给普通用户
Add permissions to the normal user (xxxx) sudo
. Note that, in Linux, if you create a new user group, the default is no sudo
permissions, that is, the new user xxxx
is not able to use sudo -s
this command. So if you want to use this command, you need to give him sudo
permission.
The following is the complete command:
sudo usermod -a -G sudo xxxxsudo usermod -a -G adm xxxx
chgrp xxxx 1.py
Change the user group permissions for the 1.py file of the current user group to xxxx
chown xxxx 1.py
Change the user right of the current 1.py file to xxxx
Modify file permissions (letter method, digital method)
Give me a simple little chestnut bar ~
Now there are 1.py 2.py 3.py three files, modify 1.py user rights to "readable writable executable" then:
chmod u=rwx 1.py
Execution Result:
-rwxrw-r-- 1 python python 0 1月 4 20:29 1.py*
From the above example, we can see that the -rwxrw-r--
user's permissions have been changed, the user group has permissions, and rwx
the permissions of the rw-
other users are r--
. With this example, we can use the same chmon g=rwx
chmod o=r
command to make permission changes. You can also hard-change multiple properties at once, for example:
chmod u=rwx,g=r,o=wx 2.py //可以用逗号进行分割
The method described above is the letter method, which now introduces the digital method:
R for Read (read), W for write (write), X for Execute (EXECUTE)
Read, the permission is binary 100, the decimal is 4; write, the permission is binary 010, the decimal is 2; Execute, the permission is the binary 001, the decimal is 1;
With multiple permissions, the corresponding 4, 2, and 1 are added:
To rwx the 4+2+1=7 to rw-then 4+2=6 to r-x 4+1=5 then = 4 to r--then-wx to 2+1=3 = 2 to-w-= 1 to-----x
In other words, the following code is equivalent:
chmod u=x,g=wx,o=rwx 2.pychmod 137 2.py
Summary
Small summary of Common Linux commands, emmmm, and then sync to the personal blog, refueling ~
Summary of basic Linux commands