ls ,file,find,别名,字符集,touch

文章目录 命令帮助字符集 如何查看字符集别名查看别名取消别名配置别名 Llinux文件属性及权限图

ls ,file,find,别名,字符集,touch

文章目录

    • 命令帮助
    • 字符集
  • 如何查看字符集
    • 别名
      • 查看别名
      • 取消别名
      • 配置别名
    • Llinux文件属性及权限图形说明
    • ls 命令
    • file 命令
    • find命令
  • touch

命令帮助

  • 内置命令
    • 属于GNU项目中bash bash自带 使用 help查看帮助
  • 外置命令
    • 第三方 额外安装 使用man 查看帮助

字符集

  • 什么是字符集
  • 各种语言在Linux系统中表达方式
  • GBK 国标
  • UTF-8 万国码
    保证xshell或者crt的字符集 和系统一致 UTF-8

如何查看字符集

[root@oldboy ~]# echo $LANG
en_US.UTF-8 #临时更改字符集
export LANG=zh_CN.UTF-8 #永久修改字符集
cat /etc/sysconfig/i18n
LANG=“en_US.UTF-8”
SYSFONT=“latarcyrheb-sun16”# centos6
[root@centos7 tmp]# cat /etc/locale.conf
LANG=“en_US.UTF-8”
source /etc/locale.conf#centos7,永久生效

localectl set-locale LANG=‘zh_CN.UTF-8’

别名

查看别名

alias cp

取消别名

\rm file  临时取消别名
方法2
全路径执行命令 临时取消别名
/usr/bin/rm file
方法3
unalias rm   取消别名 临时生效

环境变量文件执行的顺序
/etc/profile
.bash_profile
.bashrc

配置别名

小名=‘echo 呵呵’ 等号后面 必须是可执行的命令

  • [which 查看命令的全路径]

Llinux文件属性及权限图形说明


echo $? 查看上一条命令返回的结果 0代表成功 非0 代表失败

tr -cd “a-zA-Z” < /dev/urandom |head -c8|tr “a-z” “0-9”
RANDOM 存放着 0-32767
[root@oldboy ~]# echo $((RANDOM%100+1)) 随机生成1-100

ls 命令

-i, --inode
print the index number of each file

–hide=PATTERN
do not list implied entries matching shell PATTERN
(overridden by -a or -A)
-t sort by modification time, newest first

-s, --size(默认是从小到大排序)
print the allocated size of each file, in blocks
-r 从大到小排列

-R 表示连同子目录一同显示
ls //显示不隐藏的文件与文件夹
ls -a //显示当前目录下的所有文件及文件夹包括隐藏的.和…等
ls -l //显示不隐藏的文件与文件夹的详细信息
ls -ld 只显示当前文件夹具体信息

file 命令

file 查看文件的类型

  • 普通文件
    数据包
    二进制文件
    /dev/null 黑洞
    ==/dev/urandom == 白洞
    #xargs 将前一个输出甩到最后去
    -i 参数可以将传递的内容到中间
    #==tr -c == 补集

find命令

find命令默认接的命令是-print,它默认以\n将找到的文件分隔。可以使用-print0来使用\0分隔,这样就不会分行了。
想要在指定目录下搜索某目录中的某文件,应该使用
-path而不是-name
[root@centos7 ~]# find /tmp -path ‘a/.log’

[root@centos7 ~]# find /tmp -name “.log"
/tmp/a/1.log
/tmp/a/2.log
/tmp/a/3.log
/tmp/a/4.log
/tmp/a/5.log
[root@centos7 ~]# find /tmp -name "
.log” -print0
/tmp/a/1.log/tmp/a/2.log/tmp/a/3.log/tmp/a/4.log/tmp/a/5.log
但是一定要注意,-print0针对的是\n转\0,如果查找的文件名本身就含有空格,则find后-print0仍然会显示空格文件。所以-print0实现的是\n转\0的标记,可以使用其他工具将\0标记替换掉,如xargs,tr等。
#find 查找文件(/在工作中查找文件 尽量不要使用/,使用绝对路径)
#fid 路径(要查找的目录) -type (文件类型 f d l b c p s )
[root@centos6 tmp]# echo ‘11#2##33’ | xargs -d ‘#’ echo
11 2 33

[root@centos6 tmp]# echo ‘11#22#33#44#55#66#77#88#99#00’ | xargs -d ‘#’ -n 3 echo
11 22 33
44 55 66
77 88 99
00
查找空文件或空目录
find ./ -empty

查找空文件并删除
find ./ -empty -type f -print -delete

f1、find . -name “*.sh”

查找在当前目录(及子目录)下找以sh结尾的文件。

限制目录深度的查找(最大层数)
find 目录 == -maxdepth 1(层数)== -name ‘*.txt’

2、find . -perm 755

查找在当前目录(及子目录)下找属性为755的文件。

3、find -user root

查找在当前目录(及子目录)下找属主为root的文件。

4、find /var -mtime -5

 查找在/var下找更改时间在5天以内的文件。

5、find /var -mtime +3

 查找在/var下找更改时间在3天以前的文件。

6、find /etc -type l

 查找在/etc下查找文件类型为|的链接文件。

7、find . -size +1000000c

  查找在当前目录(及子目录)下查找文件大小大于1M的文件,1M是1000000个字节。

8、find . -perm 700 |xargs chmod 777

  查找出当前目录(及子目录)下所有权限为700的文件,并把其权限重设为777。

9、find . -type f |xargs ls -l

  查找出文件并查看其详细信息。

组合查找文件名以file1开头(与、或、非)file2开头的文件

?
1
2
3
4
5
6
7
8
9
10
11
12
/**

  • 组合查找语法:
  • -a 与(取交集)
  • -o 或(取并集)
  • -not 非(同 !)
  • ! 非(同 not)
    */

find . -name “file1*” -a -name “file2*”
find . -name “file1*” -o -name “file2*”
find . -name “file1*” -not -name “file2*”
find . -name “file1*” ! -name “file2*”

/**

  • 搜索权限为 777 的文件
    */

find . -type f -perm 777

/**

  • 搜索 .txt 格式且权限不为 777 的文件
    */

find . -type f -name “*.txt” ! -perm 777

exec解释:
-exec 参数后面跟的是command命令,它的终止是以;为结束标志的,所以这句命令后面的分号是不可缺少的,考虑到各个系统中分号会有不同的意义,所以前面加反斜杠。
{} 花括号代表前面find查找出来的文件名。
使用find时,只要把想要的操作写在一个文件里,就可以用exec来配合find查找,很方便的。

在目录中查找更改时间在n日以前的文件并删除它们,在删除之前先给出提示
命令:
find . -name “*.log” -mtime +5 -ok rm {} ;
输出:

[root@localhost test]# ll
总计 312
-rw-r–r-- 1 root root 302108 11-03 06:19 log2012.log
lrwxrwxrwx 1 root root 7 10-28 15:18 log_link.log -> log.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxrwx 2 root root 4096 11-12 19:32 test3
drwxrwxrwx 2 root root 4096 11-12 19:32 test4
[root@localhost test]# find . -name “*.log” -mtime +5 -ok rm {} ;
< rm … ./log_link.log > ? y
< rm … ./log2012.log > ? n
[root@localhost test]# ll
总计 312
-rw-r–r-- 1 root root 302108 11-03 06:19 log2012.log
drwxr-xr-x 6 root root 4096 10-27 01:58 scf
drwxrwxrwx 2 root root 4096 11-12 19:32 test3
drwxrwxrwx 2 root root 4096 11-12 19:32 test4

[root@oldboyedu tmp]# cat text.txt | xargs -n 3 # xargs 重新格式化以3行输出
fajg sdkldfhaf sf;dlfj
dfoidifn

[root@oldboyedu etc]# awk -v FS="#" -v OFS=’----’ ‘{print $1,$2}’ test
abc----123
8ua----456
#-v:变量 FS:输入分隔符 OFS:输出分隔符

awk ‘{print $1,$2}’ test1
abc 123
8ua 456
[root@oldboyedu etc]# awk ‘{print $1$2}’ test1
abc123
8ua456
[root@oldboyedu etc]# awk ‘{print $1 $2}’ test1
abc123
8ua456
[root@centos6 tmp]# find . -name “.txt"
./2.txt
./5.txt
./4.txt
./8.txt
./7.txt
./3.txt
./6.txt
./1.txt
[root@centos6 tmp]# find . -name "
.txt” -print0
./2.txt./5.txt./4.txt./8.txt./7.txt./3.txt./6.txt./1.txt[root@centos6 tmp]#

经xargs 分段处理 ,要小心是通过文本符号,还是标记意义符号,如
a b go to school c d ,要注意会不会把go to school 分割开

touch

发布者:admin,转转请注明出处:http://www.yc00.com/web/1691863189a546988.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信