markdown CLI命令

Posted

tags:

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

#### Combine two lines
```
# Use sed to  combine lines
cat file.txt | sed 'N;s/\n/ /'
```

#### Remove escaped new lines
```
# Use sed to remove escaped newlines
sed -e :a -e '/\\$/N; s/\\\n//; ta'
 
# i.e. Use to count all lines in all sql files
for f in $(ls *.sql | grep -v desc); do cat $f | sed -e :a -e '/\\$/N; s/\\\n//; ta' | wc -l; done | paste -s -d+ - | bc
```

#### Delete old files
```
# Deletes files older than <X> days, where any remainder of 24 hours is discarded (see: http://unix.stackexchange.com/questions/92346/why-does-find-mtime-1-only-return-files-older-than-2-days)
 
find /<path-to-files> -mtime +<X> -exec rm {} \;
 
# Examples
find . -mtime +0 # find files modified greater than 24 hours ago
find . -mtime 0 # find files modified between now and 1 day ago
# (i.e., in the past 24 hours only)
find . -mtime -1 # find files modified less than 1 day ago (SAME AS -mtime 0)
find . -mtime 1 # find files modified between 24 and 48 hours ago
find . -mtime +1 # find files modified more than 48 hours ago
```

#### Rename files in mass
```
# Echo test
for f in 2888430_*.gz; do echo "$f" "2712979_${f#2888430_}"; done
 
# The real thing
for f in 2888430_*.gz; do mv "$f" "2712979_${f#2888430_}"; done
```

#### Read lines of a file
```
while read line; do echo $line; done < file
```

#### Skip lines in a file
```
cat <file> | tail -n+2 (to skip first line)
```

#### Add numbers of a file
```
 cat file_* | cut -f3 -d' ' | paste -s -d + - | bc
 ```

#### Print columns out of order
```
# Columns are 0 based
perl -lane 'print "$F[9] $F[11] $F[6]"'
```

#### Print second to last column
```
awk '{print $(NF-1)}'
```

#### SSH Control Master
```
# Stop control master
ssh -O stop host.example.com
 
# Check control master
ssh -O check host.example.com
```

#### Reset Terminal title
```
# Reset the terminal title
PS1='\[\e]1;\s\$ \W\a\e]2;\u@\h\a\]'"$PS1"
```

#### Reset screen session
```
# Reset a screen session
Ctrl-a Z
```

#### Process start time
```
ps -eo pid,cmd,lstart
```

#### Append to crontab
```
(crontab -l ; echo "0 4 * * * myscript")| crontab -
```

#### Cache command results
```
# CACHE EXPENSIVE OPERATIONS, AND UPDATE PERIODICALLY 
CACHE_FILE=/tmp/cache.file
CACHE_TIMEOUT=300
 
if [ ! -f "$CACHE_FILE" ] || [ $(expr $(date +%s) - $(stat -c %Y "$CACHE_FILE")) -ge $CACHE_TIMEOUT ];  then
	echo "Replace with expensive operation" > "$CACHE_FILE"
fi
 
echo `cat "$CACHE_FILE"`
```

#### MySQL Select to CSV
```
SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n'
FROM users WHERE 1;
 
--SOURCE: http://ariejan.net/2008/11/27/export-csv-directly-from-mysql
```
#### Linux Performance Analysis
```
# See http://www.slideshare.net/RonFulkerson/clipboards/linux-performance-analysis
 
uptime
dmesg -T | tail
vmstat 1
mpstat -P ALL 1
pidstat 1
iostat -xz 1
free -m
sar  -n DEV 1
sar -n TCP,ETCP 1
top
```

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

markdown Firebase CLI命令

markdown Docker CLI命令

markdown Heroku CLI命令

markdown CLI命令

markdown Python - 从cli调用作业命令

从 Vue-cli 开始构建 UI 库到 Markdown 生成文档和演示案例