linux basic commands 1

 

Linux basic commands (a)

aims

  • Familiar with Linux commonly used commands
  • ls view files
  • Empty clear
  • cd    
  • pwd   
  • mkdir
  • touch
  • rm
  • cp
  • mv
  • tree
  • chmod
  • find
  • grep
  • Redirect
  • Soft connection, hard links
  • compression
  • shutdown
  • reboot
  • who
  • exit
  • passwd
  • sudo

1> View file info: ls

ls English word list of shorthand, whose function is to list the contents of a directory, the user is one of the most commonly used commands, which is similar to the dir command in DOS.

Linux文件或者目录名称最长可以有265个字符,“.”代表当前目录,“..”代表上一级目录,以“.”开头的文件为隐藏文件,需要用 -a 参数才能显示。

ls common parameters:

parameter meaning
-a Print all subdirectories and files in the specified directory, including hidden files
-l Show details of the file as a list
-h -L displays the file size with the humane way

   

FIG meaning of the information listed below:

And the DOS file operation similar to the Unix / Linux system, also allows to simultaneously use special characters refer to multiple file names, these special characters are called wildcards.

Wildcards meaning
* File on behalf of all the characters in the file name
ls te * Find files that begin with te
ls * html Find ending html file
On behalf of any character in the file name
ls ?.c Only to find the first character in any suffix is ​​.c file
ls a.? Only to find only three characters, the first two characters a., The last character of arbitrary files
[] [ "And"] "character set enclosed, that can match any one character in the group." - "is used to represent a range of characters.
[abc] Matches any a, b, c in a
[a-f] Matches any character from a to f within the range of
ls [a-f]* Find a beginning of any character from a to f within the range of file
ls a-f Find the file named af, when the "-" outside in the square brackets lose wildcard role
\ If you want to use as an ordinary wildcard character can be added in front of the escape character. "?" And "*" Do not use escape characters in square brackets will lose the role of wildcards.
ls \ * to File Find the file named * a

2> clear the screen: clear

clear Clears the display functions as (DOS-like function cls clear the screen) on the terminal, can also use the shortcut keys: Ctrl + l ( "l" letters).

3> Switch working directory: cd

When using Unix / Linux, often need to be replaced working directory. cd command helps the user to switch the working directory.Linux所有的目录和文件名大小写敏感

cd can be followed by the absolute path, relative path can be followed. If a directory is omitted, the default switches to the current user's home directory.

command meaning
cd Switch to the current user's home directory (/ home / user directory), user login when the default directory is the user's home directory.
cd ~ Switch to the current user's home directory (/ home / user directory)
cd . Switch to the current directory
cd .. Switch to the parent directory
cd - Enter the directory where the last

 

note:

  • If the path is a path starting from the root, the path in front of the need to add "/", such as "/ mnt", usually enter a directory folder, without the first "/."

4> show the current path: pwd

Use the pwd command to display the current working directory, the command is very simple, direct input pwd can be followed without parameters.

5> Create a directory: mkdir

You can create a new directory using the mkdir command. -P parameter can recursively create directories.

Note that the name of the new directory can not have the current directory in the directory or file with the same name, and create a directory must have write access to the current directory.

6> Delete files: rm

You can delete files or directories by rm. Rm command to be careful, because they can not recover the deleted files. To prevent accidental deletion of files, you can use the rm -i parameter to confirm the file you want to delete one by one.

Common parameters and the meanings shown in the following table:

parameter meaning
-i Interactive way to execution
-f Force delete, ignore the file does not exist, without prompting
-r Contents recursively delete a directory, you must add this parameter when deleting a folder

 

7> Copy: cp

Cp command function is to copy the given file or directory to another file or directory corresponding to the copy command in DOS.

Common options Description:

Options meaning
-a This option is typically used when copying a directory, it retains links, file attributes, and recursively copy the directory, simply, to keep the original file attributes.
-f Existing destination file without prompting
-i Interactive copy, overwrite the destination file before the user is prompted for confirmation
-r If the source file is given a directory file, then cp will copy recursively all directories and files in the directory, the target file must be a directory name.
-v Show copy progress

  

8> mv: move, rename

Users can use the mv command to move a file or directory, you can also rename a file or directory.

Common options Description:

Options meaning
-f Interactive operation is prohibited, if the prompt does not cover
-i 确认交互方式操作,如果mv操作将导致对已存在的目标文件的覆盖,系统会询问是否重写,要求用户回答以避免误覆盖文件
-v 显示移动进度

 

9> 创建文件: touch

用户可以通过touch来创建一个空的文件,demo如下:

touch hello.txt

说明:

  • 则会在当前路径下创建名字为hello.txt的空文件
  • Linux系统中没有严格的后缀(格式),所以创建文件时可以命名为任意的文件名

Guess you like

Origin www.cnblogs.com/ln-xx/p/12076427.html