markdown Linux命令行

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Linux命令行相关的知识,希望对你有一定的参考价值。

# Linux Commands

|Command|Description|
|---|---|
|cat [filename]|	Display file’s contents to the standard output device (usually your monitor).|
|cd /directory path|	Change to directory.|
|chmod [options] mode filename|	Change a file’s permissions.|
|chown [options] filename|	Change who owns a file.|
|clear|	Clear a command line screen/window for a fresh start.|
|cp [options] source destination|	Copy files and directories.|
|date [options]|	Display or set the system date and time.|
|df [options]|	Display used and available disk space.|
|du [options]	|Show how much space each file takes up.|
|file [options] filename	|Determine what type of data is within a file.|
|find [pathname] [expression]	|Search for files matching a provided pattern.|
|grep [options] pattern [filesname]	|Search files or output for a particular pattern.|
|kill [options] pid|	Stop a process. If the process refuses to stop, use kill -9 pid.|
|less [options] [filename]	|View the contents of a file one page at a time.|
|ln [options] source [destination]|	Create a shortcut.|
|locate filename	|Search a copy of your filesystem for the specified filename.|
|lpr [options]	|Send a print job.|
|ls [options]	|List directory contents.|
|man [command]	|Display the help information for the specified command.|
|mkdir [options] directory	|Create a new directory.|
|mv [options] source destination	|Rename or move file(s) or directories.
|passwd [name [password]]	|Change the password or allow (for the system administrator) to change any password.|
|ps [options]|	Display a snapshot of the currently running processes.|
|pwd	|Display the pathname for the current directory.|
|rm [options] directory|	Remove (delete) file(s) and/or directories.|
|rmdir [options] directory	|Delete empty directories.|
|ssh [options] user@machine	|Remotely log in to another Linux machine, over the network. Leave an ssh session by typing exit.|
|su [options] [user [arguments]]	|Switch to another user account.|
|tail [options] [filename]	|Display the last n lines of a file (the default is 10).|
|tar [options] filename	|Store and extract files from a tarfile (.tar) or tarball (.tar.gz or .tgz). |
|top|	Displays the resources being used on your system. Press q to exit.|
|touch filename	|Create an empty file with the specified name.|
|who [options]	|Display who is logged on.|

## 1. `ls` command: List directory contents.

```html
ls [options] [fd]
```
some examples:

```html
ls /      # list all content of root directory
ls ~      # list all content of home direcotry
ls ..     # one folder back (parent path)
ls ../..  # two folders back

ls -l     # list all contents in long format
ls -a     # list all contents (include hiden file)
ls -al    # list all contents (include hiden file) in long format
ls -lS    # sort file by their size

ls Documents/*.html  # list all the html files in the Documents folder
ls Documents/*.*     # list all the files in the Documents folder

ls -lS > out.txt    # save the list result in a txt file
ls -d */            # list all the directories

man ls    # all the options for ls
```

## 2. `cd` command: Change to directory.

```html
cd /directory path
```

Some examples:
```html
cd /    # change to root direcotry
cd ~    # change to home directory
cd ..   # change to one folder above (parent path)
cd Documents    # change path to Documents

cd My\ Books    # change directory to the folder that its name contain space
cd "My Books"   # change directory to the folder that its name contain space
cd 'My Books'   # change directory to the folder that its name contain space
```
## 3. `cat` command: Display file’s contents

```html
cat [options] [file1] [file2]...
```
1. display text file
2. combine & copy the text file
3. create new text file

Some examples:
```html
cat list.txt    # display content of the file
cat list1.txt list2.txt   # combine two files

cat -b list.txt   # add line number to the blank lines
cat -n list.txt   # add line number to all lines (blank line as well)
cat -s list.txt   # squeeze several blank lines to one blank line
cat -E list.txt   # add '$' to the end of each line
```
## 4. I\O Redirection
```html
output > file   # save output to a file '>'
```

Some examples:
```html
cat > test.txt    # write/overwrite the contents from terminal to the test.txt
cat >> text.txt   # appending the contents from terminal to the test.txt

cat list1.txt list2.txt > test.txt    # combine two files to the test.txt
```
## 5. `mkdir` command: Create a new directory
```html
mkdir /directory path
```

Some examples:
```html
mkdir image   # create a directory (folder) named image

mkdir image/pics    # create a subdirecotry pics in image (image must exsiting)
mkdir -p image/pics   # create a subdirecotry pics in image
mkdir -p image/{pic1,pic2,pic3}   # create several subdirectories (no space between sub-names)
```

以上是关于markdown Linux命令行的主要内容,如果未能解决你的问题,请参考以下文章

markdown 从Linux命令行发送电子邮件(postfix或netcat)

markdown 如何通过命令行在Linux或macOS中更改MySQL root密码

markdown [Linux命令] linux命令#linux #commands

markdown PostgreSQL命令行备忘单

markdown 使用命令行更改标题pdf

markdown 命令行别名