4,348
edits
No edit summary |
Tags: Mobile edit Mobile web edit |
||
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Finding or searching through files and folders = | |||
== Search for a string == | |||
A case-sensitive search through all of the files from current folder and below. | |||
<syntaxhighlight lang="bash"> | |||
$ find . | xargs grep -s "mystring" | more | |||
</syntaxhighlight> | |||
A ''case-insensitive'' search through all of the files from current folder and below. | |||
<syntaxhighlight lang="bash"> | |||
$ find . | xargs grep -si "mystring" | more | |||
</syntaxhighlight> | |||
A ''case-insensitive'' search through all of the files from current folder and below, and truncate long search results. | |||
<syntaxhighlight lang="bash"> | |||
$ find . | xargs grep -sioE ".{0,20}mystring.{0,20}" | more | |||
</syntaxhighlight> | |||
An alternative way to search for keywords. | |||
<source lang="bash"> | |||
$ cat file.txt | grep word | |||
$ grep -r -e word /etc" | |||
</source> | |||
= Copy including hidden files = | = Copy including hidden files = | ||
Line 7: | Line 38: | ||
</source> | </source> | ||
= Delete files recursively = | |||
= Delete files = | |||
== Delete files recursively == | |||
* ''Lasted tested on Ubuntu 16.04.2 LTS (xenial) | * ''Lasted tested on Ubuntu 16.04.2 LTS (xenial) | ||
Line 13: | Line 48: | ||
<source lang="bash"> | <source lang="bash"> | ||
$ find . -type f -name "*.mp4" -exec rm {} \; | $ find . -type f -name "*.mp4" -exec rm {} \; | ||
</source> | |||
== Fastest way to delete a folder == | |||
* {{testedon|2021-03-09|RHEL 8.3}} | |||
<source lang="console"> | |||
$ mkdir empty | |||
$ rsync -a --delete empty/ foldername | |||
</source> | |||
== Another method of deleting files under a folder == | |||
<source lang="console"> | |||
$ ls -f1 | xargs rm | |||
</source> | </source> | ||
= Setting a default group for a folder = | = Setting a default group for a folder = | ||
* ''Last tested on Ubuntu 16.04 LTS (xenial)'' | * ''Last tested on Ubuntu 16.04 LTS (xenial)'' | ||
Line 56: | Line 109: | ||
<syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight> | <syntaxhighlight lang="bash">$ gzip -d file.gz</syntaxhighlight> | ||
= Zip a folder = | |||
<source lang="bash"> | |||
$ zip -r test.zip ./test | |||
</source> | |||
= Mirror a folder = | = Mirror a folder = | ||
{{testedon|2020-06-08|CentOS 8}} | |||
Copy ALL and keep EVERYTHING same without deleting the source, but deleting files on the target folder that are not found in the source. | |||
<source lang="console"> | |||
$ rsync --delete -HAXavr /source/folder/foldername/ /target/folder/foldername/ | |||
</source> | |||
* ''Last tested on Ubuntu 16.04 LTS (xenial)'' | * ''Last tested on Ubuntu 16.04 LTS (xenial)'' | ||
Line 75: | Line 145: | ||
<syntaxhighlight lang="bash" highlight="1"> | <syntaxhighlight lang="bash" highlight="1"> | ||
$ rsync -azv ~/folder_a/ mhan@tom.myserver.com:~/folder_b/ | $ rsync -azv ~/folder_a/ mhan@tom.myserver.com:~/folder_b/ | ||
</syntaxhighlight> | |||
= Move files = | |||
<syntaxhighlight lang="bash" highlight="1"> | |||
$ rsync --remove-source-files -HAXzvhr /source/chanbara/* ./chanbara/ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
= Move files older or less than x days = | = Move files older or less than x days = | ||
* ''Last tested on Ubuntu 14.04.5 LTS (trusty)'' | * ''Last tested on Ubuntu 14.04.5 LTS (trusty)'' | ||