linux常用命令

帮助命令

help 指令
例如
[root@moyue01 ~]# help pwd
pwd: pwd [-LP]
    打印当前工作目录的名字。
    
    选项:
      -L        打印 $PWD 变量的值,如果它命名了当前的
        工作目录
      -P        打印当前的物理路径,不带有任何的符号链接
    
    默认情况下,`pwd' 的行为和带 `-L' 选项一致
    
    退出状态:
    除非使用了无效选项或者当前目录不可读,否则
    返回状态为0。
----------------------------------------------------------------------------------
[root@moyue01 ~]# man pwd
man 指令
PWD(1)                                      User Commands                                     PWD(1)

NAME
       pwd - print name of current/working directory
----------------------------------------------------------------------------------
[root@moyue01 ~]# info pwd
File: coreutils.info,  Node: pwd invocation,  Next: stty invocation,  Up: Working context

19.1 'pwd': Print working directory
===================================
#man
f或者回车为向下翻页
b为向上翻页
enter为下一行



创建,移动,拷贝,删除,创建链接,写入

touch filename.....
    创建普通文件
[root@moyue01 data]# touch file
[root@moyue01 data]# ll
-rw-r--r--. 1 root root     0 11月 29 18:46 file
mkdir [-p] dirname.....
    创建文件夹
[root@moyue01 data]# mkdir dir
[root@moyue01 data]# ll
drwxr-xr-x. 2 root root     6 11月 29 18:47 dir
[root@moyue01 data]# mkdir file
mkdir -p dirpath 
[root@moyue01 data]# mkdir -p ./dir/usr/home/adr
[root@moyue01 data]# ll
drwxr-xr-x. 3 root root    17 11月 29 18:57 dir
删除文件/目录
[root@moyue01 data]# touch file
[root@moyue01 data]# rm file
rm:是否删除普通空文件 "file"?y
rm [-rf] filename......
[root@moyue01 data]# mkdir dir
[root@moyue01 data]# rm dir
rm: 无法删除"dir": 是一个目录
想要删除可以加上-r    #表示递归删除
[root@moyue01 data]# rm -r dir
rm:是否进入目录"dir"? y
rm:是否进入目录"dir/usr"? y
rm:是否进入目录"dir/usr/home"? y
rm:是否删除目录 "dir/usr/home/adr"?y
rm:是否删除目录 "dir/usr/home"?y 
rm:是否删除目录 "dir/usr"?y
rm:是否删除目录 "dir"?y
-f为强制系统不会提示
-----------------------------
注意rm -rf /*千万不要用
后果如下
[root@moyue01 data]# rm -rf /*
rm: 无法删除"/sys/fs/cgroup/devices/system.slice/sshd.service/cgroup.event_control"
^Z[1]+  已停止               rm -i -rf /*
[root@moyue01 data]# ll
-bash: /usr/bin/ls: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: 没有那个文件或目录
根目录递归删除但是不会删除隐藏文件
-----------------------------
[root@moyue01 data]# rm -rf dir
移动文件或文件目录
mv [OPTTON]... Source... DIRECTORY
[root@moyue01 data]# ll
drwxr-xr-x. 2 root root     6 11月 29 19:22 dir
-rw-r--r--. 1 root root     0 11月 29 19:22 file
[root@moyue01 data]# mv file dir
[root@moyue01 data]# ll
drwxr-xr-x. 2 root root    18 11月 29 19:22 dir
mv可用来更名
drwxr-xr-x. 2 root root    18 11月 29 19:22 dir
[root@moyue01 data]# mv dir dvm & ll
drwxr-xr-x. 2 root root    18 11月 29 19:22 dvm
cp拷贝文件或者目录
cp [-r] source....directory
[root@moyue01 data]# cp file1 file2 file3 dir1
跟mv差不多
[root@moyue01 data]# cp dir1 ./dir
cp: 略过目录"dir1"
需要加上-r才可以拷贝目录
ln创建软连接&硬链接
ln[-s] filename newfilename
软连接
[root@moyue01 data]# ln -s file1 f2
[root@moyue01 data]# ll
硬链接 #不能链接目录
[root@moyue01 data]# ln file1 f1
-rw-r--r--. 2 root root  0 11月 26 14:19 f1
软连接可以认为时快捷方式
硬链接可以当初别名
常用方式
[root@moyue01 data]# ln -s ./a/b/c/d/e/f/g/ dir
[root@moyue01 data]# ll
lrwxrwxrwx. 1 root root 16 11月 26 14:38 dir -> ./a/b/c/d/e/f/g/
我们可以通过dir访问g文件
echo 字符串|环境变量
[root@moyue01 data]# echo "hello"
hello
[root@moyue01 data]# echo $JAVA_HOME
/usr/local/jdk
[root@moyue01 data]# cat file
www.baidu.com
[root@moyue01 data]# echo "hello" > file #将hello写入file中>表示覆盖
[root@moyue01 data]# cat file
hello
[root@moyue01 data]# echo "hello" >> file #将hello写入file中>>表示追加
[root@moyue01 data]# cat file
hello
hello

文件查看命令

cat
cat [-An] filename
准备文件
[root@moyue01 data]# cp /etc/profile ./
[root@moyue01 data]# cat profile
[root@moyue01 data]# cat -A profile
    cat -A profile显示隐藏字符
[root@moyue01 data]# cat -n profile
-n显示行号
     1  # /etc/profile
     2  
     3  # System wide environment and startup programs, for login setup
     4  # Functions and aliases go in /etc/bashrc
     5  
     6  # It's NOT a good idea to change this file unless you know what you
     7  # are doing. It's much better to create a custom.sh shell script in
     8  # /etc/profile.d/ to make custom changes to your environment, as this
     9  # will prevent the need for merging in future updates.
[root@moyue01 data]# cat -An profile #可同时使用
more/less查看文件内容
[root@moyue01 data]# more profile
f或空格翻页
enter按行进行滚动
b向上翻页
q|Q退出
[root@moyue01 data]# head profile
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
head显示前n行默认为10行可指定行数
[root@moyue01 data]# head -15 profile 显示前15行
[root@moyue01 data]# tail profile 默认显示后10行
tail显示后n行默认为10行可指定行数
[root@moyue01 data]# tail -15 profile 显示后15行

文件查找命令

find path -name filename
[root@moyue01 data]# find ./ -name 'd'
./a/b/c/d
从当前目录下查找名字为d的文件夹
[root@moyue01 data]# find ./ -name '*d*'
./dir1
./a/b/c/d
./dir
可以用*和? #?为占位符*为匹配所有
可以按照大小进行查询
[root@moyue01 data]# find ./ +size 1
./
./file3
[root@moyue01 data]# find ./ -size -1
./file3
./dir1/file1
./dir1/file2
./dir1/file3
1表示一个block=512b
可以指定单位
-为小于+为大于
grep 过滤查询内容
grep [-cinv] '查找字符串' filename
[root@moyue01 data]# grep -i as ./profile
-i不区分大小写
查找大小写视为相同的as 变色显示
[root@moyue01 data]# grep -c as ./profile
7
有7行出现了as
[root@moyue01 data]# grep -n as ./profile 
4:# Functions and aliases go in /etc/bashrc
8:# /etc/profile.d/ to make custom changes to your environment, as this
12:    case ":${PATH}:" in
55:# By default, we want umask to get set. This sets it for login shell
60:    umask 002
62:    umask 022
87:export HBASE_HOME=/usr/local/hbase
-n显示出现as的行号
[root@moyue01 data]# grep -v as ./profile
-v显示没有出现as的数据
c i n v可以联合使用
[root@moyue01 data]# grep -cinv as ./profile 
80
没有as不区分大小写的行数
[root@moyue01 data]# grep -i as ./profile
# Functions and aliases go in /etc/bashrc
# /etc/profile.d/ to make custom changes to your environment, as this
    case ":${PATH}:" in
# By default, we want umask to get set. This sets it for login shell
    umask 002
    umask 022
export HBASE_HOME=/usr/local/hbase
export PATH=$PATH:$HBASE_HOME/bin
[root@moyue01 data]# grep -i as ./profile | grep umask
# By default, we want umask to get set. This sets it for login shell
    umask 002
    umask 022
在上一次的基础上进行筛选
which 
[root@moyue01 data]# which pwd
/usr/bin/pwd
查找命令所在的路径
whereis 
[root@moyue01 data]# whereis pwd
pwd: /usr/bin/pwd /usr/share/man/man1/pwd.1.gz
查找命令所在路径和帮助文件所在位置

压缩解压

gzip
    压缩
    [root@moyue01 data]# gzip file file1
    -rw-r--r--. 1 root root 26 11月 29 20:56 file1.gz
    -rw-r--r--. 1 root root 26 11月 29 20:56 file.gz
    一个文件产生一个压缩包
    解压
    [root@moyue01 data]# gzip -d file1.gz file.gz 
    或者
    [root@moyue01 data]# gunzip file.gz file1.gz
bzip2
    压缩
    [root@moyue01 data]# bzip2 file file1
    -rw-r--r--. 1 root root 26 11月 29 20:56 file1.bz2
    -rw-r--r--. 1 root root 26 11月 29 20:56 file.bz2
    一个文件产生一个压缩包
    解压
    [root@moyue01 data]# bzip2 -d file1.bz2 file.bz2
    或者
    [root@moyue01 data]# bunzip2 file.bz2 file1.bz2
    与gzip类似
zip
    压缩
    [root@moyue01 data]# zip -r newdir file file1 dir
      adding: file (stored 0%)
      adding: file1 (stored 0%)
      adding: dir/ (stored 0%)
    [root@moyue01 data]# ll
      -rw-r--r--. 1 root root 432 11月 29 21:11 newdir.zip
    解压
    [root@moyue01 txt]# unzip newdir.zip 
      Archive:  newdir.zip
      extracting: file                    
      extracting: file1                   
      creating: dir/
tar
    tar -[cxvf] filename.tar file file1......
    打包
    [root@moyue01 data]# tar -vcf dir.tar file file1 dir
    file
    file1
    dir/
    解压
    [root@moyue01 data]# tar -xvf dir.tar
    file
    file1
    dir/
打包常用tar -[zcvf] dir.tar.gz file dir
得到文件为 dir.tar.gz
打包常用tar -[jcvf] dir.tar.bz2 file dir
得到文件为 dir.tar.bz2
-v显示压缩过程
-c表示打包
-x拆包不能和-c同用
-z为gzip
-j为bzip2
    

 时间指令

date查看时间
[root@moyue01 data]# date 
2021年 11月 29日 星期一 21:29:45 CST

设置时间
[root@moyue01 data]# date -s "2021-11-9 21:29:45"

同步机器时间需要重启
[root@moyue01 data]# hwclock -w
[root@moyue01 data]# reboot
[root@moyue01 data]# date 

关机指令

shutdown -h now立即关机
poweroff
half
init 0
shutdown -h 20:00定时关机
[root@moyue01 ~]# shutdown -h 22:00
Shutdown scheduled for 一 2021-11-29 22:00:00 CST, use 'shutdown -c' to cancel.

快捷键

ctrl+c结束前台进程
ctrl+z前台进程在后台挂起
ctrl+l清平和clear相同作用
ctrl+a回到命令最前端
ctrl+e回到命令后前端
ctrl+w删除光标前的一个单词
ctrl+k删除光标后的所有单词
basename path 显示路径最后一个名字
dirname path 显示最后一个名字之前的路径
[root@moyue01 data]# dirname $JAVA_HOME
/usr/local
[root@moyue01 data]# basename $JAVA_HOME
jdk
可以查看配置文件具体路径

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值