Command operations for Linux
1. Daily Operation Command
* * View your current working directory
Pwd
* * Time to view current system
Date
* * See who is online (who logged in to the server)
Who view current online
Last view recent log in history
2. File System operation
**
LS/view child nodes (folders and files) information in the root directory
Ls-al-a is show hidden file-L is displayed in a more detailed list form
* * Switch Directories
Cd/home
* * Create Folder
mkdir AAA It's a relative path.
Mkdir-p AAA/BBB/CCC
Mkdir/data This is the absolute path of the notation
* * Delete Folder
RmDir can delete empty directory
Rm-r AAA can remove all of the AAA entire folder and all child nodes in it
RM-RF AAA Mandatory Removal AAA
* * Modify folder name
MV AAA Angelababy
* * Create File
Touch somefile.1 Create an empty file
echo "I miss You,my Baby" > Somefile.2 uses the redirection > function to write the output of an instruction to a file, overwriting the original file contents
echo "Huangxiaoming, gun dan" >> somefile.2 append the output of an instruction to a file without overwriting the original file contents
Edit the build file with the VI text editor
Most basic usage
VI somefile.4
1, first will enter the "General mode", this mode only accept a variety of shortcut keys, can not edit the contents of the file
2, press the I key, will be from the general mode into the editing mode, this mode, typed is the file content
3, after editing, press ESC to exit the edit mode, return to the general mode;
4, then press:, enter the "Bottom line command mode", enter the WQ command, carriage return can
Some common shortcut keys
Some useful shortcut keys (used in general mode):
A after the cursor one begins inserting
A in the last insert of the line
I insert at the front of the line
GG jumps directly to the first line of the file
G jump directly to the last line of the file
DD Delete Row, if 5dd, then delete the cursor 5 lines at once
yy copies the current row, copies multiple rows, then 3yy copies the 3 rows near the current row
P Paste
V Enter the character selection mode, select Done, press Y to copy, press p to paste
Ctrl + V into block selection mode, select Done, press Y to copy, press p to paste
Shift+v Enter row selection mode, select Done, press Y to copy, press p to paste
Find and replace (entered in command mode in the bottom line)
%s/sad/88888888888888 effect: Find all sad in file, replace with 88888888888888
/you effect: Find you in the file and navigate to the first found place, press N to navigate to the next matching position (press N to the previous one)
Copy files
CP somefile.1/home/hadoop/
View File Contents
Cat somefile Full output of file contents at once (console)
More Somefile can flip page, scroll down one page (blank) and flip One (b) exit (q)
Less somefile can flip the page, Flip one page (space), flip One (b), flip a line (↑) The next line (↓) can search for keywords (/keyword)
tail-10 Install.log viewing 10 lines at the end of a file
Tail-f Install.log The unique inode number of the small F trace file, even after renaming the file, or tracking the original inode representation of the file
Tail-f Install.log Large F Follow the file name to track
head-10 Install.log View 10 lines of the file header
3. Operation of file permissions
Interpretation of the description format of Linux file permissions
Drwxr-xr-x (can also be represented by binary 111 101 101-755)
D: Identify node type (d: folder-: File L: Link)
R: Readable w: writable x: Executable
The first set of RWX: Represents the permissions of the owner of the file to it: a readable writable executable
The second set of R-x: Represents the permissions of the group to which this file belongs: readable, non-writable, executable
The third group of R-x: Represents the permissions of other users of this file (as compared to the above two categories of users) to it: readable, non-writable, executable
Modify file Permissions
chmod G-RW Haha.dat indicates that the RW permission for the owning group will be Haha.dat canceled
chmod o-rw Haha.dat means to cancel Haha.dat to other people's RW rights
chmod u+x Haha.dat means to increase the haha.dat to the owning user's permissions by x
You can also change the permissions in a digital way
chmod 664 Haha.dat
will be modified into rw-rw-r--.
If you want to uniformly modify all content permissions for a folder, you can use the-r parameter
Chmod-r 770 aaa/
Chown Angela:angela aaa/< only root can perform >
4, the basic user management
Add user
Useradd Angela
To change the password to login
passwd Angela, follow the prompts to enter the password
* * Configure sudo permissions for users
Edit vi/etc/sudoers with Root
Add a line to Hadoop at the following location in the file
Root all= (All) all
Hadoop all= (All) all
Hadoop users can then use sudo to execute system-level instructions
[email protected] ~]$ sudo useradd huangxiaoming
5. System Management operation
View Host Name
Hostname
Modify host name (invalid after reboot)
Hostname Hadoop
Modify host name (permanent after reboot)
Vi/ect/sysconfig/network
Modify IP (invalid after reboot)
Ifconfig eth0 192.168.12.22
Modify IP (permanent after reboot)
Vi/etc/sysconfig/network-scripts/ifcfg-eth0
Mount * * * * mount external storage devices to the file system
Mkdir/mnt/cdrom Create a directory that is used to mount
Mount-t Iso9660-o ro/dev/cdrom/mnt/cdrom/mount the device/dev/cdrom to the mount point:/mnt/cdrom
Umount
Umount/mnt/cdrom
Statistics the size of a file or folder
Du-sh/mnt/cdrom/packages
Df-h to view disk space
Shutdown
Halt
Restart
Reboot
Configure a password-free SSH login between hosts
If A wants to land B
To operate on a:
Percent percent first generate a key pair
Ssh-keygen (when prompted, enter directly)
Percent and then copy and append A's own public key to B's authorization list file Authorized_keys
Ssh-copy-id B
Background service Management
Service Network Status View the state of the specified services
Service network stop stops specifying services
Service network start to start the specified services
Service Network restart restart specified services
Service--status-all View all background services in the system
Setting up a self-starter configuration for background services
Chkconfig View all server self-starter configurations
Chkconfig iptables off turn off automatic start of the specified service
Chkconfig iptables on to start the specified service automatically
System Startup Level Management
Vi/etc/inittab
# Default RunLevel. The runlevels used is:
# 0-halt (do not set Initdefault to this)
# 1-single User mode
# 2-multiuser, without NFS (the same as 3, if you don't have networking)
# 3-full Multiuser mode
# 4-unused
# 5-x11
# 6-reboot (do not set Initdefault to this)
#
Id:3:initdefault:
Command operations for Linux
1. Daily Operation Command
* * View your current working directory pwd
* * Time to view current system date
* * See who is online (who logged in to the server) who view current online last view recent login history
2. File system operation **ls/View child nodes (folders and files) information in the root directory ls-al-a is show hidden file-L is displayed in a more detailed list form
* * Switch Directory Cd/home
* * Create folder mkdir AAA This is the way the relative path is written mkdir-p Aaa/bbb/cccmkdir/data This is the absolute path of the wording
* * Delete folder rmdir can delete empty directory Rm-r AAA can remove AAA entire folder and all child nodes in RM-RF AAA forcibly remove AAA
* * Modify folder name MV AAA Angelababy
* * Create a file touch somefile.1 create an empty file echo "I miss You,my Baby" > Somefile.2 uses the redirection ">" function to write the output of an instruction to a file, overwriting the original file content Echo "Huangxiaoming, gun Dan" >> somefile.2 appends the output of an instruction to a file without overwriting the contents of the original file
Use vi text Editor to edit the generated file ****** the most basic usage VI somefile.41, first will enter the "General mode", this mode only accept a variety of shortcut keys, can not edit the contents of the file 2, press I key, will go from the general mode into the editing mode, this mode, typed is the file content 3, After editing, press ESC to exit the edit mode, return to the general mode, 4, then press:, enter the "command mode", enter the Wq command, return to
Some useful shortcuts (used in general mode): A After the cursor one begins inserting a at the end of the line insert I at the top of the line insert GG directly jump to the first line of the file G jump directly to the last line of the file dd delete line, if 5DD, then the disposable After deleting the cursor 5 lines yy Copy the current line, copy multiple lines, then 3yy, copy the current line near the 3 lines p paste v into the character selection mode, select Done, press Y to copy, press p CTRL + V to enter the block selection mode, select Done, press Y to copy, press p to paste shift+v into the row selection module Select Finish, press Y to copy, press p to paste
Find and replace (enter in the bottom line command mode)%s/sad/88888888888888 effect: Find all sad in file, replace with 88888888888888/you effect: Find the one that appears in the file, and navigate to the first found place, press N to navigate to the next Match position (press N to previous)
Copy file CP somefile.1/home/hadoop/
View the contents of a file cat somefile all output of file contents (console) More Somefile can flip page, scroll down one page (space) up (b) exit (q) Less somefile You can flip a page, flip one (space) up one page (b), flip a line (↑) The next line (↓) can search for keywords (/keyword)
tail-10 Install.log View the file at the end of the 10 lines tail-f install.log small f trace File unique inode number, even if the file renamed, or trace the original inode represents the file Tail-f Install.log Large F follows the file name to track
head-10 Install.log View 10 lines of the file header
3. Operation of file permissions
The description format of Linux file Permissions Drwxr-xr-x (can also be represented by binary 111 101 101-755)
D: Identity node type (d: folder-: File L: Link) r: Readable w: writable x: Performs the first set of RWX: Represents the permissions of the owner of the file to it: Readable writable executable second set of R-x: Represents the permissions of the group to which this file belongs: readable, non-writable, and can perform a third group of R-x : Represents the permissions of other users of this file (as compared to the above two types of users) to it: readable, non-writable, executable
Modify file Permissions chmod G-RW Haha.dat indicates that the RW permission for the owning group will be Haha.dat canceled chmod O-RW haha.dat indicates that the RW permission for the other person will be Haha.dat canceled chmod u+x haha.dat table Add Haha.dat to the permissions of the owning user by adding X
You can also change the permissions in a digital way chmod 664 Haha.dat will be modified to rw-rw-r--
If you want to uniformly modify all content permissions for a folder, you can use the-r parameter chmod-r 770 Aaa/chown Angela:angela aaa/< only root can perform >
4, the basic user management
Add user Useradd Angela to change the password to login passwd Angela Press the prompt to enter the password
* * To configure sudo permissions for users with root edit vi/etc/sudoers in the following location of the file, add a line for Hadoop root all= (All) all Hadoop all= (all) all
Hadoop users can then use sudo to execute system-level instructions [[email protected] ~]$ sudo useradd huangxiaoming
5. System Administration Operation * * * * view hostname hostname**** modify hostname (invalid after reboot) hostname Hadoop
Modify host name (permanent after reboot) vi/ect/sysconfig/network**** modify IP (invalid after reboot) ifconfig eth0 192.168.12.22
Modify IP (permanent after reboot) Vi/etc/sysconfig/network-scripts/ifcfg-eth0
Mount * * * * mount the external storage device to the file system Mkdir/mnt/cdrom create a directory to mount the mount-t iso9660-o ro/dev/cdrom/mnt/cdrom/the device/dev/cdr Om Mount to mount point:/mnt/cdrom
Umountumount/mnt/cdrom
Statistics the size of a file or folder Du-sh/mnt/cdrom/packagesdf-h view disk space * * * shutdown halt**** restart reboot
Configure a password-free SSH login between hosts if A is to log on B to operate on a: percent of the first generation of the key pair Ssh-keygen (prompt, the direct carriage return) percent and then copy and append A own public key to the authorization list file of B authorized_ Keys in Ssh-copy-id B
Background Services Management Service network Status View the state of the specified services service network stop stops specifying service services network start starts the specified services service networ K Restart Restart the specified Services service--status-all View all background services in the system
Set the boot configuration of the background service Chkconfig view all server self-starter configuration chkconfig iptables off automatically start the specified service Chkconfig iptables on to start the specified service automatically
System Boot Level Management Vi/etc/inittab
# Default RunLevel. The runlevels used are:# 0-halt (do not set Initdefault to this) # 1-single user mode# 2-multiuser, without NFS (The same as 3, if you don't have networking) # 3-full multiuser mode# 4-unused# 5-x11# 6-reboot Set Initdefault to this) #id: 3:initdefault:
Common Linux Commands