Learn these Linux commands

Source: Internet
Author: User
Tags printable characters
Learn about these Linux commands-general Linux technology-Linux technology and application information. My colleagues spoke about the on-site analysis and post-event analysis of the linux system. I think I still need to be familiar with it. Many commands are not commonly used, but I still need to find help when I use them. It is too troublesome, all of them are listed below.

1. Create a file touch xxx
2. Create a folder named mkdir yyy.
3. Copy cp-ai xxx yyy to copy xxx to the yyy folder, and retain the recursive copy directory of link file attributes.
4. Rename mv-I xxx zzz and rename xxx file/folder to zzz
5. Move the mv-I xxx aaa/Lecture xxx file to the aaa directory.
6. Delete rm-ir yyy to delete the yyy directory and all the files in it.
Rm-I xxx delete a single file
7. Path pwd to know the current directory path
8. ls-c sorts the real files and directories by the modification time.
Ls-u sort by last access
Ls-l detailed information of real files in long format

Drwxr-xr-x 2 root 4096 111
Drwxr-xr-x 2 root 4096 222
Drwxr-xr-x 2 zabbix 4096 bin
Lrwxrwxrwx 1 root 25 mysql. sock-

>/Var/lib/mysql. sock

The information listed in each row is: file type and number of permission links. The file size of the main file group is set up or recently modified.

Time name

For a symbolic link file, the displayed file name is "->" and the Referenced File Path Name.

For device files, the "file size" field shows the master and secondary device numbers, rather than the file size.

The total number of blocks in the directory is displayed at the beginning of the long format list, which contains indirect blocks.

-Rw-r -- 1 root 4221 wgetrc
Drwxr-xr-x 2 root 4096 111

-Common files

D directory

L Symbolic Link

Block B Device Files

C character Device File

The following nine characters indicate the object access permissions. They are divided into three groups, each with three characters.
Drwxr-xr-x
| 1 | 2 | 3 |

The first group indicates the permissions of the file owner, the second group indicates the permissions of users in the same group, and the third group indicates the permissions of other users. Each group

The three characters indicate the read, write, and execute permissions for the file respectively.

The permissions are as follows:

R read

W write

X. For a directory, it indicates the access permission.


9. sort
-U considers the same row after sorting, only one row is retained
-O outputs sorting to a file
-D sort by dictionary
-F case-insensitive letters
-I ignore non-printable characters
-M as the month comparison (Ascending Order)
-R: reverse sorting result
-B. Ignore spaces and tabs.


10. compress the backup tar-cf xxx.tar aaa bbb to compress aaa and bbbto xxx.tar
Tar-tvf xxx.tar columns output all files in xxx.tar
Tar-xf xxx.tar decompress xxx.tar
Tar-rf xxx.tar ccc add ccc to xxx.tar

11. Compress gzip-v aaa bbb ccc and compress aaa bbb cccto aaa.gz bbb.gz ccc.gz.
Gzip-d Extract


12. Change Access Permissions
Chmod u-w, g + w xxx reduces the write permission on the xxx file and adds the write permission for the group users.

U user, g user group, o other user, a owner
+ Add permissions,-minus permissions, = assign permissions to replace previous permissions
R readable, w writable, x executable

Change the 111 file to the root user group in chgrp root 111.

Chown-v root 111: Change the 111 file owner to root and display the modified details.

13. send messages to all users
Wall <file name

Write account tty
Information
Common users cannot use write to send messages to the root user.

14. Shut down the system
Shutdown-r restarts immediately after shutdown
Shutdown-c cancel a running shutdown
Shutdown-r shut at shut down and restart at, and send a warning message like each user
Shutdown + 10 shutdown after 10 minutes

15. view disk Information
Du-a displays the disk usage of all file systems

16. view date
Cal-j month year # displays the day of each day in a given month.

Certificate

To get this certificate, you have to attend the unix-center training. It is a very simple course. You can learn basic linux commands and use the linux Server labs they provide, this is more conducive to memory and understanding. I am using my own ubuntu, which is faster than they are. I learned one afternoon and they have a test with 20 questions, you can get the certificate if the score is over 70 ~~~ I scored 95.5 points, which I learned today. In fact, I know a lot before, that is, I want to consolidate it!

Note: The following commands are applicable to debian and ubuntu systems.

1. ps
(= "Print status" or "process status", print or process status) lists the processes running by the current user.

Ps axu | more

List all processes currently running, including those that are not from the control terminal. the user name is displayed when the user process is displayed.

2. w

Displays the users logged on to the system and checks what they are doing and their processor usage. Is a common security command.

3. last

Displays the last user logged on to the system. It is an excellent idea to run this command frequently as a means of system security detection.

4. history | more

Displays the last (1000) commands executed by the current user in command line mode. The parameter "| more" is paused when the output screen is full. If you want to check what other users are running on your system, log on as the root user and check the file ". bash_history "(yes, this file can be modified and deleted ).

5. top

Continuously list all running processes, sorted by CPU usage (top of the list with high usage ). Press C. Exit.

PID = user ID

USER = USER who starts or owns the process.

PRI = Priority of a process (the higher the value, the lower the priority level. Generally, the process is 0, the highest level is-20, and the lowest level is 20.

NI = optimization level (for example, a process tries to run with a given priority value ). The higher the value, the higher the process optimization level (the lower the priority level)

SIZE = Code loaded into the memory by the process + Data + total number of bytes of the stack (in kilobytes)

RSS = size of physical memory occupied (in kilobytes)

SHARE = memory shared with other processes (in kilobytes)

STAT = Current State of the Process S-sleep, R-running, T-stopped or tracked, D-uninterruptible sleep, and Z-undead Process

% CPU = Percentage of CPU usage (since the last screen update)

% MEM = shared physical memory usage

TIME = cpu time used by the process (since the process was started)

COMMAND = the COMMAND line used to start the task (Be careful with the password and other information displayed in the COMMAND line. users with the permission to run the top COMMAND can see them !)

6. df-h

(= Disk free hard disk space remaining) Output hard disk information of all file systems (in readable mode, h-human readable, human readable)

7. du/-bh | more

(= Disk usuage, hard disk usage) output the actual hard disk usage of each subdirectory under the root directory "/"

8. cat/proc/cpuinfo

CPU information ?? It displays the content of the cpuinfo file. Note that the file is not a real file in the/proc directory ?? They only act as a connection when observing kernel information.

9. cat/proc/interrupts

Displays the interrupt number in use. You may need to check the configuration of a new hardware.

10. Use of scheduled task cron

Use the crontab-e command to modify the settings.

The writing format is as follows:

Minute hour, day month week [user name] command

The first section should be defined as minute, which indicates the minute of every hour for execution. The value range is from 0 to 59.
The second part should be defined as hour, which indicates execution from hour to hour. The value range is from 0 to 23.
The third paragraph should be defined as: date, which indicates execution from the day of each month, range from 1-31
The fourth part should be defined as month, which indicates the number of months of the year to be executed, ranging from 1 to 12.
The fifth part should be defined as Week, which indicates the day of the week for execution, ranging from 0 to 6, where 0 indicates Sunday.
The user name should be defined in each section, that is, the user in which the execution program is to be executed, which can be omitted;
Section 7 should define the commands and parameters to be executed.

Example:

Let the machine restart at 08:30 every morning:

# Reboot OS (this is a comment line, starting)
30 8 * root/sbin/reboot (* indicates all. Three asterisks indicate any date, month, and week, that is, the meaning of each day)

After the modification, restart cron: Use/etc/init. d/cron restart to OK.

Finally, you can use crontab-l to view all scheduled tasks.
Related Article

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.