Things under legendu
It is suggested that you use Python (the pathlib module) instead of the fselect command to find files.
Tips and Traps¶
is_*columns supporting comparing with1,trueandyes, etc.where name like '%.markdown'can be written aswhere name like %.markdownand is equivalent towhere name = '*.markdown'It is suggested that you use
gtinstead of>as>is interpreted as the redirect operator in shell if no quotes is used.
!fselect * from . where is_file = 1tips-on-cargo.markdown tips-on-rustc.markdown use-fselect-to-find-files.ipynb
!fselect name from . depth 1 where is_file = 1tips-on-cargo.markdown
tips-on-rustc.markdown
use-fselect-to-find-files.ipynb
Find all files with the extension
.markdownin the current directory and its subdirectory.
!fselect name from . where is_file = 1 and name like %.markdowntips-on-cargo.markdown
tips-on-rustc.markdown
The pipe operator | is very useful for piping the result of a command to another one.
Below is an example of find all markdown files in the current directory
and keep only those that have cargo in the name.
!fselect name from . where is_file = 1 and name like %.markdown | grep cargotips-on-cargo.markdown
Of course, this example is not very useful as it is equivalent to the following simpler command (no need of grep)
!fselect name from . where is_file = 1 and name like %cargo%.markdowntips-on-cargo.markdown
However,
the below example is an useful one which find all markdown files in the current directory
and then find lines containing the keyword cargo in those files.
!fselect name from . where is_file = 1 and name like %.markdown | xargs grep cargotips-on-cargo.markdown:Slug: tips-on-cargo
tips-on-cargo.markdown:Tags: Computer Science, programming, rust, cargo
tips-on-cargo.markdown: cargo init
tips-on-cargo.markdown: cargo new project_name
tips-on-cargo.markdown: cargo run
tips-on-cargo.markdown: cargo build
tips-on-cargo.markdown: cargo build --release
tips-on-rustc.markdown:Tags: Computer Science, programming, Rust, rustc, optimization, cargo
tips-on-rustc.markdown: and `cargo build --release` uses the release profile which defaults to `-C opt-level=3`.
File Size¶
Find files with size greater than 10 (bytes).
!fselect name, size from . where is_file = 1 and size gt 10tips-on-cargo.markdown 403
tips-on-rustc.markdown 1005
use-fselect-to-find-files.ipynb 7505
use-fselect-to-find-files-checkpoint.ipynb 1121
!fselect "name, size from . where is_file = 1 and size > 10"tips-on-cargo.markdown 403
tips-on-rustc.markdown 1005
use-fselect-to-find-files.ipynb 7505
use-fselect-to-find-files-checkpoint.ipynb 1121
Notice that the following query won’t work.
fselect name, size from . where is_file = 1 and size > 10It is interprecated as redirecting the result of fselect name, size from . where is_file = 1 and size
into a file named 10.
Find files with size greater than 5k (bytes).
!fselect name, size from . where is_file = 1 and size gt 5kuse-fselect-to-find-files.ipynb 8169
Find empty directories.
:::bash find / -type d -empty
Time Related¶
!fselect name, accessed from . where is_file = 1 and accessed gt '1 hour ago'[/home/dclong/.cargo/registry/src/github.com-1ecc6299db9ec823/fselect-0.7.4/src/parser.rs:48] fields = [
Expr {
left: None,
arithmetic_op: None,
logical_op: None,
op: None,
right: None,
minus: false,
field: Some(
Name,
),
function: None,
args: None,
val: None,
},
Expr {
left: None,
arithmetic_op: None,
logical_op: None,
op: None,
right: None,
minus: false,
field: Some(
Accessed,
),
function: None,
args: None,
val: None,
},
]
[/home/dclong/.cargo/registry/src/github.com-1ecc6299db9ec823/fselect-0.7.4/src/parser.rs:49] roots = [
Root {
path: ".",
min_depth: 0,
max_depth: 0,
archives: false,
symlinks: false,
gitignore: None,
hgignore: None,
dockerignore: None,
traversal: Bfs,
regexp: false,
},
]
query: Could not parse tokens at the end of the query!fselect "name, accessed from . where is_file = 1 and accessed gt '1 hour ago'"use-fselect-to-find-files.ipynb 2021-04-04 22:52:11
use-fselect-to-find-files-checkpoint.ipynb 2021-04-04 22:48:11
!fselect "name, accessed from . where is_file = 1 and accessed lt '1 hour ago'"tips-on-cargo.markdown 2021-04-02 08:16:26
tips-on-rustc.markdown 2021-04-02 08:16:26
File Type Related Finding¶
Find broken symbolic links.
:::bash find . -xtype l # or find -L . -type lFind executable files in current directory
:::bash find . -maxdepth 1 -type f -executable
User Related Finding¶
Find files that belong to a user but writable by its group or other people.
:::bash find /path/to/file -user user1 -perm /022Check file type of all files under the current directory.
:::bash find . -type f | xargs file
-perm mode: File’s permission bits are exactly mode (octal or symbolic). -perm -mode: All of the permission bits mode are set for the file. -perm /mode: Any of the permission bits mode are set for the file. a little bit trick about how to understand the last 2 permission criterias. as suggested, think in terms of permission BITs (0/1)
The following command finds all files that readable or writable by the group or (readable or writable) by others.
:::bash
find /path/to/file -user user1 -perm /066The following command find all files that readable and writable by the group and (readable and writable) by others.
:::bash
find /path/to/file -user user1 -perm -066The following command find all files that readable or writable by the group and (readable or writable) by others.
:::bash
find /path/to/file -user user1 -perm /060 -perm /006Find Python scripts in the current directory recursively
but ignore those under directories with the name .ipynb_checkpoints.
:::bash
find . -type f -iname '*.py' -not -path '*/.ipynb_checkpoints/*'