Common commands for Linux

Source: Internet
Author: User
Tags ranges system log disk usage

  • Linux under the use of VIM to open the configuration file garbled, in the terminal input: "lang=" can be.

  • To see if the port is occupied:

  • NETSTAT-ANP | grep Port

    Netstat-ltn

  • Lsof-i:port

  • Shell script Command list:
  • $# is the number of arguments passed to the script

    The name of the script itself

    $ $ is the first parameter passed to the shell script

    $ $ is the second parameter passed to the shell script

    [Email protected] is a list of all parameters passed to the script

    $* is to display all parameters passed to the script in a single string, unlike positional variables, which can have more than one parameter

    $$ is the current process ID number for the script to run

    $? is to display the exit status of the last command, 0 means no error, others indicate an error

      1. Find. -type f-name "*.sh"-type find a file of a certain type, such as: B-block device file. D-Directory. C-character device file. P-Pipeline file. L-Symbolic link file. F-Normal file.

      2. : N, $s/vivian/sky/replaces the first Vivian of each row in the nth row to the last row is sky

    : N, $s/vivian/sky/g replace the nth line to the last row all Vivian are sky

      1. Chown User name file path

      2. chmod 777 Test

      3. AddUser Password

      4. On the PC machine can not do on-demand operation (only for not add the domain name resolution of the PC machine), but on the other computer, then you need to put someone else's C:\Windows\System32\drivers\etc\hosts to cover their own directory of hosts file.

      5. 12.c++ often have code followed by "\" to indicate a newline, indicating that the following sentence and above are the same line.

      6. Du–sh view the file size.

      7. Shell 2>&1: & 1 more accurately, it should be the file descriptor 1, and 1 generally represents the Stdout_fileno, which is actually a dup2 (2) call. He standard output to All_result, Then copy the standard output to the file Descriptor 2 (Stderr_fileno), the consequence is that the file descriptor 1 and 2 point to the same file table entry, or the wrong output is merged. where 0 means that keyboard input 1 means that the screen output 2 indicates an error output. REDIRECT standard error to standard output and throw /dev/null go under. In layman's words, all standard output and standard errors are thrown into the trash.

      8. Try_file

    Try_files $uri $uri//index.php?q= $uri & $args;

    Checks whether the file exists in order and returns the first found file. The trailing slash is represented as a folder-$uri/. If all the files are not found, an internal redirect is made to the last parameter.

      1. The date +%s can display a large integer time of UTC equivalent to Os:millionseconds ().

      2. Date-d @1411266453 can convert the time to the current month date format.

      3. Date-d "1970-01-01 UTC 1411261790 Seconds" converts a random UTC time to the current time.

      4. Ulimit-c Unlimited enables the system to produce core files

      5. "Grep-v #" gets all lines that do not contain the # number, where "\" is the translation character,

      6. Cut-d:-f1 Gets the text with ":" As a delimiter, and gets the value of the first zone.

      7. grep return Value:

    succeeded, returned 0;

    Failed, file exists, template string does not exist, return 1;

    Failed, file does not exist, return 2;

      1. Try_file

    Try_files $uri $uri//index.php?q= $uri & $args;

    Checks whether the file exists in order and returns the first found file. The trailing slash is represented as a folder-$uri/. If all the files are not found, an internal redirect is made to the last parameter.

      1. umout. tmp resolves an issue in which the original folder cannot be deleted because the files are deleted before the project is quite worth.

      2. Stat ()

    Related functions: Fstat, Lstat, chmod, Chown, Readlink, Utime

    Header files: #include <sys/stat.h> #include <unistd.h>

    Define functions: Int stat (const char file_name, struct stat buf);

    Used to copy the file state referred to by the parameter file_name to the structure referred to in parameter buf, the return value of the function can be used to determine whether the file exists.

      1. INotify, which can be used to listen for file paths or files.

    int fd = Inotify_init ();

    int wd = Inotify_add_watch (fd, path, mask);

    int ret = Inotify_rm_watch (FD, WD);

      1. synchronous, asynchronous, blocking, non-blocking IO models

    Finally, a few more examples are not very appropriate to illustrate these four IO Model:

    There is a (synchronous blocking), B (synchronous non-blocking), C (asynchronous blocking), D (asynchronous non-blocking) four persons in fishing:

    A used is the most old-fashioned fishing rod, so, have to keep guarding, wait until the fish hooked up again lever;

    B's Fishing rod has a function, can show whether there are fish hooked, so, B and next to the MM chat, and then see if there are fish bait, some words on the rapid lever;

    C with the fishing rod and B almost, but he thought of a good way, is to put several fishing rods at the same time, and then keep in the side, once the show said the fish hooked, it will be the corresponding rod pull up;

    D is a rich man, simply hired a person to help him to fish, once the person caught the fish up, send a message to D.

      1. The Popen () function starts a process by creating a pipeline and invokes the shell. Because the pipeline is defined as one-way, the type parameter can only be defined as read-only or write-only, not both, and the resulting stream is read-only or write-only.

    The command parameter is a string pointer to a string that ends with a null terminator, which contains a shell command. This is sent to/bin/sh with the-c parameter, Executed by the shell. The type parameter is also a pointer to a string ending with a null terminator, which must be ' r ' or ' W ' to indicate whether it is read or write.

    The return value of the Popen () function is a normal standard I/O stream, which can only be closed with the Pclose () function, not fclose (). function. Writes to this stream are converted to standard input to the command commands; The standard output of command commands is the same as calling Popen (), which is the same as the process of the function, unless the command commands itself to change. Instead, reading a "Popen" stream is equivalent to reading the standard output of command commands, The standard input for command is the same as calling Popen, which is the same process as the function.

    Note that the output stream of the Popen function is fully buffered by default.

    The Pclose function waits for the associated process to end and returns the exit state of a command command, just like the WAIT4 function.

    Can be used to return the command result in the program: Popen ("Ls-l", "R"), the list of files can be returned;

    Popen ("Du-sk", "R") can be used to return the remaining space.

      1. Workflow of Libaio

    Libaio Workflow:

    Io_prep_pread ()/io_prep_pwrite () set read and write operation parameters

    Io_submit () Submit

    Io_getevents () Check Results

    1. Uname–a View all information about the system,-r view all, if it is a red hat, you can use Cat/etc/issue

    2. Match all Blank lines: ^[\t]*$[\n\r]

    3. Decompression command TAR-ZVXF * * *

    4. With Ulimit-n, we can get the maximum number of FD that a process can open.

    5. PWDX pid is used to view the directory where the running thread is located

    6. Stun Server Startup method:./server-v-b-h 121.14.85.205-a 121.14.85.206

    7. Pstack can be used to view stacks in the course of running Linux programs.

    8. Rpm-qa|grep-i MySQL is used to check if MySQL has been installed

    9. Rm-f/etc/my.cnf Remove configuration and data files from other MySQL paths

    10. Rm-rf/var/lib/mysql removing configuration and data files from other MySQL paths

    11. Mysql> set GLOBAL max_connections=300; Sets the maximum number of connections for MySQL

    12. Mysqladmin-uroot-pcoship variables Check the maximum number of connections for MySQL.

    13. TAR-XZVF redis_2.4.7.tar.gz Unzip the package.

    14. Getenforce checking the status of SELinux

    15. Vi/etc/selinux/config Disable SELinux in configuration

    16. Setenforce 0 enables the above configuration to take effect.

    17. Service iptables status Check firewall state

    18. Chkconfig iptables off firewall, after reboot takes effect

    19. Service iptables stop shut down firewall in time iptables–f can also take effect

    20. RPM-IVH vsftpd-2.0.5-16.el5_4.1.x86_64.rpm Force Installation Vsftp

    21. /sbin/chkconfig--list vsftpd Check the startup status of FTP

    22. /sbin/chkconfig--level 2345 vsftpd on or off a state of FTP

    23. Adduser-g ftp-s/sbin/nologin-d/mpeg cdnftper Add FTP user

    24. Chkconfig--list mysql Check if MySQL starts randomly

    25. Chkconfig--add MySQL lets MySQL start randomly.

    26. Tcpdump-i eth0-t tcp-s 60000-w diaoxian.cap Clutch

    27. Tcpdump–i eth0 TCP port 554–w test.cap

    View PC Configuration

      1. Cat/proc/cpuinfo viewing CPUs

    Free-m Viewing memory

    Fdisk-l viewing hard disk partitions

    Df-h Viewing mounted directories

    Ifconfig Viewing network card information

    Ethtool eth0 View details of the network card operating mode

    Lspic lists all the chip information, such as sound card, video card, network card and so on.

      1. Cat/etc/issue viewing the release version of the current system

      2. Uname–a View kernel information for the current system

      3. RPM-E--nodeps mysql-libs-5.1.73-3.el6_5.x86_64 forced uninstall MySQL

      4. Select Table_name,table_rows from tables where Table_schema = ' Olaj ' ORDER by table_rows Desc;

      5. NETSTAT–TNL | grep 3306

      6. %s/((HTTP|FTP|HTTPS)://) ([A-za-z0-9. -]+. [A-za-z] {2,6}) | ([0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3})) (: [0-9]{1,4}) * (/[a-za-z0-9\&%./-~-]*)?/\/Match link.

      7. Grep-r-n '. _log. [Loadxml|parse] './grep usage,-n denotes line number,-I means ignore case.

      8. Empty the system log and make room

    Rm-rf/var/log/*.gz

    Rm-rf/var/log/*.1

    echo "" >/VAR/LOG/DMESG

    echo "" >/var/log/kern.log

    echo "" >/var/log/messages

    echo "" >/var/log/syslog

      1. Find disk space for all files in the current directory

    DU-LH--max-depth=1

      1. g++ Hello.cpp-save-temps can save temporary files that are generated at compile time.

      2. Add Network Neighborhood: netsh-c "I i" Add Neighbors "172.30.25.246" "B8-ca-3a-f2-f4-c8"

      3. View send receive for current network: Dstat

      4. Du-h--max-depth=1 work/testing/* can see the disk usage of all files in the directory

    71-73 slightly

    1. OpenSSL engine–t See if there is an SSL hardware acceleration device
    2. Pgrep Redis-server | Wc–l View the number of startup threads.
    3. RSYNC-AVLP--exclude= "Log" to back up other things that remove log
    4. Echo–e allows for translation of subsequent content
    5. Echo-e "\e[32;40;1;4m is success\e[0m" The output font is color
    6. #cat/proc/cpuinfo |grep "Cores" |uniq view the number of CPU cores
    7. getconf PAGESIZE Query Nginx in the fastcgi_buffer_size should be configured how much.
    8. How to traverse some fields
      Startorder= "Redisserver,cpm,cls,cl,cg,rtcl,cdnadapter,ci"
      For module in $ (echo $startorder | tr ', ' \ n ')
      Do
      Done
    9. transcoding commands
      ./ffmpeg-i./bjqn/dragontv.beijing.youth.ep02.hdtv.720p.x264-chdtv.mkv-fpre vod-acodec copy-y./bjqn02.mp4
    10. Find: /download/-maxdepth 1-type f-mmin +120 | Grep-v Heartbeat.xml | Xargs-n 1 rm-f
    11. SORT-K3NR file
      K3 refers to sorting by a third field
      n Specifies that the classification is a numeric classification on a field.
      R is the descending meaning.
    12. 1>/dev/null indicates that the standard output of the command is redirected to/dev/null
      2>/dev/null indicates that the error output of the command is redirected to/dev/null
    13. Find. -name "*.C" | Xargs grep Main
    14. Du–sk View the current directory used space.
    15. TAR–JXVF TAR-BZ2 's Decompression command
    16. Stat-c%Y filename to check the last modified time of a file.
    17. Mysql-uroot-pcoship dbname < dbname.sql MySQL Direct import data
    18. SELECT Table_name,column_name,column_type from INFORMATION_SCHEMA. COLUMNS where table_schema= "Ott_r002_portalms" and data_type in (' int ', ' bigint ', ' decimal ') prevent IDs from overstepping.
    19. SELECT Table_schema,table_name,round ((data_length+index_length)/1024/1024,2) as MB from INFORMATION_SCHEMA. TABLES have mb>500 database space is not enough, see details.
    20. Awk-f ' [&,=,.,/] ' Nr==6{print $ ' tmpfile awk locks the first few lines
    21. Ps-a|awk '/process name/{print $ ' identifies a process number.
    22. Nohup Ping www.ibm.com & running programs in the background
    23. Setsid Ping www.ibm.com running programs in the background
    24. (Ping www.ibm.com &) Run the program in the background
    25. Screen, disown can also implement the function of response.
    26. !! Executes the last command executed.
    27. !s commands that begin with s in the execution history
    28. watch-d ls–l Let a command continue execution by default two seconds
    29. Pgrep ssh to find out the PID of the process associated with SSH
    30. CTRL+D Fast Launch Login terminal, ctrl+u delete a whole line (VIM insert mode is active)
    31. cd– return to the directory where you Last
    32. Touch-c-T 0801010800 filename.c time to modify files
    33. $_ last parameter of previous command
    34. Ss–t–a displaying TCP connections
    35. Cat/proc/46720/environ Gets the environment variables that the current process relies on.
    36. /proc/net/dev stores the network card information;
    37. grep eth/proc/net/dev|awk-f: ' {print $} ' |awk ' {print $, $9} ' view network card bandwidth
    38. /etc/passwd/etc/shadow user and password to store Linux system

    39. grep "http://202.105.136.35:18080/"-rl./Displays the file name with this entry
    40. awk ' End{print NR} ' tmp; counts the number of lines of a text.
    41. PS Auxw|head-1;ps auxw|sort-rn-k3|head-10 See the most CPU-consuming 10-a program;
    42. Treatment Dynamic Library not found: Ln-s/usr/lib64/libcrypto.so libcrypto.so.6
    43. Ps-a-O Stat,ppid,pid,cmd | Grep-e ' ^[zz] ' find zombie process
    44. Ps-a-O Stat,ppid,pid,cmd | Grep-e ' ^[zz] ' | awk ' {print $} ' | Xargs kill-9 Find and kill zombie process
    45. Database query Implementation Cartesian product: Select X+y+1, x+y+1 from (select 0 as X from dual union select 1 from dual Union select 2 from Dual) A, (select 0 as Y from dual Union Select 1 from dual Union select 2 from dual) b;
      Batch binding: FORALL I in 1.. 10000000
      INSERT a ...
    46. ./ffmpeg-i/mpeg/ad1.ts 2>&1 | grep ' Duration ' | Cut-d '-F 4,8 | Sed s/,//get the bitrate of the file
    47. After thread apply all BT gdb–c core.1111, you can use this command to view all threads.
    48. Netstat-n | awk '/^tcp/{++y[$NF]} END {for (w in y) Print W, Y[w]} counts the number of States of all TCP links

    49. df–h [directory name] to query which partition the current directory belongs to
    50. Iptables-i input-p tcp-m State--state new-m TCP--dport 22122-j accept open a port on the firewall/etc/init.d/iptables save to save the firewall settings. NETSTAT-UNLTP | grep Fdfs
    51. Vim/etc/rc.d/rc.local Set Boot start
    52. Centeros setting up a firewall firewall-cmd--zone=public--add-port=5000/tcp--permanent
      Firewall-cmd–reload

    53. Wget-s Http://httpd.apache.org/images/httpd_logo_wide_new.png 2>&1 | grep ' Accept-ranges '
      Accept-ranges:bytes testing whether the server supports the breakpoint continuation function
    54. Curl–range 0-99 http://images/billboard_iphone_hero.jpg Test Server supports breakpoint continuation
    55. Does the background server support long connections: netstat–n | grep time_wait, if the long connection is not supported then there will be many time_wait states.

    Common commands for Linux

    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.