What's fun here in Kangkang
Linux basic knowledge study notes
File processing commands
Command format and directory processing command ls
Command format: command [
-option ]] [parameter] Example: ls -la /etc
Description:
- Individual commands do not follow this format
- When there are multiple options, they can be written together
- Simplified and complete options
such as: -a is equal to -all
Directory processing command: ls
Command name: ls
command English original meaning:
path of list command: /bin/ls
execution authority: all users
Syntax: ls option [-ald] [file or directory]
- -a show all files, mainly show hidden files (all)
- -l detailed information display (long)
- -d only view the specified directory attributes
- -h Humanized display (unit) (human)
- -ii node, express the index number of the file
The first option of file information: -rw-r–r--
- The first digit-indicates the file type (-: binary file d: directory l: soft link file)
- The last three parts are: u: owner g: belong to group o: others
- Letter meaning: r: read w: write x: execute
Directory processing commands
Directory processing command: mkdir
The original meaning of the command in English: make directories The
path where the command is located: /bin/makir
Execution permission: all users
Syntax: makir -p [directory name]
Function description: Create a new directory -p: Recursively create
Recursive creation refers to the continuous creation of various subdirectories
Directory processing command: cd
Command English original meaning: change directory
command path: shell built-in command
execution authority: all users
Syntax: cd [directory]
Function description: switch directory
Example:
- cd /tem/Japan switch to the specified directory
- cd… Back to the upper level directory (...is the upper level directory,. is the current directory)
Directory processing command: pwd
The original meaning of the command in English: the
path of the print working directory command: /bin/pwd
Execution permission: all users
Syntax: pwd (type this command directly on the command line)
Function description: display the current directory
Example:
$ pwd
Directory processing command: rmdir (not used much)
The original meaning of the command in English: the
path where the remove empty directory command is located: /bin/rmdir
Execution authority: all users
Syntax: rmdir[directory name]
Function description: deleteairDirectory
example: $ rmdir /tmp/Hit/sushe
Directory processing command: cp
The original meaning of the command in English:
the path where the copy command is located: /bin/cp
Execution permission: all users
Syntax: cp -rp [original file or directory] [target directory]
-r Copy directory (when it is a directory, use -r, that is, the object is not one File)
-p retain file attributes (if the original file attributes are retained, use -p for time)
Function description: copy files or directories
Note:
You can copy multiple files to the specified directory
at the same time, and you can modify the file name while copying the past. Change to the desired name at the end
Directory processing command: mv
The original meaning of the command in English:
the path where the move command is located: /bin/mv
Execution permission: all users
Syntax: mv [original file or directory] [target directory] or mv [file original name] [file new name]
Function description: cut file, rename (The so-called rename is in the same directory)
Directory processing command: rm
The original meaning of the command in English:
the path where the remove command is located: /bin/rm
Execution authority: all users
Syntax: rm -rf [file or directory]
-r delete a directory (you must add -r when deleting a directory)
-f mandatory execution (do not ask whether to delete )
Function description: cut files and rename (the so-called rename is in the same directory)
File processing commands
File processing command: touch
Command path: /bin/touch
Execution permission: all users
Syntax: touch [file name/path to file name]
Function description: create an empty file
Example: $ touch SLAM.list
Note: Do not use spaces as the file name, otherwise it must be enclosed in double quotes
File processing command: cat
Command path: /bin/cat
Execution authority: all users
Syntax: cat -n [file name]
Function description: Display file content, that is, browse file content
-n Display line number
Example:
$ cat /etc/issue
$ cat -n /etc/services
The tac command can display the contents of the file in reverse, the usage is exactly the same as cat, but it does not support -n
File processing command: more
Command path: /bin/more
Execution authority: all users
Syntax: cat [file name]
- (Space) or f to page
- (Enter) newline
- q or Q exit
Function description: display file content in pages
Example:
$ more /etc/services
File processing command: less
Command path: /usr/bin/less
Execution authority: all users
Syntax: less [File name]
Function description: Display file content in pages (page up)
- The operation is similar to more, you can use the up key/pageup to page up
- In the less interface, you can type a /, and then type the content you want to search
- After searching, you can use n to search down (next)
Example:
$ less /etc/service
File processing command: head
Command path: /usr/bin/head
Execution authority: all users
Syntax: head [file name]
Function description: Display the first few lines of the file, the first ten lines are displayed by default
-n specifies the number of lines
Example:
$ head -n 20 / etc/services
The tail command can display the last n lines, -f can display dynamically
Link command
File processing command: ln
The original meaning of the command in English:
the path where the link command is located: /bin/ln
Execution permission: all users
Syntax: ln -s [original file] [target file]
-s create a soft link, otherwise it is a hard link
Function description: generate a link file
Example:
$ ln -s /etc/issue /tmp/issue.soft
instruction analysis: the
soft link is equivalent to the shortcut under win. It is small and has all rwx permissions. The ls display will appear at the beginning, and there is an arrow pointing to the original file
hard The link is equivalent to a shadow file, similar to cp, but the operation after cp will not affect the original file, but the hard link will affect the
hard link is the same as the i node of the original file, and the file after cp is different. The
hard link cannot cross partitions, and only For catalog use
Authority management commands
Authority management command: chmod
Command name: chmod
command English original meaning: change the permissions mode of a file
command path: /bin/chmod
execution permissions: all users
Syntax:
chmod [{ugoa}{±=}{rwx}] [file or directory]
chmod [ mode=421] [File or directory]
-R Recursive modification
Function description: Change the permissions of files or directories.
Instruction analysis:
You can modify permissions for different types of users at the same time, separated by commas (±= method is not commonly used)
Recursive modification refers to modifying the permissions of all files in the directory
Other authority management commands
Authority management command: chown
The original meaning of the command in English: change file ownership The
path where the command is located: /bin/chmod
Execution permission: all users
Syntax: chown [user] [file or directory]
Function description: Change the owner of a file or directory
Example: $ chown llh study (change file The owner of study is llh)
Change file permissions, only the owner or administrator root
In a directory, you can use "useradd [file name]" to create a new owner, which is related to who the owner belongs to before the group involved
Authority management command: chgrp
The usage method is exactly the same as chown
There is also a command to add a group, namely groupadd
Authority management command: umask
The original meaning of the command in English: the user file-creation mask
command path: Shell built-in command
Execution authority: all users
Syntax: umask [-S]
-S Display the default permissions of new files or directories in rwx form.
Function description: display and set the file Default permissions
Example: $ umask -S
When a user creates a file, the group he belongs to is the user's default (default) group
Any newly created files in the Linux system have no executable permissions
File search command
File search command: find
Try not to use search commands, which take up too much resources
Command path: /bin/find
Execution permission: all users
Syntax: find [Search range] [Match condition]
Function description: File search
Example:
$ find /etc -name init
Find the file init in the directory /etc.
If you change init to init , all the letters containing the four letters of init will be found, otherwise you can only find the file called init
which has the * symbol, and you can find other characters here
If the name is changed to init???, you will find a file starting with init, followed by three letters
Strictly case sensitive
-name changed to -iname will no longer case-sensitive search
$ find / -size +204800
Find files larger than 100Mb in the root directory. To
convert the file size into data blocks: 1 data block = 512 bytes = 0.5k
+ n: greater than -n: less than n: equal to
$ find /home -user lihaha
Find the file
whose owner is lihaha in the root directory- group Find according to the group it belongs to
$ find /etc -cmin -5
Find files and directories whose attributes have been modified within 5 minutes under /etc
-amin: access time (access)
-cmin: file attribute (change)
-mmin: file content (modify)
$ find /etc -size +163840 -a -size -204800
Find files larger than 80Mb and smaller than 100Mb under /etc
-a: Both conditions are met at the same time
-o: Both conditions are met either
find /etc -size +163840 -a -type f
Find files larger than 80Mb in the /etc directory, -type finds according to the file type
f: file d: directory l: soft link file
find /etc -name inittab -exec ls -l {} ;
Find the inittab file under /etc and display its detailed information
-exec/-ok command {};
is a fixed format, that is, the following command
is executed after the file is found -exec is directly displayed, -ok is found for each The target is asked to confirm-
inum according to the i-node search,
can be deleted according to the i-node
Other file search commands
Quick database file search: locate
The path where the command is located: /usr/bin/locate
Execution permission: all users
Syntax: locate file name
Function description: Find files in the file database
locate you
The system has created a database and the search speed is very fast
However, for newly created files, if the database is not updated, there is no such problem
with find. Use the following command to update the file database:
updatedb
The /tmp
directory is not in the file database and cannot be found. It
can be used and is -i
no longer case sensitive.
locks -i init
Command path search command: which
Execution authority: all users
Syntax: which command name
Function description: search the directory where the command is located and alias information
which cp
The location of the cp directory and the alias of the cp command will be displayed
Command directory and help document search command: whereis
Command path: /usr/bin/whereis
Execution authority: all users
Syntax: whereis [command name]
Function description: Search command directory and help document path
whereis ls
To be continued! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !
Tips
clear/Ctrl+l: can clear traces in the command line
Ctrl+c: terminate the current operation of the command line
Shortcut key Ctrl+h: open this in a folder, you can see the hidden files in the folder
tree: display the current directory Directory structure