Linux face questions

Source: Internet
Author: User
Tags stdin uuid

1. Linux Mount Winodws shared folder:

1) Create a shared folder under Windows.
2) Confirm that your Linux installation is a Samba package and its client program (smbclient), because Samba is the program that provides the exchange of Linux and Windows.
3) Start looking at the shared files directory under Windows: Smbclient–l//192.168.1.1, if the connection is OK, you can see the shared directory under Windows (in character form).
4) Mount shared directory: Mount–t cifs–ousername= "", passwd= ""//192.168.1.1/shared Folder//mnt/

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

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

3, with tcpdump sniffing 80 port access to see who the highest:

Tcpdump-i ETH0-TNN DST Port 80-c 1000 | Awk-f "." ' {print$1 '. " $ "." $ "." $4} ' | Sort | uniq-c | Sort-nr|head-20
1) tcpdump-i ETH0-TNN DST Port 80-c 1000: Statistics the packet with destination port 80 in this machine,-TNN: Display directly with IP and port number, not hostname and service name, and do not display timestamp. -C 1000: Statistics of 1000 packets.
2) awk-f "." ' {print$1 '. " $ "." $ "." $4} ': The output of the tcpdump is processed on one line, and the remote host IP is printed sequentially as a delimited domain.
3) Sort: Sorts the output of the access-side IP.
4) Uniq–c: Merge the same rows and count the number of peers.
5) Sort–nr: Sort by the same number of rows, reverse the order, the largest one on the front.
6) Head-20: Extract the first 20 lines.

4. Count the number of files in the specified directory:

Find/-type F | Wc–l
1) Find/-type F: Find the root directory, general file.
2) Wc–l: Count the number of rows.

5. View the number of IP connections (number of remote hosts accessing this machine):

Netstat-n | awk '/^tcp/{print $} ' | Awk-f: ' {print '} ' |sort | uniq-c | Sort–rn
1) Netstat–n: Lists all network connections for this computer, including the TCP/UDP and UNIX sockets.
2) awk '/^tcp/{print $} ':/^tcp/: The condition is a line that begins with TCP, ^: this represents the meaning of the beginning of the row. {print $: Prints the 5th field, representing the IP and port of the remote host, by default, tab as the delimited domain.
3) Awk-f: ' {print '} ': '-f: ': as a delimited field; Print the first field, remove port and show IP only.
4) Sort: Sort the IP.
5) Uniq–c: Merge the same rows and count the number of peers.
6) Sort–nr: Sort by the same number of rows, reverse the order, the largest one on the front.

6, Shell under the 32-bit random password generation (number plus the letter):

Method 1: (somewhat problematic)
cat/dev/urandom | Sed–e ' s/[^a-za-z0-9]//g ' |strings–n 32|head–n 1
1)/dev/ Urandom: Generates a random number of files.
2) sed–e ' s/[^a-za-z0-9]// G ': The resulting data, one line of processing, non-alphanumeric content deleted.
3) String–n 32: Sets the number of bits in a string to 32 bits, and it also handles each row.
4) Head–n 1: Extracts the contents of the first row.

Method 2:
cat/proc/sys/kernel/random/uuid| md5sum| Cut–c 1-32
1) Cat/proc/sys/kernel/random/uuid: Read the UUID code file, each time the data obtained will be different, for the 8-4-4-4-12 form of the number of letters and strings.
2) md5sum: To convert UUID code to MD5 code (problematic?) );
3) cut–c 1-32: Select the contents of 1-32 characters in each row.

7, statistics of Apache Access.log in the most visited 5 IP:

Cat Access_log_2011_06_26.log |awk ' {print $} ' |uniq-c|sort-rn|head-n 5
1) View the log file to

8. How to view the contents of a binary file:

hexdump-c [filename]: Use the Hexdump command.

9. What is the meaning of the vsz in the PS aux, what does RSS represent:

1) PS aux: View all processes that the system is running.
[1]a: Displays all terminal-related processes, initiated by the terminal.
[2]x: Shows all processes unrelated to the terminal.
[3]u: Displays a user-directed list of users.
1) VSZ: Virtual memory set, virtual memory space occupied by process
2) RSS: Physical memory set, process consumes actual physical memory space.
3) S: interruptible sleep state
4) R: Operating state
5) D: Non-disruptive sleep state
6) T: Stop state
7) Z: Zombie State

10, Detect and repair/dev/hda5:

Umount/dev/hda5; E2fsck-p/dev/hda5;mount/dev/hda5: Uninstall/dev/hda5;-p: Do not ask the user comments, automatically repair the file system, after detection and repair, remember to re-mount/dev/hda5.

11. Linux Boot sequence:

Boot order:
1) The BIOS program reads the information from the CMOS into memory, obtains the parameters of the hardware, detects and initializes the hardware (post,power-on self-test, power-on self-test), and decides to start the device sequence.
2) The BIOS reads the boot loader (boot loader) in the MBR into memory.
3) The boot loader reads the kernel files into memory, and after the kernel loads, re-detects the hardware and loads the drivers for each hardware so that the hardware is ready!
4) Run the first process initrd and gradually start the various services.
5) In addition, if it is a multi-system host, it also includes the boot loader and grub content. Each partition will also have a boot sector (boot sector) to complete the multiboot function.

12. The difference between symbolic links and hard links:

1) Hard connection (actual connection): In the directory block will be multiple file names to an inode, can be understood as the alias of the file, do not need to occupy additional inode and block, only need to add point data under the directory block. You can only use hard connections to files, not directories. Using the command ln filename1 filename2, the file filename1 produces a hard-connect (alias) filename2.
2) Symbolic Connection (shortcut): Create a file (Inode+block), Block records the inode of the directory to be connected to the file, and the file name, to become a symbolic link, can be understood as a shortcut. Symbolic connections can be for directories. Ln–s filename1 filename2

13. Save the partition table for the current disk partition:

sfdisk-d/dev/sdb >/etc/sdbpar.bak: Save partition Table
1) Sfdisk–d/dev/sdb: View the partition table of the entire hard disk SDB.

14, detect and automatically repair file system:

E2fsck-check [a Linux ext2/ext3 file system]
-B Specify block size
-F Force Detection.
-P Automatic Repair file system
1) The same as the 10th question

15. Install GRUB manually:

Install grub Manually
1.grub-install--boot-directory=[Specify boot directory]
DEVICE (File system)
2.grub
Grub>root (hd0,0): First partition of first hard disk
Grub>setup (hd0):
1) Grub is the boot program of the boot system, which provides the option to enter which system (multi-system environment) when booting.

16, change the kernel parameters:

# Sysctl
-P Do not restart the system, let the kernel reread/etc/sysctl.conf files
-a displays all kernel parameters and the values they are using.
-W Temporary set/etc/sysctl.conf parameter sysctl-w net.ipv4.ip_froward=0

17. Take random numbers within the specified range:
echo $[$RANDOM%39]: for 39, the remainder is definitely 39 or less.

18. Limit Apache HTTP Server: The number of connections per second is 1, the peak is 3:

Iptables-a input-d 172.16.100.1-p tcp--dport 80-m limit--limit 1/second--limit-burst 3-j ACCEPT
1) –A Input: Add a new input table rule.
2) –d 172.16.100.1: The target host's IP is native. You can also transfer to-I.
Eth0:eth0 is an external NIC for HTTP, which represents the packets that you want to enter into this network card.
3) –p TCP--dport 80:TCP protocol with a target port of 80.
4) –m limit--limit 1/second–limit-burst 3: Limit the number of connections per second to 1 and the peak to 3.
5) –j Accept: Operation for acceptance.

19, FTP Active and passive mode:

1. Active mode
1" client randomly launches a port a greater than 1024, and the FTP server-side command Port 21, after three handshake, establishes a command delivery channel.
2) The client then launches a port (port number: a+1) and informs the server by the command delivery channel.
3) after the server is accepted to the port (a+1), the active through 20 port and the client a+1 port for three handshake connection, Establish a data transfer channel.
4) but because the client may have a firewall, the server side cannot connect to the client's a+1 port. This creates a passive connection mode.
2.
passive mode

2) server-side randomly launches a port B and informs the client through the command delivery channel.
3) after the client accepts the port (b), the boot port (a+1), and the server-side B Port after three handshake connection to establish a data transfer channel

20, display/etc/inittab in the beginning of #, followed by one or more white space characters, and then followed by any non-whitespace character line:

grep "^\#[[:space:]]\{1,\}.\{1,\}"/etc/inittab
1) ^: beginning of line; \#: escape character; [[: Space:]]\{1,\}: Represents one or more whitespace characters.
2). \{1,\}:.: The delegate must have an arbitrary character.

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

grep "\:[0-9]\:"/etc/inittab
1) \: Escape character
2) [0-9]: The representative must have a number in 0-9,

22, how to add their own script to the service inside, that is, you can use the service command to invoke:

1) write test script Test#!/bin/bash
chkconfig:-ten
description:just a test
echo" hello,$1 "
2) enables the script to be called by the Service command
[1]MV test/etc/init.d/: Place the script under the stand alone directory.
[2]chmod +x/etc/init.d/test: Add x permission to a file, representing the executable.
[3]chkconfig--add test: Adds the specified system service and allows the Chkconfig directive to manage it. The relevant data is also added to the system-initiated narrative file.
[4]service test start
: Boot system service" test ".

23, write a script to add 20 users in bulk, user name user1-20, password is user followed by 5 random characters:

#!/bin/bash
for i in {1..20};
do

useradd user${i}: Adding user user1-user20
echo $pass | passwd User${i}–stdin: To set a password for the user,--stdin: Through the previous pipeline output, as a password input.
echo "user${i} <=============> $pass" >>./ Userlist.out: Writes the user and password in an additive manner to the Userlist.out file.
done

24, write a script to achieve the Judgment 192.168.1.0/24 Network, the current online IP What, can ping general thought online:

1) Method 1, use the ping command:
#!/bin/bash
ips= "192.168.1."
For i in {1..254};
ping-w 1-c 1 ${ips}${i} &>/dev/null && echo "${ips}${i} is up" | tee-a uplog.txt | | echo "${ips}${i} Isdown "
[1]ping-w 1-c 1 ${ips}${i}: Sends an ICMP packet to the specified IP,-W 1: Waits 1 seconds;-C 1:ping once.
[2]&>/dev/null: &> equals 2>1&: separate error messages and correct information into/dev/null, where there are only error messages, so 2>/dev/null can also be used.
[3]&& echo "${ips}${i} is up": if you can ping through, output IP online information.
[4]|tee-a uplog: The online IP is recorded in an additive manner to the file uplog.txt.
[5]| | echo "${ips}${i} is down": If the ping does not pass, the output IP is not in line information.
Done
echo "Please read Uplog-know which host is online." : Online users are in file Uplog.
2) Method 2, using Nmap command
NMAP–SP 192.168.1.0/24: Through packet detection, the analysis of several hosts within the LAN is initiated.

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.