Linux Interview Basic Questions __linux

Source: Internet
Author: User
Tags chmod disk usage file permissions

This article may be for beginners of no basic use, most of the children with Linux base please skip this section automatically-_-| |

Moreover, study or review Linux This thing, strongly recommends not light reading, must knock a knock, play a game, will start much faster.


Linux is an open source, free operating system, its stability, security, processing concurrency has been recognized by the industry, many medium-sized, large and even mega-projects are using Linux. Linux kernel: redhat, Red Flag Linux, Ubuntu, SuSE, Fedora, their core is the same (Note:linux is actually a general term, such as noodles is a general term, you can have a whistle surface, noodle, dozen halogen noodles, etc.)

Features of Linux
-Free/Open source
-Multithreading/multiuser support
-Good security
-Superior to memory and file management

shutdown Command
Shutdown-h now (shutdown immediately) Shutdown-r Now (restart your computer) reboot (restart your computer)

go to Desktop
StartX

User Login
Log in as little as possible with the root account login, because it is the system administrator, the greatest authority, unavoidable operation error. You can log on as a normal user, and then use the "Su-" command to switch to system administrator status

User Logoff
Enter the logout at the prompt

VIEditor is the most famous editor of Linux, but also we learn Linux must master tools, Linux can also use VI for the development of programs, such as Java programs, C programs. Input I, enter into insert mode; Enter the ESC key and enter the command mode; Enter a colon: Wq to exit Save: q! means to exit without saving


Linux file system is a hierarchical tree-like directory structure, the topmost layer in this structure isroot directory "/", and then create additional directories under this directory, and it is very important to understand the Linux file directory deeply.

- /
-Root, store root user related files
-Home, storing files for ordinary users
-Bin, a directory where common commands are stored, such as Vi,su
-Sbin, you must have certain permissions to use the command
-MNT, default mounting directory of optical drive and floppy drive
-etc, storage of configuration related files
-Var, storing frequently changing files, such as sock files for network connections
-Boot, storing related files for boot system boot
-usr, install a default directory of software, equivalent to Windows program files

Introduction to Common commands
pwdThat shows which path is currently under

User Management for Linux

useradd user name, adding user
"Case" Useradd xiaoming

passwd user name, set password for new user
"Case" passwd xiaoming, change Xiao Ming's password

Userdel user name, delete user
"Case" Userdel xiaoming, delete user but save user home directory
"Case" userdel‐xiaoming, delete user and user home directory

logout, current user launches
Who am Iand who is the current user

CDs, changing directories
ls, listing files and directories
Ls‐a, displaying all files in the directory, including hidden files
ls‐l, displaying long column table style
mkdir, create a directory
rmdir, delete empty directory
Touch, create an empty file

cp, copy command
"Case" Cp‐r dir1 dir2, recursive replication command (copy subdirectory information)

mv, moving files and changing file names
rm, deleting files and directories
RM‐RF *, delete all contents, include Directories and files, R indicates recursion, F indicates coercion
Ln, a symbolic connection, similar to creating a shortcut to a file

ln‐s Source target
"Case" Ln‐s/etc/inittab Inittab,inittab point to the actual file/etc/inittab Inittab

More, show the contents of the file with pagination, CTRL + PAGE UP turn, Sky grid down
less, displaying file content with pagination

grep, querying content in text
"Case" assumes that there is a Hanyang keyword in a file Test.java, you can use the grep name command to find it, grep n "Hanyang" test.java,n to appear on the nth line

|, Pipeline command, in Linux and UNIX systems, give the results of the previous command to the following command processing
"Case" ls‐l/etc/| More

-Man [command], assistance, similar to help in DOS

-Find, search for files and directories. In Linux, because file systems are made up of hierarchical structures, it is not easy to find specific files and directories throughout the system. and the "Find" command solves the problem.

- searches for and displays files and directories with the specified name in a specific directory
"Case" found/-name man: means to search for a file or directory that has a name of man from the root directory
-Search for files or directories that have been accessed/changed over a period of time
"Case" find/home-amin-10: Files or directories accessed within 10 minutes
"Case" find/home-atime-10: Files or directories accessed within 10 hours
"Case" find/home-cmin-10: Files or directories that have changed in 10 minutes
"Case" Find/home-ctime + 10: A file or directory that was changed 10 hours ago


- search for files of a specified size
"Case" find/home-size +10k: means to find files with a size of 10k in the/home directory


-redirect command
-Ls-l > A.txt, the contents of the list are written to the file A.txt (overwrite write)
-Ls-al >> Aa.txt, the contents of the list are appended to the end of the file Aa.txt
-Enter information from the file: Database_program < Database_data
-EN, view environment variables


-Compression and decompression
-process. zip files in zip and unzip
-Basic usage of zip command
-Zip File.zip *:zip after the compressed file name, then enter the text to compress after it
Pieces can be
-Automatically delete the original file after compression
"Case" Zip m file.zip to.txt: Compress to.txt file into File.zip file, To.txt automatically delete
-Compress subdirectories together
"Case" zip‐r file.zip *: Compressing subdirectories in the current directory
-Ignore the contents of subdirectories
"Case" zip‐j file.zip *
-Remove compressed or unnecessarily compressed files
"Cases" zip‐n. mpg:. jpg:. gif: The first file should be separated by ":" In the middle.
-Compress files after one day
"Case" Zip‐t 102002 file.zip: File compression after October 20, 2002 in the current directory
-Do not compress the original file of the linked file
"Case" Zip‐y file.zip *
-Compression rate problem, -1~-9, of which-9 of the highest compression rate
"Case" zip-9 file.zip *
-Exclude files that do not need to be compressed
Case Zip File.zip *-x file2.txt: Exclude file2.txt files from the current directory when compacting
-Unzip the. zip file with the unzip command
-Extract files directly
"Case" unzip File.zip
-Exclude files that do not need to be decompressed
"Case" unzip file.zip‐x File2: Other files are uncompressed except file2 files
-View the contents of the compressed package
Case Unzip‐z File.zip: View the contents of a File.zip package, or use "-l" "V" to view the contents of a compressed package
-processing. gz files with gzip and gunzip



Each user in Linux must belong to a group and not be independent of the group. In Linux, each file hasowner, group, other groupThe concept.
1 Owner: Typically the creator of the file, who creates the file, becomes the owner of the file naturally. You can see the owner of the file with the Ls‐ahl command. You can also modify the owner of a file by using the Chown username file name.
2 File group: When a user creates a file, the group that contains the file is the group that the user is in, the Ls‐ahl command can see all of the files ' groups, or you can use the CHGRP group name file name to modify the group where the file resides.
3 other groups: except the owner of the file and the users of the group, other users of the system are other groups of files.


file Permissions
The contents of the ls-l are shown below:
-rwxrw-r‐-1 root root 1213 Feb 2 09:39 ABC

-10 characters to determine what different users can do with a file
-the first character represents a file (-), a table of contents (d), a link (l)
-Each of the remaining characters is set (RWX), read (R), write (W), execute (x)
-The first group of rwx: The permissions of the owner of the file are read, write, and execute
-The second group of rw-: the permissions of the same group of users as the file owner are read, write, but not executed
-Third group r--: the permissions of other users who are not in the same group as the file owner are read and write-unable and executed
The number can also be expressed as: R=4,w=2,x=1 so rwx=4+2+1=7

-1 indicates the number of files connected
-Root indicates that the user
-Root indicates the group where the user is located
-1213 indicates file size (bytes)
-Feb 2 09:39 indicates the date of last modification
-ABC indicates file name

commands to change permissions
chmod change permissions on files or directories
chmod 755 ABC: Assigning ABC permissions Rwxr-xr-x
chmod U=RWX,G=RX,O=RX ABC: IBID. u= user Rights, g= group permissions, o= different groups of other user rights
chmod u-x,g+w ABC: To remove the permissions that the user performs for ABC, and to increase the group write permissions
chmod a+r ABC: Add read permissions to all users

Change owner (chown) and user Group (CHGRP) commands
Chown xiaoming ABC: Change the owner of ABC to Xiaoming
CHGRP Root ABC: Change the group that ABC belongs to root
Chown root/ABC: Change ABC the owner of this directory is root
Chown‐r root/abc: Changes to ABC this directory and all of the files and directories under it are owned by root

change user Group
When adding a user, you can specify which group to add the user to, as well as the admin rights of ROOT to change a
The group where the user is located
-USERMOD‐G Group name User name
You can change the initial directory of the user login by using the-usermod‐d directory name

Linux Partition detailed
The partitions of the hard disk are mainly divided into basic partitions (Primary portion) and extended partitions (Extension portion). For a single hard drive, the number of basic partitions and extended partitions cannot be greater than 4, and basic partitions can be used immediately but not partitioned. The extended partition must be partitioned again before it can be used, meaning it must be partitioned two times. So what's the point of having an extended partition? It is the logical partition (Logical portion), and the logical partition is not limited in number

For Windows users, several partitions have several drives, and each partition gets an alphabetic identifier, which can then be used to specify the files and directories on the partition. Their file structure is independent and very well understood. But for these users to start Redhat Linux, but a bit annoying. Because ofRedhat Linux users, regardless of a few partitions, to which directory to use, it ultimately has only a root directory, a separate and unique file structure。 Each partition in Redhat Linux is used to make up the entire file system. because itA processing method called "loading" is adopted., its entire file system contains a complete set of files and directories, and links a partition to a directory. The partition to be loaded will make its storage available in this directory.

Several important commands
mount Command
Mount [-parameters] [device name] [Mount Point]
Uninstall Command
Umount [Mount Point]
View disk usage
DF [-parameters]
-Df-h
-Df‐l
-DF [Directory full path] to see which partition a directory is in

View Linux system partition specifics
Fdisk‐l

Shell Programming
In fact, the interactive interpretation and execution of user input commands as an imperative language is only one aspect of shell functionality. The shell can also be used for programming. It provides a means to define variables and parameters and a rich program control structure. Using shell programming resembles a batch file in DOS, called shell script, or shell program or shell command file.

Shell script file:
-is a text file
-A collection of commands
-Have permission to execute
-Mode of execution (./filename)

Export can be temporarily added to a system path, such as Export path= $PATH: $HOME/bin:/root/test/t1, output environment path, referencing the original value $path, $HOME represents the work home directory,: is the path separator
Shell wildcard characters
-* Representing multiple letters or numbers
Represents a letter or a number
"Case" ls * ls a? LS f080[1-6].tif


-escape character \
"Case" ls/mnt/win1/my\documents

-Single quotation mark: Do not process any variables and commands
"Case" Echo ' Welcome $NAME, the date is date '

-double quotes: Handling variables but not processing commands
"Case" echo "Welcome $NAME, the date is date"

-Inverted quotation marks: use each word in quotation marks as a command, and if it is a variable, evaluate it first and then treat it as a command
"Case" Echo Welcome $NAME, the date is ' date '


Review History
-History, view history of used commands
-History 5, this description shows the last 5 commands used
-! 5, this description executes the command with history number 5

-!ls, this note executes the last command that starts with "LS"

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.