Lab Building-1st linux exercises for the hourly competition, 1st Lab Building

Source: Internet
Author: User

Lab Building-1st linux exercises for the hourly competition, 1st Lab Building

1. Service Management

Install and run samba:

sudo apt-get updatesudo apt-get install sambasudo service samba restart

2. extract text information

Extract links of images ending with png and jpg in a given document using a script:

grep "http.*\.\(jpg\|png\)" $1 

Grep "http. * \. \ (jpg \ | png \)" $1


3. Search for a specified file

Write the full path of all files containing the shiyanlou string in the/etc directory to the/home/shiyanlou/output file:

touch outputsudo grep -R "shiyanlou" /etc > output


4. Obtain programs that meet the conditions

Run a script to obtain the absolute path of the program running on the specified port. If no program is running, print the OK string.

t=`lsof -i:$1|tail -1|awk '{print $1}'`if [  -n "$t" ] ;then    which $telse    echo "OK"fi

5. Configure an ssh certificate for the shiyanlou user so that the password does not need to be entered when the shiyanlou user logs on to the local experiment environment through SSH. At the same time, set the SSH service to prohibit all users from logging on with a password.

#1 modify sshd configuration sudo vi/etc/ssh/sshd_config # disable Password Logon PasswordAuthentication no # comment three lines # RSAAuthentication yes # PubkeyAuthentication yes # AuthorizedKeysFile. ssh/authorized_keys # restart to make the configuration take effect sudo service ssh restart # generate a public key to write the file cd ~ /. Sshssh-keygen-t dsa-p'-f ~ /. Ssh/id_dsacp id_dsa.pub authorized_keys # insecure settings, cannot use the RSA function chmod 600 ~ /. Ssh/authorized_keys

6. Avoid accidental deletion.

(1) files or folders deleted by the rm-f command are saved to the/tmp/trash folder temporarily without being deleted. For example, after using rm-f/home/shiyanlou/testfile, the file testfile will be moved to/tmp/trash/testfile. If the directory/tmp/trash already contains a file named testfile, it will directly overwrite the old file.
(2) When the rm command does not add the-f parameter, the execution process remains unchanged, and you do not need to move to the/tmp/trash folder.

Sudo cp/bin/rm/bin/oldrmsudo cp ~ /Rm. sh/bin/rm # script content #! /Bin/basffe [$ #-eq 2] & ["$1" = "-f"] then mv $2/tmp/trashelse/bin/oldrm $1 $ 2fi

7. Password generator

(1) The length of the generated password string is 12 characters.
(2) The password must contain numbers, uppercase and lowercase letters, and at least one special character.
(3) only these special characters are allowed: ><+ -{}:.&;

arr1=(\> \< \+ \- \{ \} \: \. \& \;)arr2=(a b c d e f g h i j k l m n o p q r s t u v w x y z)arr3=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)t=${arr1[$[$RANDOM%10]]}t=$t${arr2[$[$RANDOM%26]]}t=$t${arr3[$[$RANDOM%26]]}t=$t$[$RANDOM%10]echo $t"abcdefgh"


10. Copy the specified file

Copy all files larger than 4 MB in the specified directory (including subdirectories)

#! /Bin/bashfunction getdir () {# The directory must be consistent if [! -D "/tmp" $1]; then 'mkdir "/tmp" $1 'fi for element in 'sudo ls $ 1' do dir_or_file = $1 then /" $ element if [-d $ dir_or_file] then getdir $ dir_or_file continue else ss = 'sudo ls-l $ dir_or_file | awk '{print $5} ''if [$ ss-gt 10240]; then 'cp $ dir_or_file "/tmp" $1 'fi fi done} root_dir = "/etc" getdir $ root_dir






View comments

Related Article

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.