Linux_ (1) Basic command (top)

Source: Internet
Author: User
Tags parent directory disk usage file permissions root access

First, the basic command
1. Who am I?
WhoAmI
--who am I
2. Who is online
W.H.O.
W
3. Show current path (positioning)
Pwd
4. Switch directories
CD ~ Back to home directory
Cd.. Return to the top level directory
5. View a list of subdirectories and files in a directory
Ls

6. Switch users
SU User name
Su Root

7. Create user (requires root permission)
useradd [option] User name
8. Password change (requires root access)
passwd User Name
LW3 liwei123

9. Show hidden files
Ls-a
. Current directory
.. Previous level directory (parent directory)
~ Current User home directory (/home/user name)
/root directory

10. View Help
LS--help
Mans LS
Q exit

Second, the system directory structure
1./root directory
. Current directory
.. Parent Directory
2./bin:
The bin is the abbreviation for binary, which holds the most frequently used commands.
3./boot:
Contains some of the core files used when starting Linux, including some connection files and image files.
4./dev:
Dev is the abbreviation for device, which stores Linux external devices,
The way you access your device in Linux is the same way you access your files.
5./ETC:
This directory is used to store all the configuration files and subdirectories required for system administration.
6./home:
User's home directory, in Linux, each user has a directory of their own,
In general, the directory name is named after the user's account.
7./lib:
This directory contains the most basic dynamic connection shared library of the system,
It acts like a DLL file in Windows. These shared libraries are required for almost all applications.
8./media:
The Linux system will automatically recognize some devices, such as USB flash drives, optical drives, etc.
When identified, Linux will mount the identified device to this directory.
9./MNT:
The system provides this directory for users to temporarily mount other file systems,
You can mount the CD-ROM drive on the/mnt/and then enter the directory to view the contents of the CD-ROM.
10./opt:
Is the directory for the host to install additional software.
For example, installing an Oracle database can be placed in this directory. The default is empty.
11./proc:
This directory is a virtual directory, it is a mapping of system memory,
System information can be obtained by directly accessing this directory.
The contents of this directory are not on the hard disk but in memory,
You can also directly modify some of the files inside,
For example, you can use the following command to block the host's ping command, so that others cannot ping your machine:
Echo 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all
/root:
This directory is a user home directory for system administrators, also known as super-permissions.
13./sbin:
S is the Super user's meaning, which is stored in the system administrator's use of the System Management program.
14./srv:
This directory holds data that needs to be extracted after some services are started.
15./sys:
This directory installs a new file system Sysfs that appears in the 2.6 kernel.
The Sysfs file system integrates the following 3 file system information:
Proc File system for process information,
DEVFS file system for the device,
Devpts file system for pseudo-terminal.
The file system is a visual reflection of the kernel device tree.
When a kernel object is created, the corresponding files and directories are also created in the kernel object subsystem.
16./tmp:
This directory is used to store some temporary files.
17./USR:
This is a very important directory, the user's many applications and files are placed in this directory,
Similar to the Program Files directory under Windows.
17.1/usr/bin:
The application that the system user uses.
17.2/usr/sbin:
Super users use the more advanced hypervisor and System daemon.
17.3/USR/SRC: The default drop directory for the kernel source code.
./var:
This directory is stocked with things that are constantly being expanded and used to keep directories that are often modified in this directory.
Includes various log files.

Third, Operation command
11. Create a file
Touch file name
Touch./Subordinate directory/file name

12. Create a Directory
mkdir Directory Name
Mkdir-p Parent1/parent2/child1/child2

13. deleting files Rm[remove]
RM [Options] File
Rm-r Directory Name//delete non-empty directory

14. Copy the file Cp[copy]
CP [source file] [target file]
Cp-r Source Directory Destination Directory
CP/ETC/PASSWD. Copy the password in the/etc directory to the current directory

15. Move or rename a file Mv[move]
MV [options] source file target location/destination file

16. View the contents of a file
Cat
17. View the contents of the file by screen
More
18. Progressive viewing of file contents
Less
19. Show the beginning of the file (10 lines by default)
HEAD-5 file name
20. Show end of file (10 lines by default)
TAIL-5 file name

21. Display the current time
Date
22. Show Calendar
Aa.
23. Display disk usage
Df
24. Calculate the disk usage for each file
Du
25. Clear the Screen information
Clear

Iv. file attributes
Linux system is a typical multi-user system, different users in different positions, with different permissions.
In order to protect the security of the system, the Linux system has different requirements for different users to access the same file (including directory files).
In Linux we can use the LL or LS–L command to display the properties of a file and the users and groups to which the file belongs.

1. Type
The first character in Linux means that the file is a directory, a file, or a linked file, and so on.
When [d] is the directory
When [-] is the document;
If [l] is indicated as a linked document (link file);
If [b] is indicated as the device file inside the storage interface device (can be random access device);
If [C] is indicated as a serial port device inside the appliance file, such as a keyboard, mouse (one-time reading device).

2. Permissions
In the following characters, a group of three, each of which is a combination of three parameters, is "rwx".
where [R] stands for readable (read), [W] stands for writable (write), [x] stands for executable (execute).
Note that the location of the three permissions does not change, and if there is no permission, a minus sign [-] appears.

第1-3位 determines that the owner of the file owns the file's permissions.
第4-6位 determines that the owning group (the same group of users of the owner) has permission to the file,
第7-9位 determines the permissions that other users have on the file.
Where the 1th, 4, 7 is the Read permission, if the "R" character is indicated, then there is read permission, if the "-" character, there is no Read permission;
The 2nd, 5, 8 bits indicate write permission, if the "W" character is indicated, there is write permission, if the "-" character indicates no write permission;
The 3rd, 6, and 9 bits represent executable permissions, and if represented by an "x" character, there is an EXECUTE permission, and if the "-" character is represented, then no execute permission is performed.

For a file, it has a specific owner, that is, the user who owns the file.
At the same time, in a Linux system, users are categorized by group, and one user belongs to one or more groups.
Users other than the file owner can be divided into the same group of users and other users as the file owner.
Therefore, the Linux system sets different file access rights by file owner, file owner, and other users.

--For root users, the file's permissions generally do not work on it.

31. Check the file
Ls-l type permissions, number of hard connections, file owner, file owning group, file size, change time, file name
File directory name/file name
32. File types
-General Documents
d directory file (directory)
b Device file (block)
C-Character device files (character)
L linked file (link)
P Artificial pipe (piped)
33. File Permissions
U file Owner permissions (user)
G File Owning group permissions (group)
o Other user Rights (other)
R Read access (read 4)
W Write permission (write 2)
X Execute permissions (execute 1)
34. Modify File Permissions
chmod [Options] Permission file name
Permissions U/g/o[a/all] +/-r/w/x multiple with "," separated
chmod nnn File name

35. CHGRP: Change file group
Grammar:
CHGRP [-R] belongs to group name file name
Parameter options
-R: Recursively change the group of files, that is, when you change the genus of a directory file, if you add the-r parameter, the group of all files under that directory will change.

36, Chown: Change the owner of the file, you can also change the file group
Grammar:
chown [–R] belongs to the main name of the file name
Chown [-R] Main name: Name of Group name

37, chmod: Change the file 9 properties
There are two ways to set up Linux file attributes, one is a number and one is a symbol.
Linux files have the basic permissions of nine, respectively, owner/group/others three identities each have their own Read/write/execute permissions.
Options and Parameters:
XYZ: is the permission attribute of the number type just mentioned, which is the sum of the numeric values of the Rwx property.
-R: Continuous change of recursion (recursive), i.e. all files in the secondary directory will be changed
chmod u/g/o +/-r/w/x file or directory
chmod u+w DNS
chmod u-w DNS

38. Create a link
I node (inode): Manages files and directories within Linux through the I node.
Hard links: Exactly the same as the source file, that is, the same node corresponds to multiple names. The catalog cannot use hard links.
Soft Link: Create a shortcut for the original file, independent of the original file, the content points to the source file (pointer file).
ln source file Hard Link name
Ln-s Directory/source file soft link name
Ls-il Directory Name/file name
Role: Hard links prevent accidental deletion, deleting files to be successful when the same index node belongs to a unique link.
Soft connect across file systems.

V. System commands
1. Shutdown
Function Description: Shut down the machine
Command path:/usr/sbin/shutdown
Execute permissions: Root
Syntax: Shutdown
Example: # shutdown-h now

2. Reboot
Function Description: Restart the system
Command path:/usr/sbin/reboot
Execute permissions: Root
Syntax: reboot
Example: # reboot

3. Umask
Function Description: Display, set default permissions for files
Command path:/bin/umask
Execute Permissions: All Users
Syntax: umask [-S]
-S displays the new file or directory default permissions in rwx form
Example: $ umask
$ umask-s
The file default permissions are up to 6, the file default does not have execute permission, the directory default maximum permission is 7.
User General user 0002 System user 0022
Files 664 644
Table of Contents 775 755

4. Info
Function Description: Get help information
Directive English original meaning: information
Instruction Path:/usr/bin/info
Execute permissions: All User
Syntax: info [any keyword]
Example 1: Viewing the Help information for the LS directive
$ info ls

5. Whatis
Function Description: Get a brief description of the index
Directive Name: Whatis Apropos Makewhatis
Directive English original meaning: Search the Whatis database for strings
Instruction Path:/usr/bin/whatis apropos
/usr/sbin/makewhatis
Execute permissions: All User,all user,root
Syntax: Whatis apropos [any keyword]
Example:
$ Whatis ls

6:ifconfig
Function Description: View Network setup Information
Command path:/usr/sbin/ifconfig
Execute permissions: Root
Syntax: ifconfig option [-a] [NIC Device ID]
-A displays all network card information
Example: # ifconfig-a

7. Ping
Function Description: Test network connectivity
Command path:/usr/sbin/ping
Execute permissions: Root
Syntax: Ping option IP address
Example: # ping-c 10 192.168.1.1
CTRL + C

Linux_ (1) Basic command (top)

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.