Linux level 2 - bash - "mkdir" & " mv" & "touch" & "rename" & "history" & "-" & "~" & "?" & "*"


title : Linux level 2 - bash - “mkdir” & " mv" & “touch” & “rename” & “history” & “-” & “~” & “?” & “*”

date:2020-03-03

categories: Linux

tags:Linux, bash


NOTE:本次试验主要练习:绝对与相对路径切换;
目录文件list;文件与目录创建;文件与目录名称更改;
通配符使用;命令输入历史查询
# man----look up the command using instructions   
[kingarthur@localhost ~]$ man ls
#pwd---- print working directory
[kingarthur@localhost ~]$ pwd
/home/kingarthur
[kingarthur@localhost ~]$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
#creat docu naming "test.txt" under the Docum direc
[kingarthur@localhost ~]$ mkdir ./Documents/test.txt
[kingarthur@localhost ~]$ ls ./Documents/
test.txt  Unix_and_perl_primer
# move docu using relative pathway
[kingarthur@localhost ~]$ mv ./Documents/test.txt  ./Documents/Unix_and_perl_primer/
[kingarthur@localhost ~]$ cd ./Documents/Unix_and_perl_primer/
[kingarthur@localhost Unix_and_perl_primer]$ ls
hello.sh  hello_sh_log  test.txt
# tidy up my docu based on the theme
[kingarthur@localhost Unix_and_perl_primer]$ mkdir hello_world
[kingarthur@localhost Unix_and_perl_primer]$ ls
hello.sh  hello_sh_log  hello_world  test.txt
[kingarthur@localhost Unix_and_perl_primer]$ mv ./hello.sh ./hello_sh_log ./hello_world
[kingarthur@localhost Unix_and_perl_primer]$ ls
hello_world  test.txt
#"hello_world" docu of yesterday's exercise  
[kingarthur@localhost Unix_and_perl_primer]$ ls ./hello_world/
hello.sh  hello_sh_log
#make docu of today's exercise  
[kingarthur@localhost Unix_and_perl_primer]$ mkdir ls_cd_mkdir
[kingarthur@localhost Unix_and_perl_primer]$ ls
hello_world  ls_cd_mkdir  test.txt
[kingarthur@localhost Unix_and_perl_primer]$ mv ./test.txt ./ls_cd_mkdir/
[kingarthur@localhost Unix_and_perl_primer]$ cd ls_cd_mkdir/
[kingarthur@localhost ls_cd_mkdir]$ ls
test.txt
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
# "-" can help return to the current direc
[kingarthur@localhost ls_cd_mkdir]$ cd -
/home/kingarthur/Documents/Unix_and_perl_primer
# "~"can help return to "home" direc
[kingarthur@localhost Unix_and_perl_primer]$ cd ~
[kingarthur@localhost ~]$ cd -
/home/kingarthur/Documents/Unix_and_perl_primer
#"/" can help return to "root" direc
[kingarthur@localhost Unix_and_perl_primer]$ cd /
[kingarthur@localhost /]$ pwd
/
[kingarthur@localhost /]$ cd -
/home/kingarthur/Documents/Unix_and_perl_primer
# change direc to X  using absolute path
[kingarthur@localhost Unix_and_perl_primer]$ cd /home/kingarthur/
[kingarthur@localhost ~]$ pwd
/home/kingarthur
[kingarthur@localhost ~]$ cd -
/home/kingarthur/Documents/Unix_and_perl_primer
[kingarthur@localhost Unix_and_perl_primer]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer
[kingarthur@localhost Unix_and_perl_primer]$ ls
hello_world  ls_cd_mkdir
# history 
[kingarthur@localhost Unix_and_perl_primer]$ history
    1  ls
    2  pwd
    3  df -h
    4  fdisk -l
    5  su
    6  exit
    7  man
    8  help
    9  man powerdown
   10  man poweroff
   11  man shutdown
   12  shutdown 
   13  man shutdown
   14  shutdown -P
   15  man shutdown
   16  python
   17  python --version
   18  pwd
   19  sudo dnf install python3
   20  su
   21  sudo dnf install python3
   22  su
   23  sudo dnf install python3
   24  sudo dnf install python3
   25  su
   26  su
   27  sudo dnf install python3
   28  sudo dnf install python3
   29  su
   30  sudo dnf install python3
   31  su
   32  sudo dnf install python3
   33  su
   34  su
   35  sudo 
   36  pwd
   37  wpd
   38  pwd
   39  man pwd
   40  ls
   41  cd Downloads/
   42  ls
   43  cd /
   44  pwd
   45  cd ~
   46  pwd
   47  sudo yum localinstall /home/kingarthur/Downloads/electron-ssr-0.2.6.rpm 
   48  su
   49  su
   50  su
   51  pwd
   52  su
   53  su
   54  su
   55  su
   56  su
   57  su
   58  su
   59  su
   60  su
   61  su
   62  exit
   63  pwd
   64  cd Documents/
   65  ls
   66  man vi
   67  cls
   68  clear
   69  mkdir Unix_and_perl_primer
   70  ls
   71  cd Unix_and_perl_primer/
   72  touch hello.sh
   73  ls
   74  nano hello.sh 
   75  hello.sh
   76  source .profile
   77  source ./
   78  source ./hello.sh
   79  hello.sh
   80  ls
   81  source hello.sh 
   82  touch hello_sh_log
   83  ls
   84  nano hello_sh_log 
   85  chmod u+x hello.sh
   86  hello.sh
   87  ls -l hello.sh
   88  chmod +x hello.sh
   89  ls -l hello.sh
   90  hello.sh
   91  ls
   92  hello.sh
   93  bash hello.sh
   94  . hello.sh
   95  nano hello_sh_log 
   96  nano hello_sh_log 
   97  exit
   98  echo $shell
   99  echo $Shell
  100  shell
  101  ls -l /bin/bash
  102  bash
  103  q
  104  exit
  105  man ls
  106  pwd
  107  ls
  108  mkdir ./Documents/test.txt
  109  ls ./Documents/
  110  mv ./Documents/test.txt  ./Documents/Unix_and_perl_primer/
  111  cd ./Documents/Unix_and_perl_primer/
  112  ls
  113  mkdir hello_world
  114  ls
  115  mv ./hello.sh ./hello_sh_log ./hello_world
  116  ls
  117  ls ./hello_world/
  118  mkdir ls_cd_mkdir
  119  ls
  120  mv ./test.txt ./ls_cd_mkdir/
  121  cd ls_cd_mkdir/
  122  ls
  123  pwd
  124  cd -
  125  cd ~
  126  cd -
  127  cd /
  128  pwd
  129  cd -
  130  cd /home/kingarthur/
  131  pwd
  132  cd -
  133  pwd
  134  ls
  135  history
[kingarthur@localhost Unix_and_perl_primer]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer
[kingarthur@localhost Unix_and_perl_primer]$ ls ./
hello_world  ls_cd_mkdir
[kingarthur@localhost Unix_and_perl_primer]$ ls hello_world/
hello.sh  hello_sh_log
[kingarthur@localhost Unix_and_perl_primer]$ cd ls_cd_mkdir/
[kingarthur@localhost ls_cd_mkdir]$ ls
test.txt
# make two direc[kingarthur@localhost ls_cd_mkdir]$ mkdir empty_dir unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt  unempty_dir
# creat file under the given direc
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./unempty_dir/test_mv_dir.txt
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test_mv_dir.txt
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt  unempty_dir
# move direc
[kingarthur@localhost ls_cd_mkdir]$ mv ./empty_dir ./unempty_dir 
[kingarthur@localhost ls_cd_mkdir]$ ls 
test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
empty_dir  test_mv_dir.txt
[kingarthur@localhost ls_cd_mkdir]$ mv ./unempty_dir/empty_dir/  ./
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test_mv_dir.txt
[kingarthur@localhost ls_cd_mkdir]$ mv ./unempty_dir/ ./empty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt
[kingarthur@localhost ls_cd_mkdir]$ ls empty_dir/
unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv ./empty_dir/unempty_dir/ ./
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv test.txt ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test_mv_dir.txt  test.txt
[kingarthur@localhost ls_cd_mkdir]$ mv ./unempty_dir/test.txt  ./
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mkdir test00.txt test01.txt
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test00.txt  test01.txt  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv *.txt ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test00.txt  test01.txt  test_mv_dir.txt  test.txt
[kingarthur@localhost ls_cd_mkdir]$ mv ./unempty_dir/*.txt  ./empty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls ./empty_dir/
test00.txt  test01.txt  test_mv_dir.txt  test.txt
[kingarthur@localhost ls_cd_mkdir]$ mv ./empty_dir/*.txt ./
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test00.txt  test01.txt  test_mv_dir.txt  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
# "touch" to create file
 [kingarthur@localhost ls_cd_mkdir]$ touch test.mp3 test00.mp3 test01.mp3 test02.mp3
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test00.mp3  test00.txt  test01.mp3  test01.txt  test02.mp3  test.mp3  test_mv_dir.txt  test.txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ touch test
[kingarthur@localhost ls_cd_mkdir]$ cd test
bash: cd: test: Not a directory
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./test
mkdir: cannot create directory ‘./test’: File exists
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./txt
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test  test00.mp3  test00.txt  test01.mp3  test01.txt  test02.mp3  test.mp3  test_mv_dir.txt  test.txt  txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ cd txt/
[kingarthur@localhost txt]$ cd ..
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./txt/txt.t
[kingarthur@localhost ls_cd_mkdir]$ ls ./txt
txt.t
# asterisk
[kingarthur@localhost ls_cd_mkdir]$ mv *xt ./txt/
mv: cannot move 'txt' to a subdirectory of itself, './txt/txt'
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./txt/
test00.txt  test01.txt  test_mv_dir.txt  test.txt  txt.t
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./empty_dir/
[kingarthur@localhost ls_cd_mkdir]$ mv t* ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  unempty_dir
#question mark
[kingarthur@localhost ls_cd_mkdir]$ touch fat fit feet 
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  fat  feet  fit  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls f?t
fat  fit
[kingarthur@localhost ls_cd_mkdir]$ ls f??t
feet
[kingarthur@localhost ls_cd_mkdir]$ ls ??t
fat  fit
[kingarthur@localhost ls_cd_mkdir]$ ls ???t
feet
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  fat  feet  fit  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv f* ./f_test
mv: target './f_test' is not a directory
[kingarthur@localhost ls_cd_mkdir]$ man mv
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./f_test
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  fat  feet  fit  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv f* ./f_test/
mv: cannot move 'f_test' to a subdirectory of itself, './f_test/f_test'
[kingarthur@localhost ls_cd_mkdir]$ ls
empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls f_test/
fat  feet  fit
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ touch 123 132 231 213 321 312 12 21 23 32 1 2 3
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mkdir ./ahead_of_num
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv *1 ./ahead_of_num/
[kingarthur@localhost ls_cd_mkdir]$ ls ./ahead_of_num/
1  21  231  321
[kingarthur@localhost ls_cd_mkdir]$ mv ./ahead_of_num/*1 ./ 
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mkdir behind_of_num 
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv 1* ./behind_of_num/
[kingarthur@localhost ls_cd_mkdir]$ ls ./behind_of_num/
1  12  123  132
[kingarthur@localhost ls_cd_mkdir]$ mv ./behind_of_num/1* ./
[kingarthur@localhost ls_cd_mkdir]$ ls ./behind_of_num/
[kingarthur@localhost ls_cd_mkdir]$ ls ./
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./f_test/
fat  feet  fit
[kingarthur@localhost ls_cd_mkdir]$ man rename
[kingarthur@localhost ls_cd_mkdir]$ rename ./f_test ./f_ques_mark_test
rename: not enough arguments
Try 'rename --help' for more information.
[kingarthur@localhost ls_cd_mkdir]$ man rename
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ rename f_test f_ques_mark_test f_test
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mkdir num_asterisk_test
[kingarthur@localhost ls_cd_mkdir]$ ls
1  12  123  132  2  21  213  23  231  3  312  32  321  ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ mv *1 *2 *3 ./num_asterisk_test/
[kingarthur@localhost ls_cd_mkdir]$ ls
ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./num_asterisk_test/
1  12  123  132  2  21  213  23  231  3  312  32  321
[kingarthur@localhost ls_cd_mkdir]$ ls
ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ ls empty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls unempty_dir/
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt
[kingarthur@localhost ls_cd_mkdir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir
[kingarthur@localhost ls_cd_mkdir]$ mv ./unempty_dir/t* ./
[kingarthur@localhost ls_cd_mkdir]$ ls ./
ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ mv t* ./unempty_dir/
[kingarthur@localhost ls_cd_mkdir]$ ls ./unempty_dir/
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt
[kingarthur@localhost ls_cd_mkdir]$ ls ./
ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ ls
ahead_of_num  behind_of_num  empty_dir  f_ques_mark_test  num_asterisk_test  unempty_dir
[kingarthur@localhost ls_cd_mkdir]$ cd unempty_dir/
[kingarthur@localhost unempty_dir]$ ls
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt
[kingarthur@localhost unempty_dir]$ cd txt/
[kingarthur@localhost txt]$ ls
test00.txt  test01.txt  test_mv_dir.txt  test.txt  txt.t
[kingarthur@localhost txt]$ mv *xt  ..
[kingarthur@localhost txt]$ ls
txt.t
[kingarthur@localhost txt]$ mv txt.t ..
[kingarthur@localhost txt]$ cd ..
[kingarthur@localhost unempty_dir]$ ls
test  test00.mp3  test00.txt  test01.mp3  test01.txt  test02.mp3  test.mp3  test_mv_dir.txt  test.txt  txt  txt.t
[kingarthur@localhost unempty_dir]$ pwd
/home/kingarthur/Documents/Unix_and_perl_primer/ls_cd_mkdir/unempty_dir
[kingarthur@localhost unempty_dir]$ ls
test  test00.mp3  test00.txt  test01.mp3  test01.txt  test02.mp3  test.mp3  test_mv_dir.txt  test.txt  txt  txt.t
[kingarthur@localhost unempty_dir]$ mv *xt ./txt
mv: cannot move 'txt' to a subdirectory of itself, './txt/txt'
[kingarthur@localhost unempty_dir]$ ls
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  txt.t
[kingarthur@localhost unempty_dir]$ ls ./t
test        test00.mp3  test01.mp3  test02.mp3  test.mp3    txt/        txt.t/      
[kingarthur@localhost unempty_dir]$ ls ./txt
test00.txt  test01.txt  test_mv_dir.txt  test.txt
[kingarthur@localhost unempty_dir]$ ls
test  test00.mp3  test01.mp3  test02.mp3  test.mp3  txt  txt.t
[kingarthur@localhost unempty_dir]$ 

欢迎各位生信工作者、生信初学者和有志于转行生信领域的伙伴,关注微信公众号(ID: biomather),每天发布实验源代码,供大家学习交流使用。
公众号二维码,欢迎关注:
wechat official QR

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值