Linux基础指令

1 ls指令

ls[选项][目录或文件]
对于目录,使用此命令可以列出该目录下所有的子目录和文件;对于文件则列出文件名以及其他信息。
例如:ls -r:目录反向排序
[cxx@localhost ~]$ ls
1-class Desktop Documents Downloads Music Pictures Public Templates Videos dir2 mydir mydir.zip test test.c
[cxx@localhost ~]$ ls -r
test.c test mydir.zip mydir dir2 Videos Templates Public Pictures Music Downloads Documents Desktop 1-class

ll -rt:按时间反序排序文件:

[cxx@localhost ~]$ ll -rt
total 36
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Videos
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Templates
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Public
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Pictures
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Music
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Downloads
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 02:07 Documents
drwxrwxr-x. 2 cxx cxx 4096 Mar 15 02:58 dir2
drwxr-xr-x. 2 cxx cxx 4096 Mar 15 03:01 Desktop

2.pwd指令

pwd 显示工作路径

3.cd指令

cd/home cd~ 进入“home”目录
cd.. 返回上一级目录
cd 进入个人主目录
cd- 返回上次所在的目录

4.touch命令

touch:创建一个文件
touch file:创建file文件

5.mkdir命令

mkdir dir: 创建一个叫dir的目录
mkdir dir1 dir2:同时创建两个目录
例:递归创建多个目录
[cxx@localhost ~]$ mkdir -p test/test1
[cxx@localhost ~]$ ls
1-class Desktop Documents Downloads Music Pictures Public Templates Videos dir2 mydir mydir.zip test test.c
[cxx@localhost ~]$ cd test
[cxx@localhost test]$ ls
test1
[cxx@localhost test]$

6.rm指令

rm+文件名:删除某个文件
rm -r+目录名:删除一个目录
rm -i -r+目录名:此时希望再删除目录时能够提醒确认
删除dir1
[谨慎使用:]
rm -rf dir:强制性的删除文件
rm -rf /:删除根目录
rmdir:删除空目录

7.帮助文档:

man:[重要]
man cp 回车后结果:

8.mv指令[重要]

语法:mv(选项)(参数)
选项:
-f:若目标文件或目录与现有的文件或目录重复,则直接覆盖现有的文件或目录。
-i:交互式操作。若源文件与目标文件或目标目录中的文件同名,则询问用户是否覆盖目标文件,输入“y”,则继续;输入”n”则取消覆盖操作。
例:本分[cxx@localhost ~]$ ls
1-class Desktop Documents Downloads Music Pictures Public Templates Videos dir2 mydir mydir.zip test test.c
[cxx@localhost ~]$ mv test.c haha.c
[cxx@localhost ~]$ ls
1-class Desktop Documents Downloads Music Pictures Public Templates Videos dir2 haha.c mydir mydir.zip test
[cxx@localhost ~]$

将文件移动到当前目录中:
mv /test/* .

9.cat指令

查看目标文件中的内容:

[cxx@localhost ~]$ cat haha.c

aaaa
bbbb
cccc
ddd
ee
fffff
ggg

[cxx@localhost ~]$ 

10.时间相关命令

date显示:

[cxx@localhost ~]$ date +%Y:%m:%d
2018:03:18
[cxx@localhost ~]$ 
[cxx@localhost ~]$ date +%Y:%m:%d:%H:%M:%S
2018:03:18:20:35:05
[cxx@localhost ~]$ 

时间戳:指的是从1970年1月1日开始所经过的秒数

[cxx@localhost ~]$ date +%s
1521430603
[cxx@localhost ~]$ 

11.find指令

用于查找文件。

[cxx@localhost ~]$ find ./ -name test
./test
[cxx@localhost ~]$ 
[cxx@localhost ~]$ find -name file*
./test/file1
./test/file2
[cxx@localhost ~]$ 

12.grep命令

在文件中搜索字符串,将找到的行打印出来。
例:

[cxx@localhost 1-class]$ grep -n haha test.c
3:printf("haha");
[cxx@localhost 1-class]$ grep -n haha test.c --color
3:printf("haha");(此处是利用颜色显示)
[cxx@localhost 1-class]$ 

进入目录中寻找“haha”:

[cxx@localhost ~]$ grep haha */*
Binary file 1-class/a.out matches
1-class/test.c:printf("haha");
[cxx@localhost ~]$

13.文件压缩与解压缩

将test2目录压缩:zip test2.zip test2/*
解压到tmp目录:unzip test2.zip -d /tmp

14、history

可以看到最近使用过的历史记录

bash: /root: is a directory
[root@bogon ~]# history | wc -l
218
[root@bogon ~]# history |head -n1
    1  yum install -y vim* 
[root@bogon ~]# HITSIZE
bash: HITSIZE: command not found
[root@bogon ~]# HISTSIZE
bash: HISTSIZE: command not found
[root@bogon ~]# echo $HISTSIZE
1000
[root@bogon ~]# history |wc -l
223
[root@bogon ~]# history
    1  yum install -y vim* 
    2  ls -a
    3  ls /
    4  ls -a
    5  cd /
    6  ls -a
    7   touch .vimrc
    8  ls -a
    9  clear
   10  wget  http://www.linuxidc.com/files/2016/05/vim/vimrc.zip
   11  vim .vimrc
   12  mkdir day01
   13  ls
   14  cd day01
   15  ls
   16  vim hello.c
   17  vim .vimrc
   18  vim hello.c
   19  vim .vimrc
   20  cd /
   21  ls -a
   22  mkdir .vim
   23  cd .vim
   24  mkdir plugin doc syntax
   25  ls
   26  vim plugin
   27  cd /
   28  ls -a
   29  cd .vim
   30  ls
   31  vim plugin
   32  ls
   33  cd doc
   34  mv/home/cxx/Desktop/doc/* . 
   35  mv/home/cxx/Desktop/doc/*. 
   36  mv/home/cxx/Desktop/doc/* . 
   37  mv /home/cxx/Desktop/doc/* . 
   38  ls
   39  cd ..
   40  cd /
   41  ls -a
   42  vim .vimrc
   43  reboot
   44  cd /
   45  ls -a
   46  vim .vimrc
   47  cd day01
   48  vim hello.c
   49  cd /
   50  ls
   51  ls -a
   52  vi /root/.vimrc
   53  cd day01
   54  vi hello.c
   55  ls
   56  cd /
   57  ls-a
   58  ls -a
   59  vi /root/.vimrc
   60  cd day01
   61  vi hello.c
   62  vi /root/.vimrc
   63  vi hello.c
   64  cd /
   65  ls -a
   66  vi /root/.vimrc
   67  cd day01
   68  vi hello.c
   69  ls
   70  gcc hello.c
   71  ls
   72  ./a,out
   73  ./a.out
   74  cd /
   75  cd /etc
   76  ls
   77  cd /
   78  ls -a
   79  vi .vimrc
   80  vi /root/.vimrc
   81  cd day01
   82  ls
   83  vi hello.c
   84  vim hello.c
   85  vi /root/.vimrc
   86  shutdown -h now
   87  vim yy.c
   88  vim test.c
   89  gcc test.c
   90  ll
   91  ./a.out
   92  cat test.c
   93  vim test.c
   94  gcc test.c
   95  ll
   96  ./a.out
   97  vim test.c
   98  gcc test.c
   99  ./a.out
  100  vim test.c
  101  gcc test.c
  102  ./a.out
  103  vin test.c
  104  vim test.c
  105  gcc test.c
  106  ./a.out
  107  ps aux|grep a.out
  108  vim test.c
  109  gcc test.c
  110  vim test.c
  111  gcc test.c
  112  ./a.out
  113  man fork
  114  cd code
  115  ls
  116  cat tmp
  117  cd tmp
  118  vim tmp
  119  cd ..
  120  cd ~
  121  cd code
  122  mkdir process
  123  vim process_bar.c
  124  vim process_bar.c[+]
  125  vim process_bar.c
  126  gcc process_bar.c
  127  vim process_bar.c
  128  gcc process_bar.c
  129   vim process_bar.c
  130  gcc process_bar.c
  131  vim process_bar.c
  132  gcc process_bar.c
  133  ./ a.out
  134  ./a.out
  135  vim process_bar.c
  136  gcc process_bar.c
  137  ll
  138  ./a.out
  139  vim process_bar.c
  140  gcc process_bar.c
  141  ./a.out
  142  vim process_bar.c
  143  gcc process_bar.c
  144  ./a.out
  145  vim process_bar.c
  146  gcc process_bar.c
  147  ./a.out
  148  ls
  149  rm process
  150  rm -f process
  151  rm -r process
  152  vim process_bar.c
  153  gcc process_bar.c
  154  ./a.out
  155  vim proccess_bar.c
  156  vim process_bar.c
  157  gcc process_bar.c
  158  ./a.out
  159  cat process_bar.c
  160  vi /root/.vimrc
  161  su cxx
  162  cd ~
  163  mkdir code
  164  ll
  165  ls
  166  cd code
  167  vim test.c
  168  su -test
  169  su - test
  170  su-test
  171  su -cxx
  172  su cxx
  173  su cxx
  174  ls -a
  175  su
  176  vim hllo.c
  177  ll
  178  vim test.c
  179  ll
  180  vim hello.c
  181  vim makefile
  182  make
  183  make hello.c
  184  vim hello.c
  185  gcc hello.c
  186  ps aux| grep a.out
  187  cat hello.c
  188  vim hello.c
  189  gcc hello.c
  190  ll
  191  ./ hello 
  192  ./hello
  193  ps aux|grep hello
  194  kill -l
  195  kill -19 4092
  196  ./a.out
  197  ps aux|grep a.out
  198  vim hello.c
  199  gcc hello.c
  200  vim hello.c
  201  gcc hello.c
  202  ll
  203  yum install "@Chinese Support"
  204  vim
  205  vim 
  206  ll
  207  cd code
  208  ll
  209  vim hello.c
  210  ls >makefile
  211  vim makefile
  212  make
  213  su cxx
  214  whoami
  215  cd ~
  216  pwd
  217  $HOME
  218  history | wc -l
  219  history |head -n1
  220  HITSIZE
  221  HISTSIZE
  222  echo $HISTSIZE
  223  history |wc -l
  224  history
[root@bogon ~]# history | head -n1
    1  yum install -y vim* 
[root@bogon ~]# 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值