Linux 101 Hacks 2date,grep,find

Source: Internet
Author: User

Tag: Row ext uses RAS get Jason to manipulate pattern his

It feels so foolish to press the author, I still put the things I feel good

Display the current time in a specific format
The following methods can be used to display the current time in a variety of different formats: $DateThu Jan1  ,: +: atPst the$ Date--Date=" Now"Thu Jan1  ,: -: toPst the$ Date--Date="Today"Thu Jan1  ,: -: APst the$ Date--Date='1970-01-01 00:00:01 UTC +5 hours'+%s18001$ Date '+current Date:%m/%d/%y%ncurrent time:%h:%m:%s'Current Date: on/ on/ theCurrent time : ,: +: A$ Date+"%d-%m-%y" on- on- the$ Date+"%d/%m/%y" on/ on/ the$ Date+"%a,%b%d%Y"thursday,january on  the

The following are the different formatting options for the date command, and each option represents the following meanings:

%d Date (month/day/year)
%d the day of the one month (01..31)
%m Month (01..12)
%y Two bits (00..99) of the year
%a abbreviation for the current language next week (Sun.. Sat)
%A the full spelling of the current language next week (Sunday. Saturday)
%b the abbreviation for the month under the current language (Jan. DEC)
%B the full name of the month under the current language (January). December)
%H 24-hour Hour (00..23)
%I 12-hour Hour (01..12)
%Y year (1970 ...)

Show past date and time

The following methods can be used to display the past date and time:

$ Date--Date='3 seconds ago'Thu Jan1  ,: -:xxPst the$ Date--Date="1 day ago"Wed Dec to  ,: -: -Pst -$ Date--Date="1 days ago"Wed Dec to  ,: -: -Pst -$ Date--Date="1 month ago"Mon Dec1  ,: -: atPst -$ Date--Date="1 ago"Tue Jan1  ,: -: -Pst -$ Date--Date="Yesterday"Wed Dec to  ,: -: thePst -$ Date--Date="ten months 2 day ago"Thu Feb -  ,: -: APst -
Show the future date and time

The following method can be used to show the future date and time:

$DateThu Jan1  ,: -: -Pst the$ Date--Date='3 seconds'Thu Jan1  ,: -: APst the$ Date--Date='4 hours'Thu Jan1  A: -: -Pst the$ Date--Date='Tomorrow'Fri Jan2  ,: -: -Pst the$ Date--Date="1 Day"Fri Jan2  ,: -: toPst the$ Date--Date="1 Days"Fri Jan2  ,: -: -Pst the$ Date--Date="2 Days"Sat Jan3  ,: -: +Pst the$ Date--Date='1 Month'Sun Feb1  ,: -: -Pst the$ Date--Date='1 week'Thu Jan8  ,: -: -Pst the$ Date--Date="2 months"Sun Mar1  ,: -: -Pst the$ Date--Date="2 years"Sat Jan1  ,: to:GenevaPst .$ Date--Date="Next Day"Fri Jan2  ,: to:TenPst the$ Date--Date="-1 days ago"Fri Jan2  ,: to: thePst the$ Date--Date="This Wednesday"Wed Jan7 xx:xx:xxPst the
Grep

No, it's fine.

Syntax: grep [options] pattern [filename]

In the following example, grepfinds all rows containing "John" in the "/etc/password/" file and displays them all

grep john/etc/passwdjsmith:x:1082:1082: John smith:/home/jsmith:/bin/Bashjdoe : x:1083:1083: John Doe:/home/jdoe:/bin/bash

The parameter-V displays all content that does not contain matching text. In the following example, all content that does not contain "John" under "/etc/password" is shown.

Note: In "/etc/grep -v john/etc/passwdjbourne:x:1084:1084 : Jason Bourne:/home/jbourne:/bin/bash
In the following example, it is shown in "/etc/password/grep -C john/etc/passwd2 with -   grep -CV john/etc/passwd

Using "-i", the search will ignore the case

The "-R" can be used to perform the corresponding lookup in all subdirectories. In the following example, the case is ignored in the subdirectory of "/home/users/", Looking for "John", which is displayed as "file name: Matched content". You can also use the parameter "-L" to display only the file name.

grep -ri john/home/users for your contribution. /home/users/name_list.txt:John Smith/home/users/grep -ril John/root/home/ users/subdir1/letter.txt/home/users/name_list.txt
Find command

Syntax: Find path constraint condition

How do I find the file with the specified keyword in the file name?
The following command finds files with "mail" in all filenames under the "/etc" directory.

Find " *mail* "

How do I find files with a file size that exceeds a specified value?
The following command lists all files larger than 100M in the system

Find /-type f-size +100m

How do I find files that have not been modified in recent days?
The following command lists the files that have not been modified in the current directory for the last 60 days

find . -mtime +

How do I find files that have been modified in recent days?

The following command lists the files that have been modified in the current directory in the last 2 days

find . –mtime-2

How do I delete a compressed file that has a. tar.gz extension and is larger than 100M?
When you don't want to accidentally delete a file, be careful when executing the following commands. The best way is to use "ls-l" to perform
The following same command ensures that when you execute the RM command, you know what files are deleted.

Find /-type f-name *. Tar ls -find /-type f-name *. Tar RM -f {} \;

This can be alias.

Alias rm= ' mv--verbose-f--backup=numbered--target-directory/mnt/lustre/asrdata/users/xch27/. Trash '

This way, if you really want to delete, \rm execution, otherwise, will be MV to a folder below, but can not add-rf and other parameters, because MV does not support, haha

How do I archive files that have not been modified in recent days?
The following command finds files that have not been modified in the last 60 days under the "/home/jsmith" directory and is created under "/tmp"
Create an archive that is formatted as "Ddmmyyyy_archive.tar" it doesn't feel like usual, or it will be used more.

Find /home/jsmith-type f-mtime +xargstar -cvf/tmp/"+% D%m%y'_archive. Tar'


A reminder: You can use "Midnight Commander" to do some work on the file, it is the UNIX character bounds
A very powerful file manager on the surface.

Linux 101 Hacks 2date,grep,find

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.