1. Filter out the known current directoryetcall of the first-level catalogs (not includingetcSubdirectories and hidden directories of directories below directory, only one level directory)
Ls-l | grep ' ^d '
Ls-p | grep '/$ '
Ls-f | grep '/$ '
Find. -maxdepth 1-type D! -name "."
2 , quick return to last working directory
CD-
each time the directory is toggled, the system will save the last working directory to the variable oldpwd in which CD- actually called the oldpwd variables
3 , in a directory, the fastest speed to find the most recently updated files.
Ls-lrt
with R reverse display, put the latest files in the last
4 , find out /data/test/ directory under 7 days before the log file is deleted
Simulation Scenarios
#!/bin/bash
For n in ' seq 14 ':
Do
Date-s "2018/04/$n";
Touch access_www_$ (date +%f). log;
Done
Find/data/test-type F-mtime +7 | Xargs rm-f
Find/data/test-type f-mtime +7-exec rm-f {} \;
5 , debugging system services, you want to see the system log in real time /var/log/messages the update, how to do
Tail-f/var/log/message
Tailf/var/log/message
6 , Print /etc/passwd and displays the file line number
NL/ETC/PASSWD # does not display a space line line number, the same Cat-b
cat-n/etc/passwd # Show All line numbers
vim/etc/passwd Command mode input Set Nu
grep-n./etc/passwd # . represents any single character and does not filter out space lines
Grep-n ". *"/ETC/PASSWD #. * Denotes all characters, can filter out the empty cells
Grep-n "*"/etc/passwd
awk ' {print nr,$0} '/etc/passwd
Less-n/etc/passwd
7 , set up a service to boot from
Chkconfig a service that is actually in rc#.d/ a soft link to the service command is created in the directory. In the script there are assigned start sequence number and stop sequence number
in sshd as an example, note the last line 2345 represents 2345 of the Level next self-starter - is the start sequence number - is the stop sequence number.
you can write a script yourself, format the same, you assign the start number and stop number, cannot be greater than About . Then chkconfig-add sservice_name. You can manage it through chkconfig .
8 , Linu See Chinese garbled, how to solve
Introduction to Character Sets
the character set is simply a set of text symbols and their encoding. Each country has a different character set for expressing its own language. The United States is the ASCII code, China is GBK23, in order to unify the character set standard, appeared the integration each country's character set UTF-8
1. Temporary entry into force
Export lang= "ZH_CN. UTF-8 "
2. Permanent entry into force
Echo ' lang= ' ZH_CN. UTF-8 "' >/etc/sysconfig/i18n
source/etc/sysconfig/i18n
9 , the practice of packing commands
1, with Tar Packing / etc Entire directory (packaged and compressed)
TAR-ZCVF etc.tar.gz/etc
2, with Tar Packing / etc Entire directory (packaged and compressed, but need to be excluded /etc/services files)
TAR-ZCVF etc.tar.gz/etc --exclude=/etc/services
3, the 1) Click the command to unzip the package to /data/test directory under
TAR-XVF etc.tar.gz-c/data/test/
4, will /data/test under the all . txt File Packaging
Find/data/test-type f-name "*.txt" | Xargs Tar zcvf txt.tar.gz
Ten , known Test.txt the content is "I am Cbl,myphone is 12345678"
1, filter out the file " CBL "and" 12345678 the string
Awk-f "[,]+" ' {print $3,$7} ' test.txt
Cut-c 6-8,20-test.txt
2, filter out the file " cbl,12345678 the string
Awk-f "[,]+" ' {print $], ' $7} ' test.txt
Linux Exercises-2 basic commands