Daily operation and maintenance shell command collection

1. date View and modify the system time and date

date:

-d

Display the time described by the string


-f

Display the time of each row in the DATEFILE file


-r

Displays the last modification time of a file


-R

Display time in RFC-2822 compatible date format


-rfc-2822

Display time in RFC-2822 compatible date format


-s

set time as string


-u

Display or set to Coordinated Universal Time time format


Use the -d parameter


current time

# date -d now

Thu Nov 14 22:52:45 PST 2013

 

time of next month

# date -d 'next monday'

Mon Nov 18 00:00:00 PST 2013

  

Yesterday's time and formatted display

# date -d yesterday +%Y%m%d

20131113


Displays when the file was last modified

# date -r install.log

Fri Sep 6 11:31:15 PDT 2013


Displays the current time formatted as year-month-day hour:minute:second

date "+%Y-%m-%d %H:%M:%S"


2、grep

Filter blank and commented lines

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

egrep -v "#|^$" filename


Website PV Statistics

Website PV, that is, Page view, website page hits

Count the number of hits on the /home/index page on the day

grep `date +%d/%b/%Y` access.log | grep "/home/index.html" -c


3 、 vi

Append file contents to other files under vi

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


4、ps

Troubleshooting processes with high memory usage

ps to | 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 files with file access times within [outside] n days.

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

-mtime -n[+n]: Find files with modified data time within [outside] n days.

-amin -n[+n]: Find files with file access times within [outside] n minutes.

-cmin -n[+n]: Find files whose change time is within [outside] n minutes.

-mmin -n[+n]: Find files with modified data within [outside] n minutes.


Exclude directories from looking for files

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

declare:

-path pathname -prune: avoid the specified subdirectory pathname search

-o or

-a and

-not instead


6. Process

Let the process go to the background:

Ctrl + z


Bring the process to the foreground:

fg


7. Generate random hexadecimal numbers, 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 to xxx.zip

zip -r xxx.zip ./*


Delete the xxx.txt file in the compressed file

zip -d xxx.zip xxx.txt


Add the xxx.txt file to the 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 out file compression

find -mtime +3 -name "file*"| xargs zip -rm log.zip 


View the files in the compressed package

unzip-v


10、sed

sed -s 's/^M//g' file delete the spaces in the windows format in the file

sed '2,5d' file display file file, remove 2-5 lines

sed '/10[1-4]/d' file shows the lines containing 101-104 are removed

sed '/^ *$/d file delete empty lines in file

sed -n '/10[1-4]/p' file only shows the lines containing 101-104 in the file file

sed 's/moding/moden/g' file replaces moding with moden

sed -n 's/^west/north/p' file replace the line starting with west with north and display it

sed 's/...$//' file delete the last three characters of each line

sed 's/^...//' file delete the first three characters of each line

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

sed'/101/,/105/s/$/ 20050119/' file will add "20050119" to the end of the line from the matching line of 101 to the end of the matching line of 105

sed -e '/^#/!d' file show lines starting with #

sed -e 's/:/ /g' passwd replace all colons in the file with spaces

-e does not change the source file, output to standard output

-i change source file


Delete the character ^M (ctrl-v) of the windows file under linux

:%s/^M$//g # remove the ^M at the end of the line

:%s/^M//g # remove all ^M

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


# sed -e ‘s/^M/\n/g’filename


Remove the colon from vi

but 's/'g`


Change the enabled parameter in the file from 1 to 0

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


11. Delete files with .log suffix

for i in `find -type d | grep ./`;do rm $i/*.log;done


12. Batch modify 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, make sure that the /etc/swift directory is accessible to the admin (admin) and that all ring .gz files have the correct owner.




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325233491&siteId=291194637