Shell daily operations shell Command collection

Source: Internet
Author: User
Tags gz file md5 hash rfc set time time and date rsync

1. Date view modify system time and date

Date

-D

Displays the time of the string description


-F

Show each line of time in the Datefile file


-R

Displays the last modified time of the file


-R

Display time in RFC-2822 compatible date format


-rfc-2822

Display time in RFC-2822 compatible date format


-S

Set Time to String


-U

Display or set to coordinated Universal time format


Using the-D parameter


Current time

# date-d Now

Thu Nov 22:52:45 PST 2013

Next month's time

# date-d ' next Monday '

Mon Nov 00:00:00 PST 2013

Yesterday's time and formatted display

# date-d Yesterday +%y%m%d

20131113


Shows when the file was last modified

# date-r Install.log

Fri SEP 6 11:31:15 PDT 2013


Display the current time and format as year-month-day: minutes: Seconds

Date "+%y-%m-%d%h:%m:%s"


2. grep

Filter blank lines and Comment lines

GREP-V #/etc/swift/object-server.conf |grep-v "^$"

Egrep-v "#|^$" filename


Website PV Statistics

Website PV, ie Page view, site page click Volume

Statistics Day/home/index page hits

grep ' Date +%d/%b/%y ' Access.log | grep "/home/index.html"-C


3, VI

VI Append the contents of the file to other files

: 1,129 w! >>nginx.conf.bak


4, PS

Process troubleshooting with high memory consumption

PS aux | Head-1;ps aux|grep-v pid|sort-rn-k +4|head


5. Find

Find files by directory depth

Find. -name "*.log*"-maxdepth 2-mtime +15-exec ls-l {} \;

Declare

-maxdepth Directory Depth

-atime-n[+n]: Find out the file access time within n days [outside] of the file.

-ctime-n[+n]: Find files where the file change time is within n days [outside].

-mtime-n[+n]: Find the file that modifies the data time within n days [outside].

-amin-n[+n]: Find file access time within n minutes [outside].

-cmin-n[+n]: Find files where the file change time is within n minutes [].

-mmin-n[+n]: Find the file that modifies the data time within n minutes [].


Exclude Directory Lookup files

Find. -path "./20161218"-prune-o-name "*.log*"-print

Declare

-path Pathname-prune: Avoid specifying subdirectories pathname find

-O or

-A and

-not opposite


6. Process

Turn the process into the background:

Ctrl + Z


To transfer a process to the foreground:

Fg


7. Generate a random hexadecimal number, where n is the number of characters:

OpenSSL Rand-hex N


8. Get the MD5 hash of the text:

Echo-n "Text" | Md5sum


9. Compression and decompression

Zip:

Compress the contents of the current directory as Xxx.zip

Zip-r xxx.zip./*


Delete a xxx.txt file in a compressed file

zip-d Xxx.zip Xxx.txt


To add a xxx.txt file to a compressed file

Zip-m Xxx.zip./xxx.txt


Compress multiple files and directories at the same time

Zip-r xxx.zip file1 file2 file3/home/xxx/xxxx


Unzip

Unzip to the specified directory

unzip-d/home/xxxx Xxx.zip


Unzip all txt files to the specified directory

Unzip Xxx.zip *.txt-d/home/xxxx


Remove source files after finding file compression

Find-mtime +3-name "file*" | Xargs ZIP-RM Log.zip


View files within a compressed package

Unzip-v


10. Sed

Sed-s ' s/^m//g ' file to delete spaces in Windows format

Sed ' 2,5d ' file to display files, minus 2-5 lines

Sed '/10[1-4]/d ' file display to remove rows containing 101-104

Sed '/^ *$/d file to delete blank lines in files

Sed-n '/10[1-4]/p ' file only shows rows containing 101-104

Sed ' s/moding/moden/g ' file replaces moding with Moden

Sed-n ' s/^west/north/p ' file replaces the row beginning with West with north and displays

Sed ' s/...$//' file deletes the last three characters of each line

Sed ' s/^...//' file deletes the first three characters of each line

The sed ' s#moding#moden#g ' file replaces the moding with the # after the moden,s to represent the delimiter between the search string and the replacement string

Sed '/101/,/105/s/$/20050119/' file adds "20050119" to the end of rows matching rows from 101 to 105

Sed-e '/^#/!d ' file displays lines that begin with #

Sed-e ' s/://g ' passwd replace file all colons are spaces

-E does not change source file, output to standard output

-I change source file


Character ^m (ctrl-v) for deleting Windows files under Linux

:%s/^m$//g # get rid of ^m at the end of the line

:%s/^m//g # Remove all the ^m

:%s/^m/\r/g # Replace ^m with a carriage return


# sed-e ' s/^m/\n/g ' filename


VI Remove the colon

Sed ' s/://' g '


Change the parameter of enabled in the file from 1 to 0

# sed-i '/enabled/s/1/0/' Iso.repo


11. Delete files with a. log suffix

For i in ' Find-type D | grep./';d o rm $i/*.log;done


12. Batch modification of file suffix

Rename. tar.gz Zip *.tar.gz


13. Swift Daily Commands

/etc/swift> sudo swift-ring-builder account.builder create 18 3 1

/etc/swift> sudo swift-ring-builder container.builder create 18 3 1

/etc/swift> sudo swift-ring-builder object.builder create 18 3 1


/etc/swift> Export zone=1

/etc/swift> Export storage_local_net_ip=192.168.1.101

/etc/swift> Export weight=100

/etc/swift> Export DEVICE=SDB1


Add to


/etc/swift> sudo swift-ring-builder account.builder add z$zone-$STORAGE _local_net_ip:6002/$DEVICE $WEIGHT


/etc/swift> sudo swift-ring-builder container.builder add z$zone-$STORAGE _local_net_ip:6001/$DEVICE $WEIGHT


/etc/swift> sudo swift-ring-builder object.builder add z$zone-$STORAGE _local_net_ip:6000/$DEVICE $WEIGHT


Delete

/etc/swift> sudo swift-ring-builder account.builder remove z$zone-$STORAGE _local_net_ip:6002/$DEVICE $WEIGHT


/etc/swift> sudo swift-ring-builder account.builder remove z1-192.168.1.101:6020


/etc/swift> sudo swift-ring-builder account.builder rebalance


/etc/swift> sudo swift-init proxy start


# Vgdisplay

# lvcreate-n Swiftlv-l 10G vg0

# MKFS.XFS/DEV/MAPPER/VG0-SWIFTLV

# Vi/etc/fstab

/DEV/MAPPER/VG0-SWIFTLV/SRV/NODE/SDB1 xfs noatime,nodiratime,nobarrier,logbufs=8 0 0


# service RSYNCD Start


rsync Rsync://[email protected]


/etc/swift> sudo swift-init all start


Curl-k-v-h ' x-storage-user:system:root '-h ' x-storage-pass:testpass ' https://192.168.1.100:8080/auth/v1.0


Swift-ahttp://192.168.1.100:8090/auth/v1.0-u system:root-k testpass Stat


Swift-ahttp://192.168.1.100:8090/auth/v1.0-u system:root-k Testpass Post Container1


Swift-ahttp://192.168.1.100:8090/auth/v1.0-u system:root-k Testpass Upload container1/etc/swift/*.ring.gz


Swift-ahttp://192.168.1.100:8090/auth/v1.0-u system:root-k Testpass List


After synchronizing all nodes, ensure that the Administrator (Admin) has access to the/etc/swift directory and that all ring's. gz file owners are correct.




Shell daily operations shell Command collection

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.