Linux several common commands

Source: Internet
Author: User
Tags exit in syslog disk usage

1. Mount the USB drive under Linux

If you want Linux to identify the U disk, you need to locate the mouse first in the virtual machine's Linux, and then insert the USB stick, the USB drive will be recognized by Linux, and then use fdisk-l to view the situation of the U disk.

/DEV/SDA1 * 1 6 48163+ Linux

/DEV/SDA2 7 515 4088542+ Linux

/dev/sda3 516 776 2096482+, Linux Swap/solaris

/DEV/SDA4 777 2610 14731605 5 Extended

/DEV/SDA5 777 2610 14731573+-up Linux


disk/dev/sdb:7985 MB, 7985954816 bytes

231 heads, Sectors/track, 2411 cylinders

Units = Cylinders of 6468 * 3311616 bytes


Device Boot Start End Blocks Id System

/DEV/SDB1 2 2412 7794688 b W95 FAT32

If it is a fat-formatted USB flash drive, Mount command: Mount-t vfat/dev/sdb1/mnt/udisk

If it is an NTFS-formatted USB flash drive, mount the command: mount-t ntfs-3g/dev/sdb1/mnt/udisk

If you do not have a/mnt/udisk folder, you can create a

Mkdir/mnt/udisk

Can ~

However, note that the NTFS format to be mounted, you need to download a ntfs-3g-2011.4.12-5.el5.i386.rpm package, install the ~

Baidu This package name, go to csdn download ...


View file and folder sizes under 2.Linux

When the size of the disk exceeds the standard, there will be alarm prompts, if you know the DF and du command is a very wise choice.


DF can view the first-level folder size, usage scale, file system and its hang-in points, but there is nothing to file.

Du can view the size of files and folders.


It works well with both. For example, use DF to see which level of directory is too large, and then use DF to see the size of the folder or file, so you can quickly determine the crux of the problem.


The following is a brief introduction

The DF command can show the available space and usage for all current file systems, as shown in the following example:


Here is the code snippet:


[Yayug@yayu ~]$ Df-h

Filesystem Size used Avail use% mounted on

/DEV/SDA1 3.9G 300M 3.4G 8%/

/dev/sda7 100G 188M 95G 1%/data0

/DEV/SDB1 133G 80G 47G 64%/data1

/dev/sda6 7.8G 218M 7.2G 3%/var

/dev/sda5 7.8G 166M 7.2G 3%/tmp

/dev/sda3 9.7G 2.5G 6.8G 27%/usr

Tmpfs 2.0G 0 2.0G 0%/dev/shm


The parameter-H indicates the use of the "human-readable" output, that is, in the file system size using GB, MB and other easy-to-read format.


The first field (Filesystem) and the last field (mounted on) of the above command output are the file system and its hang-in points respectively. We can see that this partition of/DEV/SDA1 is hung in the root directory.


The next four fields size, used, Avail, and use% are the partition's capacity, the size used, the remaining size, and the percentage used. Under FreeBSD, when the hard disk is full, you may see that the percentage used is more than 100%, because FreeBSD leaves some room for root, allowing Root to be managed when the file system is full, or can write something to the file system.


Du: Querying disk usage space for a file or folder


If you have a lot of files and folders under the current directory, you can cycle through the space used by all files and folders using the command without the parameter Du. This is not good to see if it is too large, so you have to specify the number of layers in the depth directory, parameter:--max-depth=, this is a very useful parameter! As follows, note that using "*", you can get the space size of the file.


Reminder: Always command more complex than Linux FreeBSD, its du command specifies the depth of the directory layer is more simplified than Linux, the-D.


Here is the code snippet:


[Email protected] yayu]# du-h--max-depth=1 work/testing

27M Work/testing/logs

35M work/testing


[Email protected] yayu]# du-h--max-depth=1 work/testing/*

8.0K work/testing/func.php

27M Work/testing/logs

8.1M Work/testing/nohup.out

8.0K work/testing/testing_c.php

12K work/testing/testing_func_reg.php

8.0K work/testing/testing_get.php

8.0K work/testing/testing_g.php

8.0K work/testing/var.php


[Email protected] yayu]# du-h--max-depth=1 work/testing/logs/

27M work/testing/logs/


[Email protected] yayu]# du-h--max-depth=1 work/testing/logs/*

24K Work/testing/logs/errdate.log_show.log

8.0K Work/testing/logs/pertime_show.log

27M Work/testing/logs/show.log


It's worth noting that you see an article on the similarities and differences between the Du and DF commands: the du DF difference causes file system false positives to resolve.


Du statistics File size addition

DF Statistics block usage


If a process opens a large file, the large file is dropped directly by RM or MV, then du updates the statistics, DF does not update the statistics, or the space is not released. Until the process of opening the large file was killed.


As a result, if you delete the file below/var/spool/clientmqueue periodically, the space is not released until you kill the process.


After you kill the process using the following command, the system resumes.

Fuser-u/var/spool/clientmqueue


http://www.yayu.org/look.php?id=162



View the size of the Linux file directory and the number of files that the folder contains


Total statistics Size

Du-sh xmldb/

DU-SM * | Sort-n//Statistics current directory size and size sorting

Du-sk * | Sort-n

Du-sk * | grep GUOJF//Look at the size of a person

du-m | Cut-d "/"-F 2//See text before second/character


See how many files are in this folder/*/*/* how many files are there?

Du xmldb/

Du xmldb/*/*/* |wc-l

40752


Explain:

WC [-LMW]


Parameter description:

-L: How many lines

-M: How many characters

-W: how many words


Http://linux.chinaitlab.com/command/734706.html



3. Real-time view of logs under Linux

Cat/var/log/*.log

If the log is updated, how to view tail-f in real time/var/log/messages

You can also use watch-d-N 1 cat/var/log/messages

-d means highlighting different places, and-n indicates how many seconds are refreshed.

This instruction does not return directly to the command line, but rather to print the new additions in the log file in real time, a feature that is very effective for viewing logs. If you want to terminate the output, press CTRL + C.

In a Linux system, there are three main log subsystems:

Connection time Log-executed by multiple programs, writes records to/VAR/LOG/WTMP and/var/run/utmp,login and other programs to update wtmp and utmp files, enabling system administrators to track who is logged on to the system.

Process statistics-performed by the system kernel. When a process terminates, write a record for each process toward the process statistics file (PACCT or acct). The purpose of process statistics is to provide command usage statistics for basic services in the system.

Error log-executed by SYSLOGD (8). Various system daemons, user programs, and cores report noteworthy events to file/var/log/messages through Syslog (3). There are also many UNIX programs that create logs. Servers that provide network services, such as HTTP and FTP, also maintain detailed logs.


The usual log files are as follows:

Transmission of Access-log Record Http/web


Acct/pacct Record User Commands


Activities of the Aculog record modem


Btmp record of failed records


Lastlog records the most recent successful logon events and the last unsuccessful login


Messages log information from syslog (some linked to syslog file) after system startup and error log, which is one of the most commonly used logs in red Hat Linux


Sudolog record commands with sudo


Use of the Sulog record using the SU command


Syslog logs information from a syslog (usually linked to a messages file)


Utmp record each user who is currently logged on


Wtmp a user's permanent record of each login entry and exit time


Xferlog Record FTP session

/var/log/secure Security-related log information

/var/log/maillog message-related log information

/var/log/cron log information related to timed tasks

/var/log/spooler log information related to UUCP and news devices

/var/log/boot.log Daemon starts and stops related log messages

Utmp, wtmp, and lastlog log files are the key to most reuse of the UNIX log subsystem-keeping the log entry and exit records for the user. Information about the currently logged-on user is recorded in the file utmp, the login entry and exit record is in the file Wtmp, and the last login file can be viewed with the Lastlog command. Data exchange, shutdown, and restart are also recorded in the Wtmp file. All records contain timestamps. These files (usually not lastlog) grow very quickly in systems with a large number of users. For example, wtmp files can grow indefinitely unless intercepted on a regular basis. Many systems configure WTMP to be recycled in a single day or week. It is usually modified by a script run by Cron. These scripts are renamed and recycled using the Wtmp file. Typically, Wtmp is named WTMP.1 at the end of the first day, and then wtmp.1 into WTMP.2 and so on until WTMP.7.


Each time a user logs in, the login program looks at the user's UID in the file Lastlog. If found, the user's last login, exit time, and host name are written to standard output, and the login program records the new logon time in Lastlog. After the new Lastlog record is written, the Utmp file is opened and inserted into the user's utmp record. This record is always deleted when the user logs on and exits. utmp files are used by various command files, including who, W, users, and finger.


Next, the login program opens the file wtmp additional user's utmp record. When the user logs on and exits, the same utmp record with the update timestamp is appended to the file. The Wtmp file is used by the program last and AC.


Specific commands

Wtmp and utmp files are binary files and they cannot be clipped or merged (using the Cat command) such as the tail command. Users need to use who, W, users, last, and AC to use the information contained in these two files.


The who:who command queries the utmp file and reports each user who is currently logged on. The WHO default output includes the user name, terminal type, logon date, and remote host. Example: Who (carriage return) shows


Chyang pts/0 18 15:06

Ynguo PTS/2 18 15:32

Ynguo PTS/3 18 13:55

Lewis PTS/4 18 13:35

Ynguo PTS/7 18 14:12

Ylou PTS/8 18 14:15


If the wtmp file name is indicated, the WHO command queries all previous records. Command who/var/log/wtmp will report every login since the Wtmp file was created or hacked.

The w:w command queries the utmp file and displays information about each user in the current system and the process it is running. For example: W (carriage return) display: 3:36pm up 1 day, 22:34, 6 users, load average:0.23, 0.29, 0.27.

USER TTY from [email protected] IDLE jcpu PCPU

Chyang pts/0 202.38.68.242 3:06pm 2:04 0.08s 0.04s-bash

Ynguo pts/2 202.38.79.47 3:32pm 0.00s 0.14s 0.05 W

Lewis Pts/3 202.38.64.233 1:55pm 30:39 0.27s 0.22s-bash

Lewis Pts/4 202.38.64.233 1:35pm 6.00s 4.03s 0.01s sh/home/users/

Ynguo PTS/7 simba.nic.ustc.e 2:12pm 0.00s 0.47s 0.24s telnet Mail

Ylou pts/8 202.38.64.235 2:15pm 1:09m 0.10s 0.04s-bash


Users:users prints the currently logged-on user with a separate line, with each user name displayed with a login session. If a user has more than one logon session, his user name displays the same number of times. For example: Users (Enter) display: Chyang Lewis Lewis Ylou Ynguo Ynguo


The last:last command searches back wtmp to display the user who has logged in since the file was first created. For example:

Chyang PTS/9 202.38.68.242 Tue 1 08:34-11:23 (02:49)

Cfan PTS/6 202.38.64.224 Tue 1 08:33-08:48 (00:14)

Chyang PTS/4 202.38.68.242 Tue 1 08:32-12:13 (03:40)

Lewis Pts/3 202.38.64.233 Tue 1 08:06-11:09 (03:03)

Lewis Pts/2 202.38.64.233 Tue 1 07:56-11:09 (03:12)


If the user is indicated, then last only reports the user's recent activity, for example: last Ynguo (carriage return) display:

Ynguo PTS/4 SIMBA.NIC.USTC.E Fri 4 16:50-08:20 (15:30)

Ynguo PTS/4 SIMBA.NIC.USTC.E Thu 3 23:55-04:40 (04:44)

Ynguo PTS/11 SIMBA.NIC.USTC.E Thu 3 20:45-22:02 (01:16)

Ynguo pts/0 SIMBA.NIC.USTC.E Thu 3 03:17-05:42 (02:25)

Ynguo pts/0 SIMBA.NIC.USTC.E Wed 2 01:04-03:16 1+02:12)

Ynguo pts/0 SIMBA.NIC.USTC.E Wed 2 00:43-00:54 (00:11)

Ynguo PTS/9 SIMBA.NIC.USTC.E Thu 1 20:30-21:26 (00:55)


The AC:AC command reports the time of the user's connection (in hours) based on the login entry and exit in the current/var/log/wtmp file, and reports the total time if the flag is not used. Example: AC (return) display: Total 5177.47

ac-d (carriage return) displays the total link time of the day

261.87 Total

Total 351.39

Total 396.09

Total 462.63

270.45 Total

Total 104.29

Today Total 179.00


Ac-p (carriage return) shows the total connection time for each user

Ynguo 193.23

Yucao 3.35

Rong 133.40

Hdai 10.52

Zjzhu 52.87

Zqzhou 13.14

Liangliu 24.34

Total 5178.22


The Lastlog:lastlog file is queried each time a user logs on. You can use the Lastlog command to check the last logon time for a particular user and format the output of the last logon log/var/log/lastlog. It displays the login name, port number (TTY), and last logon time based on the UID sort. If a user has never logged in, Lastlog displays "**never logged**. Note that you need to run the command as root, for example:


Rong 5 202.38.64.187 Fri 18 15:57:01 +0800 2000

DBB **never logged in**

Xinchen **never logged in**

pb9511 **never logged in**

Xchen 0 202.38.64.190 Sun 13 10:01:22 +0800 2000



In addition, a number of parameters can be added, for example, Lastlog-u 102 will report a UID of 102 users; Lastlog-t 7 means limiting the previous week's report.



4. View the number of files in a folder

Command 1:find-type f-o-type s-o-type p-o-type D |wc-l

Command 2:ls-al|grep ' ^-' |wc-l

Command 3:find-type F |wc-l


Linux several common commands

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.