The command "find" is one of my favorites -
Search for files in /search/path/ which are older than 5 days.
(if you want to search for directories, then use: -type d )
find /search/path/ -type f -mtime +5 -print
find /search/path/ -type d -mtime +5 -print
If you want to do something with those files after you've found them, use: -exec <somecmd> '{}' \;
Example, delete files older than 50 days in the /search/path directory
find /search/path/ -type f -mtime +50 -exec rm '{}' \;
If only there is a 'find' equivalent in the real world ... now, where did I put my keys?
There are Sooooooo many good tool/cmd(s) in Linux it would be hard to say exactly which are my favorites. I often use the following:
mlocate - updatedb; locate <anything> It's important to note your results are only good as your last updatedb command :-)
byobu - tmux/screen wrapper that shows an informational Banner at the bottom
irssi for IRC
yum info/list/whatprovides */<filename>
pvs, vgs, lvs
tar pipes
rsync
scp
sftp
I do a lot of network traffic analysis, so pcap, nmap, mtr, nmon all find weekly use.
The for loop is the beginning of all automation. Tie it to a list or to another command that supplies a list, add in ssh keys, and yehaaa, you are on your way.
for i in `cat $mylist`
do
#amazing things
done
I'm writing a lot of complicated commands, so I'm following little tricks a lot:
ctrl+x,e - Edit current command in your $EDITOR
fc - Edit last command(from history) in your $EDITOR
my history say ls -ltrh
ps aux --sort -rss
Above command helps to find out the process which are consuming high memory.
I don't link I have a-1, but if I were to choose, the combination of | PIPE, grep, and cut are so beautiful.
I do use several commands daily, but I can't live without : grep, sed, cut or awk really usefull.
For other tools/commands I shoud say: sar, ss, df, du, top, kill, ps axf, vi, sudo ... etc almost all haha
A little find exercise.
$ mkdir example ; cd example
$ for i in $(seq 1 10000); do touch file-$i ; done
$time find . -exec rm {} real 0m6.288s user 0m3.530s sys 0m2.736s
$ time find * -delete real 0m0.186s user 0m0.037s sys 0m0.149sMuch faster, isn't it?
$ for i in $(seq 1 10000) ; do touch file-$i ; done $ find . -exec chmod o-r {} \;
$ find . | xargs chmod o-r
$ for i in $(seq 1 10000); do touch file\ $i ; done $ find | xargs chmod o-r .. chmod: cannot access '10000': No such file or directory $find -print0 | xargs -0 chmod o-r
I gave some kudos to @flozano .
In the same vein... ansible-doc.
Since I've taken to doing a bunch with Ansible, I find the documentation to be indispensible.
Other than 'help' commands, I love awk. I use it for most operations where I would otherwise use grep, because I usually want to find some pattern, and report on a portion of it. I find that awk makes doing so pretty easy.
Red Hat
Learning Community
A collaborative learning environment, enabling open source skill development.