1.touch command: used to modify or the time attribute of the directory, including access time and change time. If the file does not exist, the system will create a new file.
Syntax:
touch [-acfm] [-d<Date time>] [-r<Reference documents or directories>] [-t<Date time>] [--help]
Parameter Description:
a: Change the reading time record of the file (atime and ctime)
m: Change the modification time record of the file (mtime and ctime)
d: Set the time and date in a variety of formats
t: Set the file time record in the same format as the date instruction
Example: create a new file
[root@centos7 data]# ls [root@centos7 data]# touch file [root@centos7 data]# ls file [root@centos7 data]# stat file File: 'file' Size: 0 Blocks: 0 IO Block: 4096 regular empty file Device: 803h/2051d Inode: 67 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:default_t:s0 Access: 2022-02-05 09:18:19.259013812 +0800 Modify: 2022-02-05 09:18:19.259013812 +0800 Change: 2022-02-05 09:18:19.259013812 +0800 Birth: -
2. Check the file type with file
[root@centos7 data]# file file file: empty [root@centos7 data]# file file1 file: ASCII text
3. File naming rules:
1) The maximum length of a file name is 255 bytes
2) The maximum length of file name including path is 4095 bytes
3) Blue - > directory green - > executable red - > compressed file light blue - > linked file gray - > other files
4) All characters are valid except / and NUL, but directory names and files using special characters are not recommended. Some characters need to be quoted in quotation marks
4. Change the suffix color of the document
/etc/DIR_COLORS
5.1) generate a file named $abc
[root@centos7 data]# touch '$abc' [root@centos7 data]# ll $abc total 4 -rw-r--r--. 1 root root 0 Feb 5 09:31 $abc
Note: single quotation marks should be used here, not double quotation marks, because double quotation marks will recognize $, and abc will be regarded as a variable, and this variable is undefined, so touch will find a file with an empty name by default
[root@centos7 data]# touch "$abc" touch: cannot touch '': No such file or directory
Similarly, deletion is the same
[root@centos7 data]# rm -rf '$abc' [root@centos7 data]# ls file
2) Generate a file named - A with touch
It is assumed that - a is the parameter of touch, so the following situation will occur
[root@centos7 data]# touch -a touch: missing file operand Try 'touch --help' for more information.
Therefore, we need to change our thinking and use -- add a space to indicate that there is no parameter:
[root@centos7 data]# touch -- -a [root@centos7 data]# ls -a file
Of course, delete it. Similarly:
[root@centos7 data]# rm -rf -- -a [root@centos7 data]# ls file
6. File types under Linux
1) - ordinary documents
2) d directory file
3) Block b equipment
4) c character device
5) l symbolic link file
6) p pipe file (pipe)
7) s socket file (socket)
7. Display current working directory
1) Each SHELL and system process has a current working directory
2)CWD: current work direcctory
3) Displays the absolute path of the current SHELL CWD
pwd(printing working directory):
-P shows the real physical path - L shows the link path (default)
[root@centos7 dir1]# pwd -P /data/dir1 [root@centos7 dir1]# pwd -L /data/dir1
8. View file status
1)stat
2) Three timestamps:
Access time: access time, atime, to read the contents of the file
Modify time: modify time, mtime, change file content (data)
Change time: change time, ctime and metadata
[root@centos7 dir1]# stat /data/dir1 File: '/data/dir1' Size: 6 Blocks: 0 IO Block: 4096 directory Device: 803h/2051d Inode: 67 Links: 2 Access: (0755/drwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root) Context: unconfined_u:object_r:default_t:s0 Access: 2022-02-05 09:57:53.018038076 +0800 Modify: 2022-02-05 09:57:53.018038076 +0800 Change: 2022-02-05 09:57:53.018038076 +0800 Birth: -
9. Absolute and relative paths
1) Absolute path: start with a forward slash and complete the location path of the file. It can be used whenever you want to specify a file name
2) Relative path: do not start with a slash. Specify the location relative to the current working directory or a directory. You can specify a file name as a short form
3)basename
[root@centos7 ~]# basename /etc/lvm/cache cache
4)dirname
[root@centos7 ~]# dirname /etc/lvm/cache /etc/lvm
10 change directory
1) cd (change directory):
Use absolute or relative paths:
[root@centos7 ~]# cd /etc/lvm/cache
[root@centos7 cache]#
[root@centos7 ~]# cd ../etc/lvm/cache
[root@centos7 cache]#
Switch to parent directory
[root@centos7 etc]# cd .. [root@centos7 /]# cd .. [root@centos7 /]# pwd / [root@centos7 /]# cd ../.. [root@centos7 /]# pwd /
Switch current user home directory
[root@centos7 /]# cd [root@centos7 ~]# pwd /root
Switch to previous working directory
[root@centos7 ~]# cd - / [root@centos7 /]# pwd /
2) Option - P
3) Relevant environment variables:
PWD: current working path
[root@centos7 /]# echo $PWD /
OLDPWD: last directory path
[root@centos7 /]# echo $OLDPWD /root
11. List the contents ls
1) List the contents of the current directory or specify a directory
2) Usage:
ls [OPTIONS] [FILE_OR_DIRS]
3) Example:
ls -a contains hidden files
[root@centos7 ~]# ls -a . .bash_profile .cache Desktop .esd_auth .mozilla Public .viminfo .. .bash_profiley .config Documents .ICEauthority Music Templates y .bash_history .bashrc .dbus Downloads .local Pictures Videos
ls -l displays additional information
[root@centos7 ~]# ls -l total 4 drwxr-xr-x. 2 root root 6 Feb 3 21:00 Desktop drwxr-xr-x. 2 root root 6 Jan 1 01:28 Documents drwxr-xr-x. 2 root root 6 Jan 1 01:28 Downloads drwxr-xr-x. 2 root root 6 Jan 1 01:28 Music drwxr-xr-x. 2 root root 6 Jan 1 01:28 Pictures drwxr-xr-x. 2 root root 6 Jan 1 01:28 Public drwxr-xr-x. 2 root root 6 Jan 1 01:28 Templates drwxr-xr-x. 2 root root 6 Jan 1 01:28 Videos -rw-r--r--. 1 root root 178 Feb 3 21:31 y
ls -R directory recursion
[root@centos7 data]# ls -R .: dir1 ./dir1: f1
ls -ld directory and symbolic link information
[root@centos7 ~]# ls -ld dr-xr-x---. 15 root root 4096 Feb 5 09:22 .
ls -1 file line display
[root@centos7 ~]# ls -1 Desktop Documents Downloads Music Pictures Public Templates Videos
ls -S files are sorted from large to small
[root@centos7 ~]# ls -S y Desktop Documents Downloads Music Pictures Public Templates Videos
ls -t files sorted by mtime
[root@centos7 ~]# ls -t y Desktop Documents Downloads Music Pictures Public Templates Videos
ls -u with - t option, display and sort by atime, from new to old
[root@centos7 ~]# ls -ut Desktop Documents Downloads Music Pictures Public Templates Videos y
ls -U display by directory storage order
[root@centos7 ~]# ls -U Desktop Downloads Templates Public Documents Music Pictures Videos y
ls -X sort by file suffix
[root@centos7 ~]# ls -X Desktop Documents Downloads Music Pictures Public Templates Videos y
12.df command: the command is used to display the current file system disk usage on Linux system
Syntax:
df [option] ... [file]
[root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 915780 0 915780 0% /dev tmpfs 931512 0 931512 0% /dev/shm tmpfs 931512 10640 920872 2% /run tmpfs 931512 0 931512 0% /sys/fs/cgroup /dev/sda2 52403200 5029468 47373732 10% / /dev/sda3 31441920 33024 31408896 1% /data /dev/sda1 1038336 184100 854236 18% /boot tmpfs 186304 32 186272 1% /run/user/0 /dev/sr0 9961428 9961428 0 100% /run/media/root/CentOS 7 x86_64
13. Shortcut key of bash (understand)
1) ctrl + l clear the screen, which is equivalent to the clear command
2) ctrl + o executes the current command and redisplays the command
3) ctrl + s block screen output, lock
4) ctrl + q allow screen entry
5) ctrl + c terminate command
6) ctrl + z suspend command
7) ctrl + a cursor moves to the beginning of the command line, which is equivalent to the Home key
8) ctrl + e cursor moves to the End of the command line, which is equivalent to the End key
9) ctrl + f cursor moves one character to the right
10) ctrl + b move the cursor one character to the left
11) alt + f cursor moves one word end to the right
12) alt + b moves the cursor one word to the left
13) alt + r deletes the entire current row
14) ctrl + xx cursor moves between the beginning of the command line and the cursor
15) ctrl + u deletes from the cursor to the beginning of the command line
16) ctrl + k deletes from the cursor to the end of the command line
17) ctrl + w delete from the cursor to the left to the beginning of the word
18) ctrl + d deletes a character at the cursor
19) alt + d is deleted from the cursor to the end of the word
20) ctrl + h deletes a character in front of the cursor
21) ctrl + y paste the deleted character behind the cursor
22) alt + c changes the initial capitalized word from the cursor to the right
23) alt + u start at the cursor and change the word on the right to uppercase
24) alt + l # start at the cursor and change the word on the right to lowercase
25) ctrl + t exchanges the position of the cursor and the previous character
26) alt + t , exchange the position of the cursor and the previous word
27) alt + N prompts to enter the specified character, and then repeat the character N times
Note: alt combination shortcut often conflicts with other software