[Top] Summary of common linux commands

chown

Through chmod, you can modify the permissions of a file, as well as modify the file owner and user group. chown is short for change owner. chown -R is used to modify subdirectories and files in a directory at the same time (-R means recursion).
create user

useradd changhf
passwd changhf

Change the user group of the directory /usr/test and all files and subdirectories below it to changhf

su //到root目录下执行下面的命令
chown -R changhf:changhf /usr/test

Change the user group of the directory /home/admin/music and all files and subdirectories below it to admin

chown -R admin:admin /home/admin/music

View the user group a user is in

groups admin //输出admin : admin

View all user groups

cat /etc/group

sed

-i : Modify the contents of the read file directly instead of outputting to the terminal.

sed 's/要被取代的字串/新的字串/g'
//对当前目录下的所有xml文件修改${user.home}为/opt/rocketmq
sed -i 's#${user.home}#/opt/rocketmq#g' *.xml
//$ 代表的是最后一行,a是新增,因此该文件最后新增『# This is a test』!
sed -i '$a # This is a test' abc.txt 

If you have a file with a million lines and you want to add some text on line 100, vim might go crazy! Because the file is too big!

echo

  • Text, variable output
echo "helloworld"  //输出文本
echo $JAVA         //输出变量
  • Use the > command to overwrite the original content of the file and re-enter the content, or create the file if it does not exist.
echo "123" > test
chmod +x test && /bin/bash ./test
// 输出:123
  • Use the >> command to append content to the file, and the original content will be saved.
echo "123" >> test
echo "456" >> test
chmod +x test && /bin/bash ./test
// 输出:
123
456

ls

ls -al
drwxr-xr-x+ 
//d表示目录,-表示文件
//后面是权限rwx,三个为一组,一次为拥有者,同用户组,其他用户组的权限。

Each file and directory under linux has specific permissions, namely the file owner, group and other users.

vim

vim enters a file, type / enter the keyword search, enter the keyword to be searched, press Enter to start the search, n to search down, N to search up; shift + G to enter the end of the file.

scp

//scp 传送中目录下的文件到另一台服务器指定目录
scp /root/abc.sql   root@192.168.0.1:/root  
//scp -r "目标机器地址" "当前物理机地址"
scp -r root@192.168.0.2:/opt/temp /tmp/helloworld

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324519482&siteId=291194637