30 Linux face questions

Source: Internet
Author: User
Tags ftp protocol

1.linux How to hang a shared directory under Windows

Mount.cifs//192.168.1.3/server/mnt/server-o user=administrator,pass=123456

Linux server needs to manually build a later user and pass is the Windows Host account and password note space and comma

2. View the number of concurrent requests for HTTP and its TCP connection status

Netstat-n | awk '/^tcp/{++b[$NF]} END {for (A-B) print a, b[a]} '

There is also ulimit-n view Linux system open the largest file descriptor, here default 1024, do not modify the Web server changes here is no longer useless. To modify a few ways, say one of them:

Modify/etc/security/limits.conf

* Soft Nofile 10240

* Hard Nofile 10240

Effective after reboot

3. Sniff 80-port access with tcpdump to see who is the tallest

Tcpdump-i ETH0-TNN DST Port 80-c 1000 | Awk-f "." ' {print $1″. ' $2″. " $3″. " $4} ' | Sort | uniq-c | Sort-nr |head-5

4. View the number of connections per IP for the current system

ls/var/log/-lr| grep "^-" |wc-l

5. View the number of connections per IP for the current system

Netstat-n | awk '/^tcp/{print $} ' | awk-f: ' {print $} ' | sort | uniq-c | Sort-rn

6. 32-bit random password generation under shell

Cat/dev/urandom | head-1 | md5sum | Head-c >>/pass

The generated 32-bit random number is saved in the/pass file.

7. count the most visited 5 IPs in Apache's Access.log

Cat Access_log | awk ' {print '} ' | Sort | uniq-c | Sort-n-R | Head-5

8. How to view the contents of a binary file

We typically view the contents of a binary file by using the Hexdump command.

Hexdump-c XXX (file name)-C is the parameter of different parameters have different meanings

-C is the comparison specification of 16 binary and ASCII code display

-C is a single-byte character display

-B single-byte octal display

-O is a double-byte octal display

-D is a double-byte decimal display

-X is a double-byte hexadecimal display

Wait, wait.

What does the vsz in 9.ps aux mean and what does RSS mean?

VSZ: Virtual memory set, process-occupied virtual memory space

RSS: Physical memory set, process warfare with actual physical memory space

10. Detect and Repair/dev/hda5

Fsck is used to check and maintain inconsistent file systems. If the system is out of power or disk problems, the FSCK command can be used to check the file system, using:

fsck-p/dev/hda5

boot sequence for 11.Linux systems

Load bios–> read mbr–>boot loader–> load kernel –> user layer init a inittab file to set the level of system operation (General 3 or 5,3 is a multi-user command line, 5 is the interface) –> Init Process Execution rc.syninit–> boot kernel module –> perform different levels of running scripts –> Execute/etc/rc.d/rc.local (local run service) –> execute/bin/ Login, you can log in.

12. The difference between a symbolic link and a hard link

We can take symbolic links, which are soft connections, as shortcuts in Windows systems.

A hard link is like copying another copy.

ln 3.txt 4.txt This is a hard link, equivalent to copy, can not cross the partition, but modify 3, 4 will follow the change, if the deletion of 3,4 is not affected.

Ln-s 3.txt 4.txt This is a soft connection, equivalent to a shortcut. Modify 4,3 will also change, if the deletion of 3,4 will be broken. It's not ready to use.

13. Save the partition table for the current disk partition

The DD command is a powerful command to convert at the same time as replication

DD IF=/DEV/SDA of=./mbr.txt Bs=1 count=512

14: No 14 questions, I myself to a simple, how to copy in the text, paste, delete rows, delete all, search by row and alphabetical search.

The following actions are all in the command-line state operation, not in the edit state operation.

Move to the line that you want to copy in the text, move to where you want to copy the YY, and press p to paste it.

Delete Row move to row by DD

Remove all DG here Note g Be sure to capitalize

Find by row: 90 This is the 90th line.

Find/path by letter This is where the word path is located, there may be multiple occurrences in the text, and multiple lookups will appear in different locations.

15. Install Grub Manually

Grub-install/dev/sda

16. Modifying kernel parameters

VI/etc/sysctl.conf Modify the parameters here

Sysctl-p available after refresh

17. Take a random number within 1-39

echo $[$RANDOM%39]

Random number

%39 take remainder

18. Limit the number of new connections to Apache per second to 1 and a peak of 3

The number of new connections per second is usually done by a firewall, and Apache itself seems unable to set the number of new connections per second and can only set maximum connections:

Iptables-a input-d 172.16.100.1-p tcp–dport 80-m limit–limit 1/second-j ACCEPT

Hardware firewall settings More simple, interface, you can directly fill in the numbers ...

Maximum connection Apache itself can be set

MaxClients 3, modify the Apache maximum connection premise or to modify the system default TCP connection number. I said it in my blog, so I won't say it.

19.FTP Active mode and passive mode

The FTP protocol works in two ways: Port mode and PASV mode, Chinese meaning active and passive.

The port (Active) connection process is: The client sends a connection request to the server's FTP port (by default, 21), the server accepts the connection, and establishes a command link. When the data needs to be transferred, the client tells the server on the command link with the port command: "I opened the xx port, you come to connect me." The server then sends a connection request from Port 20 to the client's XX port, creating a data link to transmit the data.

The PASV (passive) connection process is: The client sends a connection request to the server's FTP port (by default, 21), the server accepts the connection, and establishes a command link. When the data needs to be transferred, the server tells the client on the command link with the PASV command: "I opened the xx port, you come to connect me." The client then sends a connection request to the XX port of the server and establishes a data link to transmit the data.

As can be seen from the above, the two ways of the command link connection method is the same, and the data link building method is completely different.

20. Display/etc/inittab begins with #, followed by one or more white space characters and followed by any non-whitespace character line

grep "^# \{1,\}[^]"/etc/inittab

21. Display/etc/inittab contains: A number: (that is, two colons in the middle of a number) line

grep "\:[0-9]\{1\}\:"/Etc/inittab

22. How to add a script to the system service, which is called with service

Add in the script

#!/bin/bash
# chkconfig:345 85 15
# DESCRIPTION:HTTPD

and then save

Chkconfig Httpd–add Creating a system service

You can now use the service to start or restart

23. Write a script, implement batch add 20 users, username user1-20, password is user followed by 5 random characters

#!/bin/bash

#description: Useradd

For i in ' seq-f '%02g "1 ';d O

Useradd user$i

echo "user$i-' echo $RANDOM |md5sum|cut-c 1-5 '" |passwd–stdinuser$i >/dev/null 2>&1

Done

24. Write a script to realize the 192.168.1.0/24 network, the current online IP What, can ping general think online
#!/bin/bash
For IP in ' SEQ 1 255 '
Do
{
Ping-c 1 192.168.1. $ip >/dev/null 2>&1
If [$?-eq 0]; Then
Echo 192.168.1. $ip up
Else
Echo 192.168.1. $ip down
Fi
}&
Done
Wait

25. Write a script to determine if a specified script is a syntax error, and if there is an error, then remind the user to type Q or Q to ignore the error and exit any other key to open the specified script via vim .

[email protected] tmp]# cat checksh.sh
#!/bin/bash

Read-p "Please input check script->" file
If [-f $file]; Then
Sh-n $file >/dev/null 2>&1
If [$?-ne 0]; Then
Read-p "You input $file syntax Error,[type Q to exit or Type vim Toedit]" answer
Case $answer in
Q | Q)
Exit 0
;;
Vim
Vim $file
;;
*)

Exit 0
;;
Esac

Fi
Else
echo "$file not Exist"
Exit 1
Fi

26, write a script: (26 includes 3 small questions)

1, create a function, can accept two parameters:

1) The first parameter is a URL, you can download the file, the second parameter is a directory, that is, the location of the download after the save;

2) If the user-given directory does not exist, the user is prompted to create it, or if it is created, the function returns a 51 error value to the calling script;

3) If the given directory exists, then download the file; Download command after the execution of the test file download success or not; If successful, return 0 to the calling script, otherwise, return 52 to the calling script;

[email protected] tmp]# cat downfile.sh

#!/bin/bash

Url=$1
Dir=$2
Download ()
{
CD $dir >>/dev/null 2>&1
If [$?-ne 0];then
Read-p "$dir No such file or Directory,create? (y/n) "Answer
If ["$answer" = = "Y"];then
Mkdir-p $dir
CD $dir
wget $url 1>/dev/null 2>&1
If [$?-ne 0]; Then
Return "52″
Fi
Else
Return "51″

Fi
Fi
}

Download $url $dir
echo $?

27, write a script: (27 includes 2 small questions)

1, create a function, you can accept a disk device path (such as/DEV/SDB) as a parameter, before you actually start the next step to remind the user of the danger, and let the user choose whether to continue, and then empty all partitions on this disk device (prompt, using the command DD if=/dev/ Zero OF=/DEV/SDB bs=512 count=1 Implementation, note that the device path should not be written wrong;

If this step fails, return 67 to the main program;

Then create two primary partitions on this disk device, a size of 100M, a size of 1G, and if this step fails, return 68 to the main program;
Format this two partitions, the file system type is ext3; If this step fails, return 69 to the main program;

If the above procedure is normal, return 0 to the main program;

2, call this function, and by receiving function execution of the return value to determine its execution, and display the information;

Local darray= (' ls/dev/sd[a-z] ')

For i in ${darray};d o

[["$i" = = "$"] && sd= $i &&break

Done

Else

Return66

Fi

#当匹配成功, enter the selection, tell the user whether to continue, enter the infinite loop if the input is wrong, and when the user chooses Y, empty the target partition and jump out of the while loop

While:;d o

READ-P "Warning!!! This operation would clean $Sd data. Next=y,quit=n [Y|n]: "Choice

Case $Choice in

Y

DD If=/dev/zero of= $Sd bs=512 count=1 &>/dev/null &&break | | return 67;;

N

Exit 88;;

*)

echo "Invalid choice,please choice again.";

Esac

Done

#使用echo传递给fdisk进行分区, if this command fails, then jump out, error value 68, it should be noted that sometimes this return value is very strange, the author before the success or failure is returned 1, and then after the restart, it is good, if cautious, you can create the partition, to judge, However, it is necessary to use other tools to intercept the relevant fields, although there are some minor problems, but nothing serious.

Echo-e "n\np\n1\n\n+100m\nn\np\n2\n\n+1024m\nw\n" |fdisk/dev/sdb&>/dev/null | | Return 68

#格式化之前, let the kernel re-read the disk partition table, it is worth noting that some system version, using Partprobe invalid, such as the author's environment is rhel5.8, and rhel6.0 later, the command is very dangerous, and use partx-a/dev/ SDB works better ... This should be prudent, if the format fails, then tell the failed partition to be defined as a variable, and jump out of the function, and bring out the error value

' Partprobe '

Part= ' fdisk-l/dev/$Sd |tail-2|cut-d ""-f1 "

For M in ${part

};d O

! Mke2fs-j $M &>/dev/null && errorpart= $M &&return 69

Done

Return0

}

#下面代码, call the function, receive the function return value, and determine where the error is based on the return value.

Disk_mod $

Res=$?

[$Res-eq 0] && exit 0

[$Res-eq] && echo "error! Invalid input. "

[$Res-eq] && echo "error! Command, DD <-faild.

[$Res-eq] && echo "error! Command, fdisk <-faild.

[$Res-eq] && echo "error! Command--Mke2fs <-faild. "

30 Linux face questions

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.