Linux Shell 使用技巧

一次建立多個目錄php

[root@localhost tmp]# mkdir -p /user/{folder1,folder2,folder3}    
[root@localhost tmp]# ls /user/     
folder1  folder2  folder3

找出根目錄下最大的10個目錄,並按使用空間從大到小排序node

[root@localhost ~]# du -a ./ | sort -nr | head -n 10    
132380    ./     
132316    ./source     
69916    ./source/ZendGuard-5_5_0.tar.gz     
18720    ./source/xunzai.com_mysql-5.0.18.tar.gz     
13732    ./source/php-5.4.11.tar.gz     
6144    ./source/phpMyAdmin-3.5.6-all-languages.tar.gz     
5996    ./source/httpd-2.4.3.tar.gz     
5044    ./source/libxml2-2.9.0.tar.gz     
1984    ./source/pcre-8.32.zip     
1960    ./source/freetype-2.4.10.tar.gz

查看根目錄下全部以「.」開頭的文件mysql

[root@localhost ~]# find ./ -name ".[^.]*"    
./.bash_logout     
./.bash_profile     
./.bashrc     
./.cshrc     
./.tcshrc     
./.cache     
./.config     
./.bash_history     
./.xauth96WqtE     
./.mysql_history     
./.mysql_history.TMP     
./.viminfo

修改文件或目錄的時間戳sql

[root@localhost ~]# stat person.txt    
  File: ?.erson.txt?     
  Size: 74            Blocks: 8          IO Block: 4096   regular file     
Device: 803h/2051d    Inode: 145535279   Links: 1     
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)     
Context: unconfined_u:object_r:admin_home_t:s0     
Access: 2016-04-02 05:05:10.370059171 -0700     
Modify: 2016-04-02 05:04:40.854898705 -0700     
Change: 2016-04-02 05:04:40.913901033 -0700     
Birth: -     
[root@localhost ~]# touch -t 201604052135 person.txt #格式爲YYMMDDhhmm     
[root@localhost ~]# stat person.txt     
  File: ?.erson.txt?     
  Size: 74            Blocks: 8          IO Block: 4096   regular file     
Device: 803h/2051d    Inode: 145535279   Links: 1     
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)     
Context: unconfined_u:object_r:admin_home_t:s0     
Access: 2016-04-05 21:35:00.000000000 -0700     
Modify: 2016-04-05 21:35:00.000000000 -0700     
Change: 2016-04-05 06:36:16.304945163 -0700     
Birth: -

快速備份一個文件:cp filename{,.bak}vim

[root@localhost ~]# ls    
anaconda-ks.cfg  person.txt  source     
[root@localhost ~]# cp person.txt{,.bak}     
[root@localhost ~]# ls     
anaconda-ks.cfg  person.txt  person.txt.bak  source

進程運行到後臺bash

[root@localhost ~]# Ctrl + z

進程運行到前臺ide

[root@localhost ~]# fg

隨機產生10位字符數的十六進制數debug

[root@localhost ~]# openssl rand -hex 10    
c3e805e84074211cc698

將文件解壓到新的目錄xml

[root@localhost src]# ls    
apr-1.4.6.tar.gz        libmcrypt-2.5.8.tar.gz     
apr-util-1.5.1.tar.gz   libpng-1.5.14.tar.gz     
autoconf-2.69.tar.gz    libxml2-2.9.0.tar.gz     
debug                   pcre-8.32.zip     
freetype-2.4.10.tar.gz  php-5.4.11.tar.gz     
gd-2.0.35.tar.gz        phpMyAdmin-3.5.6-all-languages.tar.gz     
httpd-2.4.3             xunzai.com_mysql-5.0.18.tar.gz     
httpd-2.4.3.tar.gz      ZendGuard-5_5_0.tar.gz     
jpegsrc.v8b.tar.gz      zlib-1.2.7.tar.gz     
kernels     
[root@localhost src]# tar zxvf apr-1.4.6.tar.gz -C /tmp/tmp/     
apr-1.4.6/     
apr-1.4.6/shmem/     
apr-1.4.6/shmem/win32/     
…………     
[root@localhost src]# ls /tmp/tmp/     
apr-1.4.6

將全部文件名中含有」txt」的文件移入「/tmp/tmp」目錄排序

[root@localhost ~]# find -iname "*txt*" -exec mv -v {} /tmp/tmp/ \;    
?./person.txt?.-> ?.tmp/tmp/person.txt?     
?./person.txt.bak?.-> ?.tmp/tmp/person.txt.bak?     
[root@localhost ~]# ls /tmp/tmp/     
apr-1.4.6  person.txt  person.txt.bak

將任意一行開頭爲「#」的去除掉

[root@localhost ~]# cat a.txt    
This is the file     
#This is another file     
#This is the final file     
[root@localhost ~]# sed '2s/^#//' a.txt     
This is the file     
This is another file     
#This is the final file
相關文章
相關標籤/搜索