2021-10-13-linux Foundation

See what types of shell interpreters are available on this machine:
[root@sanchuang huahsan]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/usr/bin/tmux
/bin/tmux

sh It's a very old interpreter, more than bash Have a sense of history, No bash Easy to use 
[root@sc ~]# sh switch to sh interpreter
sh-4.4# Switch bash to bash interpreter
[root@sc ~]# 

Switching between sh and bash

[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-gmgpy7p8-1645066292674) (C: \ users \ Xixi \ appdata \ roaming \ typora user images \ image-20211207210154079. PNG)]

ls view the contents of the folder

-l display details
-a display all files and folders, including hidden files And
-A displays all files and folders, including hidden files, not displayed And
-h is displayed in units that can be recognized by human -- "K,M,G,T,P"
-h, --human-readable
with -l and -s, print sizes like 1K 234M 2G etc.
-t sort according to the creation time of the file. The last created file is in the front time
The default is the ASCII code value of the first letter of the file name, which is arranged in ascending order
-r according to the ASCII code value of the initial letter of the file name, it is arranged in descending order -- reverse
-d displays the attributes of the directory itself, not the attribute directory of the folder or file inside

  • [root@sc wuxia]# mkdir   .song hides files or folders in linux to start
    [root@sc wuxia]# ll
     Total consumption 16
    -rw-r--r--.  1 root root  144 10 September 13:54 create_dir.sh
    -rw-r--r--.  1 root root  103 10 October 13:04 create_user.sh
    -rw-r--r--.  1 root root   75 10 October 13:00 del_dir.sh
    drwxr-xr-x. 32 root root 4096 10 October 13:00 huashan
    
    d The type of representative file is directory (folder)  directory
    - The type of representative file is ordinary file
    rwxr-xr-x Delegate authority   r read read     w write write   x Execute (run) execute
     32 Number of links to the file-->How many files in the folder are related to it
    
    root  1st root Representative is root user
    root   2nd root Representative is root group
    4096 File size bytes
    	Byte runout  bytedance  -->Company name  -->Product tiktok today's headlines, watermelon videos, etc.    Tik Tok 
    
    	byte byte -->B  -->1 English letters are stored in the unit where the computer consumes 1 byte and 1 Chinese character consumes 3 bytes to store data
    	1kB  = 1024B
    	1MB =1024KB 
    	1GB=1024MB
    	1TB=1024GB
    	1PB=1024TB
    	1EB=1024PB
    	k-->M-->G-->T-->P-->E
    	10 October 13:00 Creation time of the file
    

    ASCII (American Standard Code for information interchange) is a set of computer coding system based on Latin alphabet, which is mainly used to display modern English and other Western European languages.

/Device stores device files device mouse, keyboard, display, disk, network card and other hardware will have a file corresponding to it – "everything in linux is a file"

brw-rw----. 1 root disk 8, 1 October 11 09:21 sda1 - "disk device file -" disk data storage related device file block block

crw–w----. 1 root TTY 4, 0 October 11 09:21 tty0 -- "character display file character character character

lrwxrwxrwx. 1 root 15 October 11 09:21 stderr - > / proc / self / FD / 2 -- "link file: shortcut link

===
What are the file types?
d folder (directory)
-Ordinary documents
l link file link
c character device file character
b device file block

===

[root@sc wuxia]# mkdir  hunan
[root@sc wuxia]# Ln - s ABCD create a symbolic link to ABCD
                         source file     Link file
-s   symbol  Symbol
    Symbolic link=windows Shortcut in
    Symbolic link=Soft link


[root@sc wuxia]# ll xiang
lrwxrwxrwx. 1 root root 5 10 November 13:18 xiang -> hunan
[root@sc wuxia]# 

[root@sc wuxia]# cd xiang/
[root@sc xiang]# pwd
/wuxia/xiang
[root@sc xiang]# pwd -P 
/wuxia/hunan
[root@sc xiang]# 

       -P, --physical Show real physical path
              avoid all symlinks
=====
practice:
	1.new directory/10-13 folder
	2.get into/10-13 Folder, create a new folder in it hunan  hubei  .shenzheng
	3.Displays the details of the files in the current folder, including hidden files, but not displayed.and..
	4.Displays the size of the folder in units that humans can recognize
	5.Displays the files in the current folder in descending order
	6.stay hunan New folder under directory changsha  yueyang zhuzhou 
	7.display hunan The detailed information of the directory itself is not displayed
	8.to hubei Create a symbolic link file called e
	[root@sc 10-13]# ln  -s hubei  e

	9.get into e Folder, display the current path (to display the real physical path)
	10.use vim Editor in/10-13 Create a new file in the directory sc.txt  ,Define the content
	11.display/10-13 Details in folder
=====
[root@sc 10-13]# mkdir -p hunan/{changsha,yueyang,zhuzhou}  
-p If the file exists, no error will be reported
   If the file does not exist, create a new one

[root@sc 10-13]# mkdir guangdong/{guangzhou/{baiyun,fanyu,huadu,tianhe},qingyuan,maoming,shaoguang,dongguang,zhuhai} -p  
[root@sc 10-13]# mkdir hejin{1..10}
[root@sc 10-13]# rm  -rf  guangdong
rm Commands for deleting files and folders  remove
   rm - remove files or directories
     -f, --force  force
              ignore nonexistent files and arguments, never prompt
     -r, -R, --recursive recursion
              remove directories and their contents recursively  -->Zhulian nine Nationalities

-rf  Forcibly delete all contents in folders and subfolders without giving any reminders

rm  It is a dangerous command, because the deleted content will not enter the recycle bin. The system with the default character interface has no recycle bin

Reminder: when deleting things at work, ask yourself and leaders again and again if you still need them? Is there a backup?

Wildcard:

*Represents any character
? Represents an arbitrary character

[root@sc 10-13]# mkdir  aa ab abc abd abcd abce
[root@sc 10-13]# ls
aa  ab  abc  abcd  abce  abd  e  huangshan  hubei  hunan  jiangxi  jiujiang  lushan  sc.txt
[root@sc 10-13]# rm -rf a?
[root@sc 10-13]# ls
abc  abcd  abce  abd  e  huangshan  hubei  hunan  jiangxi  jiujiang  lushan  sc.txt
[root@sc 10-13]# rm -rf a??
[root@sc 10-13]# 
[root@sc 10-13]# touch  feng{1..100}.txt new empty file
[root@sc 10-13]# rm  -rf  *.txt
[root@sc 10-13]# rm -rf feng??.txt


[root@sc 10-13]# rm -rf * deletes all files and folders in the current directory, but does not delete hidden files

Never use it or kill it
 It will cause all files in the system to be deleted
[root@sc 10-13]# cd  /
[root@sc /]# RM - RF * relative path

[root@sc /]# rm -rf / * absolute path

touch command

Purpose:
	1.Create a new empty file. If the file does not exist, create a new one

    2.Update file creation time

.txt   yes windows Text file in  -->There are text files, no pictures, no sound and video

[root@sc wuxia]# touch   tang.txt

[root@sc wuxia]# ll tang.txt 
-rw-r--r--. 1 root root 0 10 September 13-15:37 tang.txt
[root@sc wuxia]# date
2021 Wednesday, 13 October 2015:40:46 CST
[root@sc wuxia]# touch tang.txt
[root@sc wuxia]# ll tang.txt 
-rw-r--r--. 1 root root 0 10 September 13-15:41 tang.txt
[root@sc wuxia]# 

du is used to view the size of a file or folder

  du - estimate file space usage  

-s  Size after summary  sum
-h  Display in a human recognizable format  ,K  M G
-a  Count the size of each file  all




[root@sc boot]# du -sh grub2
5.5M	grub2
[root@sc boot]#
[root@sc boot]# du -sh vmlinuz-4.18.0-193.el8.x86_64 
8.6M	vmlinuz-4.18.0-193.el8.x86_64
[root@sc boot]# 


[root@sc boot]# ls -l -h
 134 total dosage M
-rw-r--r--. 1 root root 184K 5 August 2020 config-4.18.0-193.el8.x86_64
drwxr-xr-x. 3 root root 4.0K 10 September 12:02 efi
drwx------. 4 root root 4.0K 10 September 12:07 grub2
-rw-------. 1 root root  66M 10 September 12:06 initramfs-0-rescue-57d1329660644355897d0b9ff095549c.img
-rw-------. 1 root root  29M 10 September 12:08 initramfs-4.18.0-193.el8.x86_64.img
-rw-------. 1 root root  19M 10 September 14:40 initramfs-4.18.0-193.el8.x86_64kdump.img
drwxr-xr-x. 3 root root 4.0K 10 September 12:04 loader
drwx------. 2 root root  16K 10 September 12:01 lost+found
-rw-------. 1 root root 3.8M 5 August 2020 System.map-4.18.0-193.el8.x86_64
-rwxr-xr-x. 1 root root 8.6M 10 September 12:05 vmlinuz-0-rescue-57d1329660644355897d0b9ff095549c
-rwxr-xr-x. 1 root root 8.6M 5 August 2020 vmlinuz-4.18.0-193.el8.x86_64
[root@sc boot]# du -sh grub2/
5.5M	grub2/
[root@sc boot]# 

How to view the file size:
	1.du  -->recommend
		du -sh  The size of the folder is counted

	2.ll -h -->Cannot automatically count the size of the entire folder

cp copy files and folders

Operations on files
	1.Copy a single file
	2.Copy multiple files
[root@sc lianxi]# cp  changsha.txt  hunan
                       source file       destination
[root@sc lianxi]# cp --help
 Usage: cp [option]... [-T] Source file destination file
 Or: cp [option]... source file... catalogue
 Or: cp [option]... -t Directory source file...

[root@sc lianxi]# cp  /etc/hosts   /lianxi

[root@sc lianxi]# cp  /etc/passwd   .   Copy the / etc / passwd file to the current directory, or is it called passwd
=====

[root@sc lianxi]# cp changsha. Txt sc.txt passwd Shanghai copy multiple files to a folder
                      The front is the source file              Destination directory

[root@sc lianxi]# cp  /etc/hosts   /etc/passwd   /lianxi/hunan
======

Copy, paste and rename in one step
[root@sc lianxi]# cp changsha.txt  cs.txt will change Sha Copy and paste the txt file into the current directory and change its name to CS txt

Actions on folders
	1.Copy a single folder
	2.Copy multiple folders
    3.-r  Recursive copy, copy the sub files and sub folders in the folder
[root@sc lianxi]# cp -r hunan shanghai
[root@sc lianxi]#
[root@sc lianxi]# cp -r hunan shanghai
cp: Overwrite'shanghai/hunan/changsha.txt'? y
cp: Overwrite'shanghai/hunan/hosts'? y
cp: Overwrite'shanghai/hunan/passwd'? y
[root@sc lianxi]# cp -r hunan shanghai
cp: Overwrite'shanghai/hunan/changsha.txt'? y
cp: Overwrite'shanghai/hunan/hosts'? y
cp: Overwrite'shanghai/hunan/passwd'? y
cp: Overwrite'shanghai/hunan/feng1.txt'? y
cp: Overwrite'shanghai/hunan/feng2.txt'? y
cp: Overwrite'shanghai/hunan/feng3.txt'? y
cp: Overwrite'shanghai/hunan/feng4.txt'? y
cp: Overwrite'shanghai/hunan/feng5.txt'? y
cp: Overwrite'shanghai/hunan/feng6.txt'? ^C
[root@sc lianxi]# /usr/bin/cp -r hunan shanghai

[root@sc lianxi]# CP / boot / Lianxi - R use of absolute path
[root@sc lianxi]# cp /wuxia/  . -r mixed use of relative path and absolute path
[root@sc lianxi]# CP / Wuxia / / boot / etc / passwd / Lianxi / Hubei - R copy of multiple folders and files
[root@sc lianxi]# cp hunan  xiang  -r

Coverage issues
[root@sc lianxi]# cp changsha.txt hunan
cp: Overwrite'hunan/changsha.txt'? y
[root@sc lianxi]#

Why cp Will the command give an override reminder?

[root@sc lianxi]# alias
alias cp='cp -i'

man cp Effect of
       -i, --interactive interactive
              prompt before overwrite  Remind before overwriting
 Solve the problem of reminder:
	1.Cancel alias  -->Not recommended
	[root@sc lianxi]# unalias cp
	2.use cp Absolute path of the command -->recommend
	[root@sc lianxi]# /usr/bin/cp  changsha.txt hunan

shell The interpreter is right linux When the command is interpreted, it is preferred to check whether there is an alias setting. If there is an alias, it is preferred to use the alias

[root@sc lianxi]# cp changsha.txt hunan
cp: Overwrite'hunan/changsha.txt'? y
[root@sc lianxi]# which cp view the path where the cp command is stored
alias cp='cp -i'
	/usr/bin/cp
[root@sc lianxi]# 

file command view type

[root@sc lianxi]# file boot view the type of file
boot: directory
[root@sc lianxi]# file hosts
hosts: ASCII text
[root@sc lianxi]#
Exercise 3:
	1.Create a new directory under the root directory wuxia
	2.Then in wuxia New under directory tianshan,hengshan,taishan,songshan
	3.stay tianshan Create a new empty file in the directory qijian,stay hengshan New directory empty file yilin,stay taishan New under directory xiaodeng
	4.copy/etc/hosts reach songshan Directory, copy hengshan Directory to songshan Under the directory
	5.see taishan File type, and then view taishan Size of directory
	6.delete tianshan Directory, and then copy songshan Directory to taishan Directory called shaolin
 Exercise 4:
	1.Create a new folder under the root directory jindafu
	2.take/etc/hosts Copy files to jindafu
	3.take/boot Copy directory to jindafu
	4.take/etc/passwd Copy files to jindafu Lower boot In the catalogue
	5.stay jindafu New in directory liufu Directory, and then jindafu Directory boot Copy directory to liufu Under the directory
	6.delete liufu catalogue
	7.copy/etc/hosts File to jindafu,Do not give coverage reminder?
	[root@sanchuang jindafu]# /usr/bin/cp /etc/hosts .
	8.take/etc/hosts Copy files to jindafu Directory called huojianhua
	9.take/home/Copy all files and folders in the directory to/jindafu Under the directory

Exercise 4:
1. Create a new folder under the root directory
2. Copy the / etc/hosts file to jindafu
3. Copy the / boot directory to jindafu
4. Copy the / etc/passwd file to the boot directory under jindafu
5. Create a liufu directory in the jindafu directory, and then copy the boot directory under the jindafu directory to the liufu directory
6. Delete liufu directory
7. Copy the / etc/hosts file to jindafu without giving overwrite reminder?
[root@sanchuang jindafu]# /usr/bin/cp /etc/hosts .
8. Copy the / etc/hosts file to the jindafu directory, which is called huojianhua
9. Copy all files and folders in / home / directory to / jindafu directory

Keywords: Linux Operation & Maintenance bash

Added by mrfruits on Thu, 17 Feb 2022 05:00:39 +0200