linux 命令

Last updated on September 15, 2024 pm

🧙 Questions

☄️ Ideas

ls

查看文件夹命令

# -l 每个文件一行
# -h 显示大小
# -a 显示隐藏文件

# 查看每个文件大小
ls -lh 

# 查看所有文件
ls -la

# 按照时间排序
ls -lart # 升序
ls -lt # 降序
# 返回10个文件
ls -lart | head -10
ls -ltr | head -10

ssh

连接服务器命令

# 登录远程服务器
# ssh root@39.103.180.147
ssh ${user}@${host}

Note: 执行的命令必须在当前用户下 或者在/usr/bin/目录下

# 执行远程服务器命令
# ssh ispong@39.103.180.147 "java -version"
ssh ${user}@${host} "${command}"

scp

传输文件命令


# 从本地上传文件到服务器
# scp demo.txt ispong@39.103.180.147:~/
scp ${file} ${user}@${host}:${path}

# 上传文件夹到服务器
# scp ./demo ispong@39.103.180.147:~/
scp -r ${folder} ${user}@${host}:${path}

# 服务器上传文件到本地
#scp ispong@39.103.180.147:~/demo.txt ./
scp ${user}@${host}:${path} ${file}

ln

软连接命令 连接文件路径
Note: 一定要用全局路径

# 软连接
# ln -s /usr/local/bin/kubectl /usr/bin/kubectl
ln -s ${actualPath} ${targetPath}$$

压缩命令

7zip
# 解压7zip
# 注意:-o后面没有空格
sudo yum -y install p7zip 
7za x -y -aoa ./xxx.7z -o./xxx

7za
zip

# 解压
sudo yum -y install unzip
unzip -d /opt/ xxx.zip

# 压缩
zip -r -q -o xxx.zip xxx/
rar
brew install rar 
unrar e xxx.rar

sed

tail -n 7 test
sed -i '1d' dws_alarm_ordered.csv # 删除前几行
sed -i '7,$d' dws_dfg_logsheet_report.csv # 从第7行删除到最后
sed -i '$7' dws_dfg_logsheet_report.csv # 删除倒数几行
sed '5,7d' sed-demo.txt # 删除某些行
sed '1d;5d;9d;$d' sed-demo.txt # 删除不连续的行

echo

# 覆盖写入 
echo "hello" > hello.txt 

# 换行写入 
echo "hello" >> hello.txt

ssh-keygen -t rsa -C 'ispong@outlook.com'

sed

cat test.csv | sed 's/[\\t]/,/g' > ./demo.test
#  拆分文件 看日志
split -n 4 test.txt

linux 命令
https://ispong.isxcode.com/os/linux/linux 命令/
Author
ispong
Posted on
June 7, 2021
Licensed under