linux command operation
1. Daily operation commands
**View the current working directory
pwd
**View current system time
date
**See who's online (who's logged into the server)
who View current online
last View recent login history
2. File system operation
**
ls / View information on child nodes (folders and files) under the root directory
ls -al -a is to show hidden files -l is to show a more detailed list
**Switch directory
cd / home
**Create folder
mkdir aaa This is the way to write a relative path
mkdir -p aaa/bbb/ccc
mkdir /data This is the way to write the absolute path
**Delete folder
rmdir can delete empty directories
rm -r aaa can delete the entire folder aaa and all its sub-nodes
rm -rf aaa Force delete aaa
**Modify the folder name
mv aaa angelababy
**Create a file
touch somefile.1 creates an empty file
echo "i miss you,my baby" > somefile.2 Using the function of redirection ">", write the output result of an instruction to a file, which will overwrite the content of the original file
echo "huangxiaoming ,gun dan" >> somefile.2 appends the output of a command to a file without overwriting the original file
Edit the generated file with the vi text editor
******The most basic usage
vi somefile.4
1. First, it will enter the "general mode", this mode only accepts various shortcut keys, and cannot edit the content of the file
2. Press the i key, it will enter the editing mode from the normal mode. In this mode, all files are typed in.
3. After editing, press Esc to exit the editing mode and return to the normal mode;
4. Press : again to enter the "bottom line command mode", enter the wq command, and press Enter.
******Some commonly used shortcut keys
Some useful shortcut keys (used in normal mode):
a start inserting one position after the cursor
A is inserted at the end of the row
I insert at the beginning of the line
gg jumps directly to the first line of the file
G jumps directly to the end of the file
dd delete lines, if 5dd , delete 5 lines after the cursor at once
yy copy the current line, copy multiple lines, then 3yy, copy the 3 lines near the current line
p paste
v Enter character selection mode, after the selection is complete, press y to copy, press p to paste
ctrl+v to enter block selection mode, after the selection is complete, press y to copy, press p to paste
shift+v to enter the row selection mode, after the selection is complete, press y to copy, press p to paste
Find and replace (entered in bottom line command mode)
%s/sad/88888888888888 Effect: Find all sad in the file and replace with 88888888888888
/you effect: find the you appearing in the file, and locate the first found place, press n to locate the next matching position (press N to locate the previous one)
3. Operation of file permissions
****Interpretation of the description format of linux file permissions
drwxr-xr-x (also 111 101 101 --> 755 in binary)
d: identifies the node type (d: folder -: file l: link)
r: readable w: writable x: executable
The first group of rwx: Indicates the permissions of the owner of this file to it: readable, writable and executable
The second group of rx: Indicates the permissions of the group to which this file belongs: readable, not writable, executable
The third group of rx: Indicates the permissions of other users of this file (relative to the above two types of users) to it: readable, not writable, executable
**** Modify file permissions
chmod g-rw haha.dat means to cancel the rw permission of haha.dat to the group to which it belongs
chmod o-rw haha.dat means to cancel the rw permission of haha.dat to others
chmod u+x haha.dat means to increase the authority of haha.dat to the user by x
Permissions can also be modified numerically
chmod 664 haha.dat
will be modified to rw-rw-r--
If you want to modify all content permissions of a folder uniformly, you can use the -R parameter
chmod -R 770 aaa/
chown angela:angela aaa/ <only root can execute>
When the directory does not have execute permission, ordinary users cannot enter
When the file has only read and write permissions, ordinary users can delete it (deleting a file is not modifying it, it is operating the parent and directory), as long as the parent directory has the permission to execute and modify
4. Basic user management
*****Add user
useradd angela
To change the password to log in
passwd angela Enter the password as prompted
**Configure sudo permissions for the user
Edit vi /etc/sudoers with root
In the following location of the file, add a line for hadoop
root ALL=(ALL) ALL
hadoop ALL=(ALL) ALL
The hadoop user can then use sudo to execute system-level commands
[hadoop@shizhan ~]$ sudo useradd huangxiaoming
5. System management operations
*****View hostname
hostname
**** Modify the host name (invalid after restart)
hostname hadoop
*****Modify the hostname (permanently take effect after restart)
vi /ect/sysconfig/network
**** Modify IP (invalid after restart)
ifconfig eth0 192.168.12.22
**** Modify IP (permanently take effect after restart)
vi /etc/sysconfig/network-scripts/ifcfg-eth0
mount **** mounts an external storage device to the file system
mkdir /mnt/cdrom creates a directory to mount
mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom/ Mount device /dev/cdrom to mount point: /mnt/cdrom
*****umount
umount /mnt/cdrom
***** Statistics file or folder size
du -sh /mnt/cdrom/Packages
df -h check disk space
****Shutdown
halt
**** Reboot
reboot
******Configure password-free ssh login between hosts
If A wants to log in to B
Operate on A:
%% first generate a key pair
ssh-keygen (press Enter when prompted)
%% Then copy and append A's own public key to B's authorized_keys file
ssh-copy-id B