Some Linux commands and analysis

(1) .ls

Display the files in the current directory pantp

image

(2).ls -alt

Display the detailed list information of all files (including hidden files starting with .) in the current directory pantp, sorted by time

image

 

hostname

(1)hostname

View computer name

image

(2)hostname –i

View your computer's IP address

image

.whoami

View currently logged in users

image

.cp

Copy a file or directory

(1) Copy the file

image

(2) Copy the directory

image

.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:

image

(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

image

.mv

Move files or directories, similar to cutting in Windows systems;

(1) Move files

Move the file old.txt to the dir1 directory

image

(2) Mobile directory

Move the directory dir3 to the dir1 directory

image

(3) Rename the file

Name old.txt new.txt

image

.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:

image

After editing according to the above steps, the content of the file is as follows:

image

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

image

(2).history 2

Show the last two commands

image

.chmod

Change the file's mode x (execute), w (write), r (read)

Sogou screenshot_2012-07-10_09-49-59

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;

Sogou screenshot_2012-07-10_09-57-25

 

(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

Sogou screenshot_2012-07-10_10-03-52

.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)

image

(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

Sogou screenshot_2012-07-10_18-58-25

(2). Change the group to which dir1 belongs from root to test

Sogou screenshot_2012-07-10_19-39-41

.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

image

(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:

image

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;

image

(2). View custom tasks

image

 

We can view log.txt to see the running results:

image

(3) Delete custom tasks

-r delete the current user's crontab file

image

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:

image

(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;

image

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 ;

image

.ssh

(1) Log in to a certain machine, log in as the current user by default

image

(2) Use the specified user to log in to a machine:

Sogou screenshot_2012-07-10_21-09-46

.ps

(1) .ps –ef

ps

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

image

.find

Commonly used as follows:

(1) View files and directories in a directory

find system

image

(2) Match the required file by file name

find path --name matching options

image

.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

image

(2) Use with other commands, such as cat

image

.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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326370728&siteId=291194637