my linux FAQ

my linux FAQ

  1. Use commands to query whether the system is 32-bit or 64-bit getconf LONG_BIT or getconf WORD_BIT For example: [root@sy02/]# getconf LONG_BIT 64 file command For example: [root@sy02/]# file/bin/ls/bin/ls: ELF 64 -bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), stripped
  2. View the file in Mb mode ls -lh
  3. Filter the displayed files, such as displaying only the xml end files: ls *.xml
  4. Check the remaining space of the disk: df -hl
  5. Download files to the local in ssh: session sftp tab option sets the local destination path sz filename.filetype
  6. Copy files between two servers scp -P 2188 user@ip:/path/file.
  7. Clear the file: true> des.txt
  8. svn submits the file: svn -m "message" filename does not write "-m". The message cannot be submitted, and it is a good habit to add message!
  9. The tar command decompresses the file: tar xzvf this.tar.gz "tar xzvf this.tar.gz ./" The online information of this command says that it is unzipped to this directory after testing.
  10. Create file command touch filename
  11. The problem of inconsistency between Windows and linux line breaks The line break under Linux is/n, while under Windows it is/r\n. Without processing, the two files will have problems when displayed. For example, a Linux text file will not wrap when opened with Windows Notepad. The format is messy. If a Windows file is opened with VI under Linux, it will appear^ M characters, etc. Solution: Use CMD under Linux: dos2unix and unix2dos dos2unix/unix2dos are included in the Tofrodos installation package DOS text files traditionally have CR/LF (carriage return/line feed) pairs as their new line delimiters while Unix text files traditionally have LFs (line feeds) to terminate each line. Tofrodos comprises one program, "fromdos" alias "todos", which converts text files to and from these formats. Use "fromdos" to convert DOS text files to the Unix format, and "todos" to convert Unix text files to the DOS format. This functionality is also available via the dos2unix/unix2dos symlinks. Install dos2unix/unix2dos under UBUNTU: $ sudo apt-get install tofrodos
  12. Alias ​​in the alias directory for easy access to vi ~/.bashrc alias scserver="cd/usr/local/netqin/boss/netqin/BOSS_SC_SERVICE/trunk/src" Only valid for a certain user when re-entering ssh
  13. View the total number of files in the current directory: ls -l |grep "^-"|wc -l
  14. In vi jump, the "home" and "end" keys do not work. To the end of a line: "$" command to the beginning of a line: "0" The command to scroll the whole screen forward is CTRL-F (minus two Row). The reverse command is CTRL-B.
  15. vi delete multiple lines: ndd delete n lines starting with the current line
  16. When deleting a large number of files in Linux, directly using rm will cause the error: -bash:/bin/rm: parameter list is too long. At this time, the find command can be used in combination. Example: 1. Change rm * -rf to: find. -Name "*" | xargs rm -rf'*' will do. 2. Change rm test* -rf to: find. -Name "test*" | xargs rm -rf "test*"
  17. Remotely log in to other servers ssh -p 2188 username@ip
  18. Zombie process removal method kill -18 PPID (PPID is its parent process) This signal tells the parent process that the child process has died, please take back the resources allocated to him.
  19. Find a string in a file grep -n "str" ​​-r ./This is to find all files containing str strings in the current directory and subdirectories under its jurisdiction grep -R abc * in this directory and all its subdirectories Find the string abc in the file under
  20. Linux system manually install the rz sz software package wget http://freeware.sgi.com/source/rzsz/rzsz-3.48.tar.gz tar zxvf rzsz-3.48.tar.gz install cd rzsz-3.48 modify the fourth line of the Makefile OFLAG = -O is OFLAG = -O -DREGISTERED make posix (make and several configuration options generally use posix) cp rz sz/usr/bin/.
  21. Linux file cutting split -b 10m filename.txt m must be lowercase cut to 10m for each file
  22. View the program to open the file server tmp directory disk is full, directly emptying or deleting the file is invalid, the space still cannot be released, you need to view the file occupied by the program with the root user's lsof command, find the program, kill it and restart it. lsof (list open files) is a tool that lists open files on the current system. In the Linux environment, everything exists in the form of files. Through files, you can access not only regular data, but also network connections and hardware. Enter lsof in the terminal to display the files opened by the system. Because lsof needs to access the core memory and various files, it must be run as the root user to fully utilize its functions.
  23. Secure CRT rz upload file error problem The size of the file uploaded by rz is wrong with the local file. After uploading the file at 10M, only 343bytes is left. Later, it was discovered that the upload file as ascii was accidentally checked in the rz dialog box. After removing it, it was normal.
  24. Install Net::SNMP 1) By CPAN (best) on command line, as root: [your_host]# perl -MCPAN -e shell cpan shell - CPAN exploration and modules installation (v1.76) ReadLine support enabled cpan> install Net ::SNMP
  25. ulimit modify the maximum number of open files Linux has a default ulimit limit for users, and this file can configure the user's hard configuration and soft configuration, and the hard configuration is an upper limit. Modifications that exceed the upper limit will cause errors such as "operation not permitted". In/etc/security/limits.conf, add * soft noproc 10240 * hard noproc 10240 * soft nofile 10240 * hard nofile 10240 If nginx is used, it is best to adjust the following configuration
  26. Load analysis uses ps faux to view the current process status R-Running S-Sleeping D-Waiting for something If a process is D for a long time, it means that there may be a problem with the process, causing other process requests to be in a waiting state, and the system load will increase sharply (Http://www.andymillar.co.uk/blog/2006/12/24/linux-load-average-explained/)
  27. Change the owner of the file chown username somefile chown -R username somedir (directory and subfiles) chown username:usergroup somefile
  28. linux timestamp http://tool.chinaz.com/Tools/unixtime.aspx
  29. How to decompress files in batches in linux-find -maxdepth 1 -name "*.bz2"|xargs -i tar xvjf {} 
  30. One line of code counts the number of lines of code in the directory find. -Name "*.java" | xargs wc -l
  31. Add route/sbin/route add -net 10.74.0.109 netmask 255.255.255.255 gw 172.16.54.1 (the machine that needs to be added) (the gateway of the machine)/sbin/route You can view the routing table
  32. The location of crontab is CentOS as an example, its real location is:/var/spool/cron
  33. curl shows the connection time curl -o/dev/null -s -w'%{time_total}' http://www.miotour.com
  34. Save the sql running results in MySQL to a file. Method 1: Use tee mysql> tee output.txt Logging to file'output.txt' mysql> notee Outfile disabled. Method 2: Use the mysql command line tool- -tee parameter $mysql --tee=ot.txt Logging to file'ot.txt' mysql> This time, all input and output will be logged to the specified file (until exit). If you specify a file that already exists, the result will be appended to the file.
  35. Delete logs more than three days old find. -name "*.log.*" -mtime +3|xargs rm -rf
  36. ssh passwordless connection from A without password access to B, then generate ssh-keygen -t rsa -P'' -f/root/.ssh/id_dsa on A and append to B's/root/.ssh/iauthorized_keys, you need to open/etc/ssh/sshd_config: PubkeyAuthentication yes AllowUsers root AuthorizedKeysFile .ssh/authorized_keys
  37. linux java installation http://lelong.iteye.com/blog/349549   settings. bashrc does not work, you need to set/etc/profile export JAVA_HOME=/root/jre1.6.0_31/export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar and source/etc/profile
  38. nc use http://www.huanxiangwu.com/477/linux-nc-netcat  detailed explanation 1. chat function host nc -l 1234 client nc $ip 1234 pay attention to the version, some need to add the parameter -lp 2. telnet redis and Add the command echo -e "get test/r\n" | nc localhost 6379 redis must add "\r\n" echo needs to add the parameter -e, recognize the backslash 3. telnet memcache and add the command printf "set zhangyan 0 0 5\r\n12345\r\n" | nc 127.0.0.1 11211 printf "get zhangyan\r\n" | nc 127.0.0.1 11211 incr decr delete Similar from:  http://blog.s135.com/post/384/
  39. Mac vim for python settings need to install ctags gcc, gcc is best to use the pkg version (mine is lion os), various problems with tar packaging and must be compiled with python to have the auto-completion function mvim ctags needs to be set after installation Go to vimrc, otherwise the member list cannot be generated. Various problems (ctags: illegal option) let Tlist_Ctags_Cmd ='/usr/local/bin/ctags' Switch between left and right windows Ctrl+ww More shortcuts  http://www.clovery.org/tree-explorer-plugin-nerdtree-for-vim.html ctrl+x followed by ctrl+o shows the code completion function vim python   http://blog.dispatched.ch/2009/05/24/vim-as-python -ide/
  40. mysql int bigint范围 INT[(M)] [UNSIGNED] [ZEROFILL] A normal-size integer. The signed range is  -2147483648 to  2147483647. The unsigned range is  0 to  4294967295.  A large integer. The signed range is   to  . The unsigned range is   to  . The project generation id range setting is small, and the parseInt method is used to parse, resulting in more 2147483647 is an error, and the parsing method is changed to parseLong, but there are still hidden dangers. The type of the database is set to INT instead of BIGINT. If it exceeds, it cannot be generated. BIGINT[(M)] [UNSIGNED] [ZEROFILL]-92233720368547758089223372036854775807018446744073709551615
  41.  linux install python mysqldb error: command'gcc' failed with exit status 1 yum install gcc python-devel
  42. libz.a: could not read symbols: Bad value libz.a(compress.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC Try multiple methods A Set extra_link_args+=['-fPIC'] in setup_posix.py, to no avail, reinstalled zlib and set  extra_link_args+=['--with-zlib-dir=/usr/zlib'] to no avail, but it was finally found that it was first the use mysql integrated zlib, behind the cover option and install it directly to/home/work/mysql/lib/mysql , and then compile the installation, and finally succeeded.
  43. Create a new folder in the mac/home directory. sudo vim/etc/auto_master Comment out the home line and restart it. If you don’t restart, only execute sudo automount. The test on this machine is invalid.
  44. Milliseconds to time, time to milliseconds to milliseconds to time date -d @1402287199 +"%Y-%m-%d" Time to milliseconds: D="20140601235958" date +%s -d "${D:0: 8} ${D:8:2}:${D:10:2}:${D:12:2}" the current millisecond to the date date +"%Y-%m-%d" | date "+% Y-%m-%d" http://blog.csdn.net/jk110333/article/details/8590746
  45. Read the file and split each line according to ";"#!/bin/bash lines=`cat files.txt` cat parser_tables.txt | (while read parser_table; do echo $parser_table >> info.log parser=`echo $parser_table | cut -d/; -f 1` table=`echo $parser_table | cut -d/; -f 2` echo $parser echo $table for line in $lines do echo $line >> info.log done done)
  46. Batch replace the strings in multiple files sed -i "s/size/sun/month/g" `grep size -rl/usr/aa`
  47. Linux split file by line split -l 300 large_file.txt new_file_prefix
  48.  Edit the iptables port to set up a firewall in Linux, take CentOS as an example, open the iptables configuration file:
    1. vi/etc/sysconfig/iptables  

    Use the/etc/init.d/iptables status command to query whether port 80 is open. If not, you can deal with it in two ways: 1. Command line iptables -A INPUT -m state --state NEW -m tcp -p tcp - dport 22 -j ACCEPT 2. Modify the vi/etc/sysconfig/iptables command to add port 80 to the firewall

    1. -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  

    3. Turn off/on/restart the firewall

    1. /etc/init.d/iptables stop  
    2. #start Start  
    3. #restart Restart  
Reference: https://cloud.tencent.com/developer/article/1067247 my linux FAQ-Cloud+Community-Tencent Cloud