Work week four: Linux basics

Source: Internet
Author: User

Content of this week's job:

1, the Replication/etc/skel directory is/home/tuser1, requires/home/tuser1 and its internal files belong to the group and other users do not have any access rights.

# Ls/home/tuser1 | | Mkdir/home/tuser1 && cp-r/etc/skel/*/home/tuser1 && chmod-r g-r,o-r/home/tuser1 | Ls-l/home/tuser1

-RW-------. 1 root root 0 August 10:59 a.txt


2. Edit the/etc/group file and add the group Hadoop.

# Vim/etc/group

Add a line to the end of the file: hadoop:x:139:


3. Manually edit the/etc/passwd file to add a new line, adding user Hadoop, whose basic group ID is the Hadoop group ID number; its home directory is/home/hadoop.

# VIM/ETC/PASSWD

Hadoop:x:139:139::/home/hadoop:/bin/bash


4. Copy the/etc/skel directory as/home/hadoop, which requires that the genus Group and other users of the Hadoop directory be modified without any access rights.

# Ls/home/hadoop | | Mkdir/home/hadoop && cp-r/etc/skel/*/home/hadoop && chmod g-r,o-r/home/hadoop | Ls-ld/home/hadoop

DRWX------. 4 Hadoop hadoop 4096 August 10:50/home/hadoop


5, modify the/home/hadoop directory and all the internal files of the owner of Hadoop, belong to Hadoop group.

# Chown-r Hadoop:hadoop/home/hadoop | Ls-ld!$ && Ls-la!$

Chown-r Hadoop:hadoop/home/hadoop | Ls-ld/home/hadoop && Ls-la/home/hadoop
DRWX------. 4 Hadoop hadoop 4096 August 10:50/home/hadoop
Total dosage 20
-RW-------. 1 Hadoop hadoop 0 August 10:57 a.txt
-RW-------. 1 Hadoop hadoop 18 May 05:21. bash_logout
-RW-------. 1 Hadoop hadoop 176 May 05:21. Bash_profile
-RW-------. 1 Hadoop Hadoop 124 May 05:21. BASHRC
Drwx--x--x. 2 Hadoop hadoop 4096 November gnome2
Drwx--x--x. 4 Hadoop hadoop 4096 July 22:17. Mozilla


6. Display the lines in the/proc/meminfo file beginning with uppercase or lowercase s, in two ways;

# grep ^[SS]/proc/meminfo

swapcached:0 KB
swaptotal:2031612 KB
swapfree:2031612 KB
shmem:4028 KB
slab:85816 KB
sreclaimable:19592 KB
sunreclaim:66224 KB

# grep-i ^s/proc/meminfo

swapcached:0 KB
swaptotal:2031612 KB
swapfree:2031612 KB
shmem:4028 KB
slab:85812 KB
sreclaimable:19588 KB
sunreclaim:66224 KB


7. Display the default shell of the/etc/passwd file as a non-/sbin/nologin user;

# grep-v "/sbin/nologin"/etc/passwd | Cut-d:-f1,7

Root:/bin/bash
Sync:/bin/sync
Shutdown:/sbin/shutdown
Halt:/sbin/halt
Admin:/bin/bash
Mageia:/bin/bash
Slackware:/bin/bash
Openstack:/bin/bash
Hadoop:/bin/bash
Gdm:/bin/bash
Abc:/bin/bash
Asd:/bin/bash
Asdd:/bin/bash
Lll:/bin/bash
Gentoo:/bin/csh


8. Display the user whose default shell is/bin/bash in/etc/passwd file;

# grep "/bin/bash"/etc/passwd | Cut-d:-f1

Root
Admin
Mageia
Slackware
OpenStack
Hadoop
Gdm
Abc
Asd
Asdd
lll


9. Find out one or two digits in/ETC/PASSW D file;

# grep "\<[0-9]\{1,2\}\>"/etc/passwd

# grep-e "\<[0-9]{1,2}\>"/etc/passwd


10. Display the line beginning with at least one blank character in/boot/grub/grub.conf;

# grep "^[[:space:]]\+"/boot/grub/grub.conf

Root (hd0,0)
kernel/vmlinuz-2.6.32-642.el6.x86_64 ro root=/dev/mapper/vg_mycentosl68-lv_root Rd_NO_LUKS rd_LVM_LV=vg_ Mycentosl68/lv_swap crashkernel=auto rd_no_md rd_lvm_lv=vg_mycentosl68/lv_root LANG=zh_CN. UTF-8 keyboardtype=pc keytable=us rd_no_dm rhgb quiet
Initrd/initramfs-2.6.32-642.el6.x86_64.img


11, the display/etc/rc.d/rc.sysinit file with the beginning of #, followed by at least one white space character, and then have at least one non-whitespace character line;

# grep "^#[[:space:]]\+[^[:space:]]\+"/etc/rc.d/rc.sysinit

# grep-e "^#[[:space:]]+[^[:space:]]+"/etc/rc.d/rc.sysinit

#/etc/rc.d/rc.sysinit-run once at boot time
# taken in part from Miquel van Smoorenburg ' s BCHECKRC.
# Check SELinux Status
# Print a text banner.
# only read this once.
# Initialize Hardware
# Set Default Affinity
# Load Other user-defined modules
# Load modules (for backward compatibility with VARs)
# Configure Kernel Parameters
# Set the hostname.
# Sync waiting for storage.
# Device Mapper & related initialization
# Start any MD RAID arrays that haven ' t been started yet
# Remount The root filesystem read-write.
# Clean Up SELinux labels
# If Relabeling, relabel mount points.
# Mount all other filesystems (except-NFS and/proc, which is already
# mounted). Contrary to standard usage,
# filesystems is not unmounted in single user mode.
# the ' No ' applies to all listed filesystem types. See Mount (8).
# Check to see if a full relabel is needed
# Update Quotas If necessary
# Initialize pseudo-random number generator
# Configure Machine if necessary.
# Clean out/.
# do we need (W|u) tmpx files? We don ' t set them up, but the sysadmin might ...
# clean Up/var.
# Clean up utmp/wtmp
# Clean up various/tmp bits
# Make ICE Directory
# Start up swapping.
# Set up Binfmt_misc
# Boot time profiles. Yes, this should is somewhere else.
# Now then we have all of our basic modules loaded and the kernel going,
# Let's dump the syslog ring somewhere so we can find it later
# Create the crash indicator flag to warn on crashes, offer fsck with timeout
# Let's rhgb know that we ' re leaving rc.sysinit


12. Find the line ending with ' LISTEN ' followed by 0, 1, or more whitespace characters in the result of the "Netstat-tan" command;

# Netstat-tan | grep "listen[[:space:]]*$"

TCP 0 0 0.0.0.0:44877 0.0.0.0:* LISTEN
TCP 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
TCP 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
TCP 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
TCP 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN
TCP 0 0::: 37831:::* LISTEN
TCP 0 0::: 111:::* LISTEN
TCP 0 0::: $:::* LISTEN
TCP 0 0:: 1:631:::* LISTEN
TCP 0 0:: 1:25:::* LISTEN
TCP 0 0:: 1:6010:::* LISTEN


13, add user bash, Testbash, basher, Nologin (this one user's shell is/sbin/nologin), and then find the current system on its user name and the default shell of the same user information;

# useradd Bash && useradd testbash && useradd basher && useradd-s/sbin/nologin nologin

# grep "^\ ([[: alnum:]]\+\>\). *\1$"/etc/passwd

Sync:x:5:0:sync:/sbin:/bin/sync
Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
Halt:x:7:0:halt:/sbin:/sbin/halt
Bash:x:3011:3013::/home/bash:/bin/bash
Nologin:x:3014:3016::/home/nologin:/sbin/nologin


Note: For personal work and learning purposes only

Work week four: Linux basics

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.