Interview--Common Linux commands

Source: Internet
Author: User
Tags readable dmesg

ls

Ls-la

Parameters:
-A: All files are listed together with the hidden file (the file that starts with.)
-A: All files, together with hidden files, but not included. And.. These two directories are listed together to
-D: Lists only the directory itself, not the profile data in the directory
-F: Lists the results directly without sorting (LS presets are sorted by file name!) )
-F: Give additional data structures based on information such as files, directories, etc., such as:
*: Represents the executable file;/: representative Directory; =: represents socket file; |: represents FIFO file;
-H: List the file capacity in a more readable way (e.g. GB, KB, etc.);
-I: Lists inode locations instead of listing file attributes;
-L: Long data serial out, including the attributes of the file and so on data;
-N: Lists UID and GID instead of user and group name (UID and GID will be mentioned in account management!) )
-r: Reverse output of the sorting results, for example: the original file name from small to large, the reverse is from large to small;
-R: Listed along with subdirectory contents;
-S: Sort by file Size!
-T: Sort by time

Detailed explanation of users and groups: http://www.cnblogs.com/xd502djj/archive/2011/11/23/2260094.html

Tools or commands for managing users (user);

Useradd Note: Add Users
AddUser Note: Add Users
passwd Note: Set a password for the user
Usermod Note: Modify the user command, can be usermod to modify the login name, the user's home directory and so on;
Pwcov Note: Synchronizing users from/etc/passwd to/etc/shadow
PWCK Note: Pwck is to verify that the user profile/etc/passwd and/etc/shadow file contents are legitimate or complete;
Pwunconv Note: Is the pwcov of the reverse operation, is to create/etc/passwd from/etc/shadow and/etc/passwd, and then delete the/etc/shadow file;
Finger Note: View the user Information tool
ID Note: View the user's UID, GID, and user group to which they belong
CHFN Note: Change user Information tool
SU Note: User Switching tool
sudo note: sudo is executed by another user (execute a command as another user), SU is used to switch users, and then to complete the corresponding task by switching to the user, but sudo can execute commands directly, such as Sudo You do not need the root password to perform root assignment only root can execute the corresponding command, but the Visudo to edit the/etc/sudoers to achieve;
Visudo Note: Visodo is the command to edit the/etc/sudoers, or you can use the VI to edit the/etc/sudoers effect is the same without this command;
Sudoedit Note: Same as sudo function;

2) tools or commands for managing user groups (group);

groupadd  注:添加用户组;
groupdel         注:删除用户组;
groupmod        注:修改用户组信息
groups     注:显示用户所属的用户组
grpck
grpconv   注:通过/etc/group和/etc/gshadow 的文件内容来同步或创建/etc/gshadow ,如果/etc/gshadow 不存在则创建;
grpunconv   注:通过/etc/group 和/etc/gshadow 文件内容来同步或创建/etc/group ,然后删除gshadow文件;

Useradd -G police Tom//New Tom User and added to police workgroup

Note::-G belongs to the group-D home Directory-S used by the shell

usermod -G groupname username or: gpasswd-a user Group//Add workgroup to existing users

Close user account: passwd peter–l

Re-release: passwd peter–u

Permanently delete user account Userdel Peter

Groupdel Peter

Usermod–g Peter Peter (Force delete all files and subdirectories in the user's home directory and home directory)

Remove a user from a group

Edit/etc/group Find the GROUP1 line, delete A

or with a command.

gpasswd-d A GROUP

Display user Information

ID User

cat/etc/passwd

Cat View File Contents

> indicates new content overwrites original file

>> indicates that new content has been appended to the file

More pagination Display

Less

Very important command:

History [-c] [-D offset] [n] or HISTORY-ANRW [filename] or history-ps arg [arg ...]
Parameters:
N: number, to list the most recent command lists
-C: Eliminate all history content in the current shell
-A: Add the current New History command to Histfiles, and if there is no histfiles, the default write ~/.bash_history
-r: Read Histfiles's contents into the current Shell's history memory
-W: Writes current history memory content to Histfiles

!! # Execute last Instruction

!988 # Execute No. 988 Instruction

!ps #执行历史命令以ps开头的命令

History 10 # List The last 10 commands executed

History | Tail-4 #

Alias ls= ' ls-l--color=tty ' #给命令起别名

Type LL #

Unalias ll #取消命令别名

Find (Find/-name file1-print, looking down from the current directory for a file named File1)

mkdir (mkdir dir1, new catalog Dir1)

mv file1/home/haowen/, moving files to directory/home/haowen/

, equivalent to window clipping)

(MV file1 filenew1, change file name to Filenew1)

Parameters:
-f:force the meaning of coercion, forcing the direct movement without asking;
-I: If the target file (destination) already exists, you will be asked to overwrite it!
-U: If the target file already exists and the source is newer, it will be updated (update)

PWD Print working Directory (PWD, show current path) pwd-p shows the exact path instead of using the link path

Touch create an empty file to revise a file date to current (Mtime and Atime)

Locate lists the full file name of a file from the database

Find./-name index.jsp Find files with the name index.jsp in the current directory

  grep    (grep "mobile=13712345678"   Logfile1,   in Logfile1;
           Search Find Content "mobile=13712345678")
 ping   (ping 61.129.78.9, ping www.163.com, test network connection is normal)
 ifconfig  (ifconfig, view native IP address, subnet mask, etc.)
 ps     (ps-aux View the processes that have started in the system, Ps-aux | grep programe1,
  & nbsp;      See if Program 1 is running
 kill  (kill-9  2325, kill process with process number 2325,  
         killall  programe1, kill programe1 process)
 reboot (restart system)

Chown (Chown-r Haowen. Assigns all file and directory permissions in the current directory to Haowen
,-R includes subdirectories)
Chgrp-r MySQL. (Change the current folder to a MySQL group, MySQL is an existing group) change the file or directory to belong to the group.

chmod:
Linux/unix file call permissions are divided into three levels: file owners, groups, and others.
The use of chmod can be used to control how files are called by others.
+ indicates an increase in permissions,-represents a cancellation permission, = Represents a unique set of permissions.
R means that the readable 4,w indicates that the writable 2,x represents the executable 1,

1. Set the file file1.txt to be readable by everyone:
chmod ugo+r file1.txt or chmod 444 file1.txt

2. Set the file File2 to master read-write execution, group,other, read only
chmod 744 File2 (7=> "111",4=> "100" binary)

3. Set the file File3 to be master read/write execution, Group,other, no permission operation can not read and write execution)

chmod file3 (7=> "111",0=> "000")


Each of the a,b,c is a number that represents the permissions of the user, Group, and other respectively.

 r=4,w=2,x=1 to rwx property 4+2+1=7; 4+2=6 to rw-property;
To r-x the property, 4+1=5

Finger displaying information about users of the system
Netstat-a look at the online status of the network:
NTSYSV Provisioning service starts simultaneously with system startup

System-related commands:---
DMESG: for example DMESG | More Display system diagnostic information, operating system version number, physical and other information
DF: For example df-h display hard disk space
Du: View the hard disk space used by all levels of subdirectories in the directory
Free: View system memory, size occupancy of virtual memory (swap space)
Top: Dynamic real-time view of system memory, CPU, process

Hostname View Host Name:
Hostname new hostname Modify host name (temporary, reboot is gone):

Mount
When the mount command does not use any options and parameters, it displays the file system information that is mounted on the current Linux system.

Mount Cttype Dev dir
The disc file system type is: Iso9660;dev indicates the device name on which the file system needs to be mounted, and the device name of the optical drive is/dev/cdrom; Dir indicates the mount point, which is the path to the file directory that is mounted.

Name:crontab (Task Scheduler)
Usage rights: All users
How to use:
crontab [-u user] filecrontab [-u user] {-l |-r |-e}
Description
Crontab is used to allow a user to execute a program at a fixed or fixed interval, in other words, a user-like time table. -u user refers to the setting of the time table for the specified user, which presupposes that you must have permission (for example, root) to specify another's time schedule. If you do not use the-u user, it means setting your own schedule.
Parameters:

-E: Do a text editor to set the time table, the default text editor is VI, if you want to use a different text editor, you first set the VISUAL environment variables to specify the use of the text editor (for example, Setenv VISUAL Joe)
-R: Delete the current schedule table
-L: Lists the current schedule table

The format of the schedule table is as follows:
F1 F2 F3 f4 f5 program

Where F1 is expressed in minutes, F2 represents hours, F3 represents the day of the month, F4 represents the month, and F5 represents the day of the one week. Program represents the programs to execute.
When F1 is * indicates that every minute the program,f2 is executed, the program is executed every hour, and the rest of the analogy
When the F1 is a-B, it is executed from the time of the minute to the minute of the hour, and the F2 is a-B indicating that it is executed from the first and the other, and the other analogy
When F1 is */n, it is executed once every n minutes, F2 is */n for every n-hour interval, and the rest of the analogy
When F1 is a, B, C,... A, B, C,... Minutes to execute, F2 for a, B, C,... The time indicated that the first, B, c ... Hours to execute, and the rest of the analogy
The user can also store all the settings in the file file, using the crontab file to set the time schedule.
Example:
The/bin/ls is performed at the first 0 minutes of every day per month:
0 7 * * */BIN/LS

In December, the/usr/bin/backup is performed every 20 minutes in the morning from 6 to 12 hours per day:
0 6-12/3 */usr/bin/backup

Monday to Friday every 5:00 send a letter to [email protected]:
0 * * 1-5 mail-s "HI" [email protected] </tmp/maildata

Every day of the month 0:20 midnight, 2:20, 4:20 .... Perform echo "haha"
0-23/2 * * * echo "haha"

Attention:
When the program executes at the time you specify, the system will send you a letter showing what the program is doing, and if you do not wish to receive such a letter, please add >/dev/null 2>&1 after each line.

Name: Sleep
Usage rights: All users
How to use: Sleep [--help] [--version] number[s**d]
Description: Sleep can be used to delay the current action for some time
Parameter description:
--HELP: Display Auxiliary message
--version: Show version number
Number: Length of time, can be followed by s,m,h or D
Where S is seconds, M is minutes, h is hour, D is the number of days
Example:
Show the current time delay after 1 minutes, and then show the time again:
Date;sleep 1m;date

Name: Finger
Usage rights: All users
How to use: Finger [options] user[@address]
Description: Finger can allow users to query some other user's information.
Example: The following command can query the information of the native administrator:
Finger root

Name: Last
Usage rights: All users
How to use:shell>> last [options]
Note: The display system has been received from the beginning of each month from the information of the person logged in
Put the meter:
-R omit the hostname field
-num Display before num
Username Display Username's login message
TTY restricted login message with terminal code
Example:

Shell>> Last-r-2

Name: Write
Usage rights: All users
How to use:
Write user [Ttyname]
Description: Send message to other users
Put the meter:
User: Pre-user account for the messaging
Ttyname: If the user has more than two TTY connections at the same time, you can choose the appropriate TTY messaging
Example. 1:
Send message to Rollaend, at this time rollaend only one connection:
Write Rollaend
The next step is to hit the message and end, press CTRL + C

Example. 2: The connection to Rollaend,rollaend is PTS/2,PTS/3:
Write Rollaend PTS/2

The next step is to hit the message and end, press CTRL + C
Note: If the other party sets MESG N, then the seat will not be passed on to each other

Interview--Common Linux commands

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.