ziggle

Hail Hydra


  • Home

  • Archives

  • Search

linux-find

Posted on 2018-05-29

###

1
2
3
# find path -option [ -print] [ -exec -ok  command] {} 

root@ziggle:~$ find / -name *.conf -type f -print

参数说明
参数说明 :

find 根据下列规则判断 path 和 expression,在命令列上第一个 - ( ) , ! 之前的部份为 path,之后的是 expression。如果 path 是空字串则使用目前路径,如果 expression 是空字串则使用 -print 为预设 expression。

expression 中可使用的选项有二三十个之多,在此只介绍最常用的部份。

-mount, -xdev : 只检查和指定目录在同一个文件系统下的文件,避免列出其它文件系统中的文件

-amin n : 在过去 n 分钟内被读取过

-anewer file : 比文件 file 更晚被读取过的文件

-atime n : 在过去 n 天过读取过的文件

-cmin n : 在过去 n 分钟内被修改过

-cnewer file :比文件 file 更新的文件

-ctime n : 在过去 n 天过修改过的文件

-empty : 空的文件-gid n or -group name : gid 是 n 或是 group 名称是 name

-ipath p, -path p : 路径名称符合 p 的文件,ipath 会忽略大小写

-name name, -iname name : 文件名称符合 name 的文件。iname 会忽略大小写

-size n : 文件大小 是 n 单位,b 代表 512 位元组的区块,c 表示字元数,k 表示 kilo bytes,w 是二个位元组。-type c : 文件类型是 c 的文件。

d: 目录

c: 字型装置文件

b: 区块装置文件

p: 具名贮列

f: 一般文件

l: 符号连结

s: socket

-pid n : process id 是 n 的文件

你可以使用 ( ) 将运算式分隔,并使用下列运算。

exp1 -and exp2

! expr

-not expr

exp1 -or exp2

exp1, exp2

-print :将查找到的文件输出到标准输出
-exec command {} \; – 将查到的文件执行command操作,{} 和 \;之间有空格
-ok 和-exec相同,只不过在操作前要询用户

实例

  • 找到当前目录下及子目录拓展名为 c 的文件

    1
    find . -name "*.c"
  • 目录里找类型

    1
    find . -type f
  • 目录找最近天数修改的文件

    1
    find . -ctime -20
  • 查找前目录中文件属主具有读、写权限,并且文件所属组的用户和其他用户具有读权限的文件:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    find . -type f -perm 644 -exec ls -l {} \;
    find . -name *lin*,其中 . 代表在当前目录找,-name 表示匹配文件名 / 文件夹名,*lin* 用通配符搜索含有lin的文件或是文件夹
    find . -iname *lin*,其中 . 代表在当前目录找,-iname 表示匹配文件名 / 文件夹名(忽略大小写差异),*lin* 用通配符搜索含有lin的文件或是文件夹
    find / -name *.conf,其中 / 代表根目录查找,*.conf代表搜索后缀会.conf的文件
    find /opt -name .oh-my-zsh,其中 /opt 代表目录名,.oh-my-zsh 代表搜索的是隐藏文件 / 文件夹名字为 oh-my-zsh 的
    find /opt -type f -iname .oh-my-zsh,其中 /opt 代表目录名,-type f 代表只找文件,.oh-my-zsh 代表搜索的是隐藏文件名字为 oh-my-zsh 的
    find /opt -type d -iname .oh-my-zsh,其中 /opt 代表目录名,-type d 代表只找目录,.oh-my-zsh 代表搜索的是隐藏文件夹名字为 oh-my-zsh 的
    find . -name "lin*" -exec ls -l {} \;,当前目录搜索lin开头的文件,然后用其搜索后的结果集,再执行ls -l的命令(这个命令可变,其他命令也可以),其中 -exec 和 {} ; 都是固定格式
    find /opt -type f -size +800M -print0 | xargs -0 du -h | sort -nr,找出 /opt 目录下大于 800 M 的文件
    find / -name "*tower*" -exec rm {} \;,找到文件并删除
    find / -name "*tower*" -exec mv {} /opt \;,找到文件并移到 opt 目录
    find . -name "*" |xargs grep "youmeek",递归查找当前文件夹下所有文件内容中包含 youmeek 的文件
    find . -size 0 | xargs rm -f &,删除当前目录下文件大小为0的文件
    du -hm --max-depth=2 | sort -nr | head -12,找出系统中占用容量最大的前 12 个目录

java-io

Posted on 2018-05-14

Java 的 I/O 大概可以分成以下几类:

  1. 磁盘操作:File
  2. 字节操作:InputStream 和 OutputStream
  3. 字符操作:Reader 和 Writer
  4. 对象操作:Serializable
  5. 网络操作:Socket
  6. 新的输入/输出:NIO

字节操作

java i/o 使用了装饰着模式实现,以 InputStream 为例,InputStream 是抽象组件,FileInputStream 是 InputStream 的子类,属于具体组件,提供了字节流的输入操作。FilterInputStream 属于抽象装饰者,装饰者用于装饰组件,为组件提供额外的功能,例如 BufferedInputStream 为 FileInputStream 提供缓存的功能。

实例化一个具有缓存功能的字节流对象时,只需要在 FileInputStream 对象上再套一层 BufferedInputStream 对象即可。

1
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));

字符操作

不管是磁盘还是网络传输,最小的存储单元都是字节,而不是字符,所以 I/O 操作的都是字节而不是字符。但是在程序中操作的通常是字符形式的数据,因此需要提供对字符进行操作的方法。

InputStreamReader 实现从文本文件的字节流解码成字符流;OutputStreamWriter 实现字符流编码成为文本文件的字节流。它们继承自 Reader 和 Writer。

编码就是把字符转换为字节,而解码是把字节重新组合成字符。

1
2
byte[] bytes = str.getBytes(encoding);     // 编码
String str = new String(bytes, encoding); // 解码

GBK 编码中,中文占 2 个字节,英文占 1 个字节;UTF-8 编码中,中文占 3 个字节,英文占 1 个字节;Java 使用双字节编码 UTF-16be,中文和英文都占 2 个字节。

如果编码和解码过程使用不同的编码方式那么就出现了乱码。

五、对象操作

序列化就是将一个对象转换成字节序列,方便存储和传输。

序列化:ObjectOutputStream.writeObject()

反序列化:ObjectInputStream.readObject()

序列化的类需要实现 Serializable 接口,它只是一个标准,没有任何方法需要实现。

transient 关键字可以使一些属性不会被序列化。

ArrayList 序列化和反序列化的实现 :ArrayList 中存储数据的数组是用 transient 修饰的,因为这个数组是动态扩展的,并不是所有的空间都被使用,因此就不需要所有的内容都被序列化。通过重写序列化和反序列化方法,使得可以只序列化数组中有内容的那部分数据。

1
private transient Object[] elementData;
Read more »

linux group

Posted on 2018-05-07
1
2
3
4
5
6
root@ziggle:~# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
....

/etc/passwd 中各个字段表示的信息 用:分割

  • 通过用户类型分组,我们可以把用户分为:
    • 管理员
    • 普通用户
  • 通过用户组类型分组,我们可以把用户组分为:
    • 管理员组
    • 普通用户组
  • 从用户的角度,我们可以把用户组分为:
    • 基本组(默认组)
    • 额外组(附加组)
  • 对于普通用户,我们还可以分为:
    • 系统用户
    • 普通用户
  • 因此,对于普通用户组,我们也可以分为:
    • 系统用户组
    • 普通用户组

      /etc/passwd 中各字段含义

      account : 用户名
      password :密码占位符 (x)
      uid : 用户ID
      gid : 用户组ID
      command : 注释信息
      home dir : 用户家目录
      shell : 用户默认shell

密码 /etc/shadow

useradd

  • useradd -u UID:指定 UID,这个 UID 必须是大于等于500,并没有其他用户占用的 UID
  • useradd -g GID/GROUPNAME:指定默认组,可以是 GID 或者 GROUPNAME,同样也必须真实存在
  • useradd -G GROUPS:指定额外组
  • useradd -c COMMENT:指定用户的注释信息
  • useradd -d PATH:指定用户的家目录
  • useradd -s SHELL:指定用户的默认 shell,最好是在 /etc/shells 中存在的路径
  • useradd -s /sbin/nologin:该用户不能登录,还记得我们上面说到的系统用户不能登录吧?我们可以看到系统用户的 shell 字段也是 /sbin/nologin
  • echo $SHELL :查看当前用户的 shell 类型
  • useradd -M USERNAME:创建用户但不创建家目录
  • useradd -mk USERNAME:创建用户的同时创建家目录,并复制 /etc/skel 中的内容到家目录中。关于 /etc/skel 目录会在下一篇 Linux 权限管理中再次讲解。
    如果用户没有家目录,那么不能切换到该用户

userdel

  • userdel [username] : 删除用户
  • userdel -r [username] : 删除用户同时删除用户家目录

git 问题解决

Posted on 2018-05-07

git unable pull from remote

1
2
3
4
5
muyue@wp-desk MINGW64 /d/code/LearnOnlineAPI (dev)
$ git pull
error: cannot lock ref 'refs/remotes/origin/feature/zbf': 'refs/remotes/origin/feature/zbf/Notice' exists; cannot create 'refs/remotes/origin/feature/zbf'
From http://git.xueanquan.cc/dotnet/live/LearnOnlineAPI
! [new branch] feature/zbf -> origin/feature/zbf (unable to update local ref)
  • solution
    1
    2
    $ git gc --prune=now
    git remote prune origin

全局配置

~/.gitconfig

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[user]
name = ziggle
email = muyue1125@gmail.com
# [https]
# proxy = https://127.0.0.1:8087
# [http]
# proxy = http://127.0.0.1:8087
[merge]
tool = vimdiff
[credential]
helper = wincred


[alias]
tree = log --oneline --decorate --all --graph

# [include]
# path =

别名

1
git config --global alias.tree "log --oneline --decorate --all --graph"

代理

###

1
$ git rm -r -n --cached "bin/"   ,此命令是展示要删除的文件表预览

Unstaging a Staged File

1
git reset HEAD benchmarks.rb

Unmodifying a Modified File

1
git checkout --benchmarks.rb

怎样在一个分支拉去另一个分支的远程代码

1
2
git fetch <remote> <sourceBranch>:<destinationBranch>
git fetch origin master:master

找到一个被删除的文件并恢复

  • Use git log –diff-filter=D –summary to get all the commits which have deleted files and the files deleted;
  • Use git checkout $commit~1 path/to/file.ext to restore the deleted file.

linux /windows git status 显示不同

git config –global core.autocrlf true

###
在默认设置下,中文文件名在工作区状态输出,查看历史更改概要,以及在补丁文件中,文件名的中文不能正确地显示,而是显示为八进制的字符编码,示例如下:
$ git status -s
?? “\350\257\264\346\230\216.txt\n
$ printf “\350\257\264\346\230\216.txt\n”

1
git config --global core.quotepath false

powershell

Posted on 2018-04-14
1
> taskkill /pid 12436 /f

tee-object

1
scripts git:(master) ✗ frida -U  com.tencent.mm  -l .\ec\wechat.js | Tee-Object log.log
1…141516…22
ziggle

ziggle

Hail Hydra !

110 posts
45 tags
RSS
GitHub
© 2021 ziggle
Powered by Hexo
|
Hail Hydra—