(1) .ls
Display the files in the current directory pantp
(2).ls -alt
Display the detailed list information of all files (including hidden files starting with .) in the current directory pantp, sorted by time
hostname
(1)hostname
View computer name
(2)hostname –i
View your computer's IP address
.whoami
View currently logged in users
.cp
Copy a file or directory
(1) Copy the file
(2) Copy the directory
.scp
Remotely copy files or directories (copy files or directories from one host to another) I installed a linux system in a virtual machine, I can't take a screenshot of this, only write the syntax, here only from the local machine The copy to the remote host is listed, and the other copy from the remote host to the local machine is not listed;
(1) Copy the file
First switch to the directory where the file that needs to be copied on the machine is located (of course, you can also write an absolute path, or you can write a relative path according to the situation)
scp local file name remote host login username@remote host IP address: the directory of the remote host
Here is a practical example:
(2) Copy the directory
First switch to the upper layer of the directory that needs to be copied on the machine (of course, you can also write an absolute path, or you can write a relative path according to the situation)
scp -r local directory name remote host login username@remote host IP address: the directory of the remote host
.mv
Move files or directories, similar to cutting in Windows systems;
(1) Move files
Move the file old.txt to the dir1 directory
(2) Mobile directory
Move the directory dir3 to the dir1 directory
(3) Rename the file
Name old.txt new.txt
.we
Command Mode, Edit Mode, Bottom Line Mode
Command mode:
Press the esc key to switch to the command line mode, which is commonly used to delete
x deletes the character at the current cursor
dd deletes the current line where the cursor is located
Edit mode:
Press a, i, o to enter edit mode
a The cursor will move back one place and insert after the current cursor
i Insert before the current cursor, the character where the current cursor is will move backward
o Insert after a new line
Now follow the steps below to insert pantp characters separately in the above three ways:
Proceed as follows:
1. Open the file vi new.txt
2. Put the cursor on the second character of the first line, press the letter a, and enter pantp
3. Press esc to switch to command line mode
4. Put the cursor on the second character of the second line, press the letter i, and enter pantp
5. Press esc to switch to command line mode
6. Put the cursor on the second character of the third line, press the letter o, and enter pantp
7. Press esc to switch to command line mode
8. Type: wq to save and exit
The original file content is as follows:
After editing according to the above steps, the content of the file is as follows:
Exit and save
(1) Switch to command line mode
(2): q Exit vi without saving
:wq save and quit vi
:q! Force quit vi without saving
.more
Split-screen display of files, only valid if the file size exceeds a certain length, and percentage information will be displayed after a certain length; otherwise, the effect of this command is similar to cat;
more filename
.cat
Display all the contents of the file, and display all the contents of the file at once;
cat filename
.tail
Display the latest content of a file
(1).tail –f filename
Dynamically display the content of file growth;
(2).tail –1000f filename
Dynamically display the contents of the last 1000 lines of file growth;
.history
(1).history
show all command history
(2).history 2
Show the last two commands
.chmod
Change the file's mode x (execute), w (write), r (read)
There are ten characters in the red part,
The first character indicates whether it is a file or a directory, d is a directory, - is a file
The second, third, and fourth characters represent the read, write, and execute permissions of the user root to which the current file belongs;
The fifth, sixth, and seventh characters represent the read, write, and execute permissions of the user of the group root to which the current file belongs;
The eighth and ninetieth characters represent the read, write, and execute permissions of users in other groups of the current file;
(1).chmod g+x filename
Add w permission to the group user to which the current file of sed.txt belongs;
(2).chmod 777 filename
Add the w permission to the user of the group to which the current file of sed.txt.cp belongs; this is represented by binary, write 1 if there is this permission, write 0 if not, and then calculate the total number;
Before changing:
110 100 100----->6 4 4
needs to be changed to:
110 110 100----->6 6 4
.chown
Change the user and group of the table file or directory; (The linux installed on my virtual machine has only one root user and one root group, I first create a test group, and create a test user under this group, and the password is also test; new; The operations of users and groups are not introduced here, as a developer, such operations are rare)
(1) chown username file name/directory
Change the owner of a file or directory
Change the user of the directory dir1 from root to test
(2). Change the group to which dir1 belongs from root to test
.crontab
crontab is used to allow users to execute programs at a fixed time or at regular intervals;
For the demonstration of the crontab command below, I built an execution script in the pantp directory, crontab.sh
(1). Establish timed execution tasks
I need the crontab.sh script to be executed every minute and output the file to log.txt in the pantp directory
In order to make this effect obvious, I made some changes to the crontab.sh file. The modified file is:
First introduce the format of the schedule in crontab
The format of the schedule is as follows:
f1 f2 f3 f4 f5 program
Where f1 is the minute (0-59), f2 is the hour (0-23), f3 is the day of the month (1-31), f4 is the month (1-12), and f5 is the day of the week Day of the week (0-6 0 means Sunday). program represents the program to be executed. When
f1 is *, it means that the program should be executed every minute, and when f2 is *, it means that the program should be executed every hour, and so on .
When it is ab, it means to execute from the ath to the bth hour, and the rest is analogous.
When f1 is */n, it means that it is executed every n-minute interval, and f2 is */n, which means that it is executed every n-hour interval. Other analogy
When f1 is a, b, c,..., it means a, b, c,... minutes to be executed, and when f2 is a, b, c,..., it means a, b, c ...hours to be executed, the rest and so on;
Enter crontab -e, then enter the following part, after the input is complete, press :wq to exit;
(2). View custom tasks
We can view log.txt to see the running results:
(3) Delete custom tasks
-r delete the current user's crontab file
This is a command to be used with caution. This will delete all custom tasks of the current user. We can directly enter crontab -e, and then delete the unnecessary ones;
.but
Use script to process text files
Replace Abc in both sed.txt and sed.txt.cp with pantp
Before executing the sed command:
(1) The first way: sed -e 's/Abc/pantp/' a.txt
-e means that the command is executed in the form of a command line; the parameter s means that the replacement operation is performed, and the result after execution will be displayed;
Note : In this case, only the result after execution will be displayed, but the file itself has not changed ;
(2) The second case: sed -i 's/Abc/pantp/' a.txt
The parameter -i indicates that the file is modified by direct operation without output, and the file itself has changed ;
.ssh
(1) Log in to a certain machine, log in as the current user by default
(2) Use the specified user to log in to a machine:
.ps
(1) .ps –ef
Through the above command, I usually check whether a process exists. Sometimes I need to kill the process according to the process. At this time, it is used with the kill command. I usually use the kill -3 process number, and this command can generate the core file.
(2).ps –aux
The three options of aux will also be used together, but I won't summarize them here if I don't use them frequently.
.rm
delete files or directories;
rm –rf filename or directory name
.tar
(1) Make a tar package and package the directory a as a.tar
tar –cvf a.tar a
(2) Unzip the tar package and unzip the a.tar package
tar –xvf a.tar
.jar
(1) Package, package the directory a into a.jar
jar –cvf a.jar a
(2) Unzip the package and unzip a.jar
jar –xvf a.jar
(3) View the list of files in the jar package
jar –tvf a.jar
.grep
Only two commonly used options are introduced, c statistic i ignore case
Find the number of occurrences of a character in the file, and count the number of lines in which the character appears. If the character to be found appears more than once in a line, it will only be counted once;
grep -c character filename
.find
Commonly used as follows:
(1) View files and directories in a directory
find system
(2) Match the required file by file name
find path --name matching options
.wc
-l print the number of lines in the current file
-c print the number of bytes in the current file
-w print word count of current file
(1) wc file name
(2) Use with other commands, such as cat
.clear
clear screen;
.pwd
View the current directory;
.his
.Switch to specified user
his – tyjk
.Switch to root user
his
.logout/exit
exit the current dialog;
The shutdown command is generally not used to verify problems in an actual production environment;
Shutdown: shutdown now
Restart: shutdown –r now
reboot
add 2012/09/11
top
The top command is the resource manager in the Linux system, which can display the current CPU, memory usage, remaining amount, etc.
uname
uname -a View the version of the linux system