CentOS Next LS grep head cut simple usage

Source: Internet
Author: User

Requirements: View the recent modification times for files in a directory.

View the files in the/proc directory and sort by time to intercept the top five files that were recently modified:

Go to the/proc directory
[Email protected]_web_006031 ~]# cd/proc/

View all files and directories under the directory
[[email protected]_web_006031 proc]# LS
1 16763 2342-26940 (589) 756 BU s execdomains kallsyms mdstat sched_debug sysrq-trigger Xen
Ten 16765 2351 260 26941 3 PNs, 924 cgroups FB kcore meminfo schedstat sysvipc zoneinfo
109 16766 2 2352 261 26942 523 6 692 774 926 cmdline filesystems K Eys Misc SCSI timer_list
16785 2618 26943 7 3817 928 FS Cpuinfo key-users self modules ATS
16786 20138 241 2619 26946 All-in-all-in-all-930-crypto interrupts kmsg mounts Slabinfo TTY
13 16787 21 24 3 26904 26947 4 793 931 devices Iomem Kpagecount MTD Softirqs uptime
14 16842 22 25 26925 27 335 40 49 5 6 738 8 933 diskstats ioports kpageflags net stat version
16857 2521 26938 5 2736 896 DMA I PMI loadavg pagetypeinfo swaps vmallocinfo
9 2341 2522 26939 (+ buddyinfo driver IRQ Locks part Itions SYS vmstat

Filter out the directory and intercept the 5 most recently modified files.
[Email protected]_web_006031 proc]# ls-lut |grep "^-" |head-5
-r--r--r--1 root root 0 Oct 11:27 buddyinfo
-r--r--r--1 root root 0 Oct 11:27 cgroups
-r--r--r--1 root root 0 Oct 11:27 cmdline
-r--r--r--1 root root 0 Oct 11:27 cpuinfo
-r--r--r--1 root root 0 Oct 11:27 Crypto

Use the Cut command to intercept how much is displayed. (For example: 5 is the beginning of the 5th character display)
[Email protected]_web_006031 proc]# ls-lut |grep "^-" |head-5 |cut-c5-
r--r--1 root root 0 Oct 11:28 cgroups
r--r--1 root root 0 Oct 11:28 execdomains
r--r--1 root root 0 Oct 11:28 fb
r--r--1 root root 0 Oct 11:28 Iomem
r--r--1 root root 0 Oct 11:28 ioports
[[Email protected]_web_006031 proc]#

Ls-t sorting according to the modified time of the file
Ls-u can show the last access time of a file and let-t sort by access time
^-is a regular expression that begins with a bar, which represents a normal file
CUT-C specifies that the cut command retains and outputs those characters

The following is a cross bar-specifying a range, and you can also use commas to specify the range

Scope description
n Nth Character
N-N characters selector until the current line ends
N-m from nth character selector to first M characters
-M from the first word selector until the M character

CentOS Next LS grep head cut simple usage

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.