Analysis of common commands in Linux

Hits: 0

Common Commands in Linux

White: Normal file
Blue: Directory
Red: Compressed package
Green: Executable file

Copy: ctrl + insert
Paste: shift + insert
Clear Screen: ctrl + l
Cancel the current command and re-enter:ctrl + c

1. ls

Syntax: ls[ options ][ directory or file ]
Function: For a directory, this command lists all subdirectories and files under the directory. For files, the filename is listed along with other information.

ls lists the files and directories contained in the current directory, similar to double-clicking a directory on Windows to open it and see what’s in the directory

Here / is a special directory on Linux, called ” [root directory] “, which is equivalent to “this computer” in windows, and these directories here are equivalent to “system files”

Common options:
-aList all files in a directory, including implicit files starting with .
-dDisplay the directory like a file, rather than the files under it. For example: ls -d specifies the directory
-kto indicate the size of the file in k bytes. ls –alk specified file
-lList file details.
-rReverse sort the directory.
-tSort by time.
-RList files in all subdirectories (recursively)

2. pwd

Syntax: pwdFunction 
: Display the current directory of the user

He can tell us which directory we are currently in, because when we use commands, sometimes the directory is more complicated, and it is easy to not remember where we are (lost)

Displays the absolute path corresponding to the current directory. On Windows, it is the absolute path of the path starting with the drive letter. On Linux, the absolute path starts with / (the root directory)

3. cd

In Linux systems, files and directories on disk are organized into a directory tree, and each node is a directory or file.

Syntax: cd directory name 
Function: Change the working directory, change the current working directory to the specified directory

cd followed by a path. This path can be an absolute path or a relative path. cd is equivalent to double-clicking the directory to switch.

Of course, cd ./root can also be abbreviated as cd root

Also:
cd . . : Return to the parent directory
cd ~: enter the user’s home directory
cd -: return to the recently accessed directory

4. touch

Syntax: touch [options]...File... 
Function: The touch command parameter can change the date and time of the document or directory, including the access time and change time, or create a new file that does not exist.

5. cat

Syntax: cat[ options ][ file ]
Function: View the content of the target file
-n can number all lines of output

6. echo

Syntax: echo  [content] > [file name] 
Function: print content to console, can also be used to write files

7. mkdir

Syntax: mkdir [options] dirname.. 
Function: Create a directory named "dirname" in the current directory

Common options:
-p,--parentsIt can be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create those directories that do not exist, that is, multi-level directories can be created at one time.

After creating multiple directories, it may be confusing, you can use the tree command to distinguish
Maybe the first time you hit tree, you will get an error, and you can’t find this command. The command we mentioned earlier is his own, and the tree is a command provided by a third party, and we need to download and install it separately. The command is: yum install tree
this yum is equivalent to an “app store”, called a “package manager”

8. rm

Syntax: rm [-firv]  [dirName/dir] 
Function: delete file or directory

Common options:
-feven if the file attribute is read-only (that is, write-protected), delete it directly,
-iask for confirmation one by one before deleting,
-rdelete the directory and all files under it

The deletion in Linux is really deleted, and the file cannot be recovered. It is not like the windows we often contact, you delete it There’s also a recycle bin afterward to make you regret…

9. mv

Syntax: mv [options] source file or directory target file or directory 
function: the first indicates the file/directory to be moved, the second indicates the target location to be moved, both of these parameters can be absolute path/relative path

Common options:
-f: force means that if the target file already exists, it will not be asked and overwritten directly
-i: if the destination file (destination) already exists, it will be asked whether to overwrite!

10. cp

Syntax : cp  [options] source file or directory target file or directory
Function: Copy files or directories

Common options:
-for –force to forcibly copy a file or directory, regardless of whether the destination file or directory already exists
-ior –interactive to ask the user before overwriting the file.
-rRecursive processing, processing the files and subdirectories in the specified directory together. If the form of the source file or directory does not belong to a directory or symbolic link, it will be treated as a normal file and processed

11. man

Syntax: man [options] Command 
function: View other command help manuals

Common options:
-ksearch online help by keyword ,
numonly find in chapter num
man man, you can see several chapters in the man manual and their meanings

Of course, it is also quite fast to use Baidu to search…

12. less

Syntax: less  [parameters] file
Function: View file content. Not all file content will be loaded into memory at once. Can also be searched

Common options:
-NDisplay line number for each line
n:Repeat previous search (related to / or ?)
q: Exit

When opening a large file, he will not load it all at once, he can manually turn the page

13. head

Syntax: head  [parameters] ... [files] ...
Function: head is used to display the beginning of the file to the standard output. The default head command prints the first 10 lines of the corresponding file.

Common Options:

14. tail

Syntax: tail  [required parameter]  [optional parameter]  [file]  
Function: used to display the content at the end of the specified file. If no file is specified, it will be processed as input information. Commonly viewed log files.

Common options:
-floop read

15. vim

If there is this file, open it, if not, it will automatically create one

At this point, INSERT appears in the lower left corner to enter the insert mode, and you can enter the content.

We want to save and exit and find that there is no x to close. Don’t press it at this time. If you press one ctrl + sto save, it will not work. In vim, ctrl + s is not a save, and it is a shortcut for xshell. key, the function is to freeze the screen (I’m afraid something is too fast to respond, just press ctrl + qit to release the freeze)

1) First return to normal mode from insert mode, press esc

If you want to learn more about vim operation, you can enter his own official “interactive” tutorial: vimtutor, which has a detailed introduction

16. grep

Syntax : grep  [parameters] ... [files] ...
Function: used to find out whether the file contains the specified string, and display the corresponding line

Common options:
--colorHighlight the found results
--include Specify to find certain files
--exclude specified exclude certain files

17. ps

Syntax : ps  [parameters] ...
Function: Used to view the processes running on the current system

ps aux # show all processes on the system
ps aux | grep “process name”
ps aux | grep “process id”

Common options:
aDisplay all processes
uin a terminal Display program status in a user-based format
xDisplay all programs without distinguishing by terminal

18. netstat

Syntax : netstat  [parameters] ...
Function: View the network status on the system

Example:
netstat -anp
netstat -anp | grep “process name”
netstat -anp | grep “port number”

Common options:
-aShow all sockets that are or are not listening
-nShow numeric addresses instead of resolving host, port or username
-pShow PID and name of the process the socket belongs to

Linux permissions

Permissions are used to restrict some of your operations. For example, operations like rm are very dangerous. The greater the ability, the greater the responsibility. Once a novice uses rm, this dangerous operation has a great impact.

This is mainly about files and directories:

File type:
d: Folder
-: Common file
l: Soft link (shortcut similar to Windows)
b: Block device file (such as hard disk, CD-ROM, etc.)
p: Pipe file
c: Character device file (such as screen and other serial devices)
s: Socket file

Basic permissions
r: Indicates readable
w: Indicates writable
x: Indicates executable
-: Indicates no corresponding permissions For
example: rwx: readable, writable, executable, rw-: readable, writable, not executable

Three roles:
The nine English letters after each line are divided into three groups:
For example:
Of course, according to these three groups of roles, you can set different permissions respectively. As for how you want to set it yourself, what you want to set for each group depends on your own wishes and actual needs.

Modify file permissions

Function: set file access permissions
Format: chmod  [parameter] permission filename

You may also like...

Leave a Reply

Your email address will not be published.