cancel
Showing results for 
Search instead for 
Did you mean: 
kubeadm
Flight Engineer Flight Engineer
Flight Engineer
  • 15.5K Views

What's your favorite tool/cmd in Linux?

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? 

Tags (2)
49 Replies
itnet7
Flight Engineer
Flight Engineer
  • 5,117 Views

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

 

 

Aloysius
Cadet
Cadet
  • 5,116 Views

I do a lot of network traffic analysis, so pcap, nmap, mtr, nmon all find weekly use.

  • 5,107 Views

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

 

  

0 Kudos
sbulav
Flight Engineer Flight Engineer
Flight Engineer
  • 5,090 Views

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

 

Ap023
Cadet
Cadet
  • 5,084 Views

my history say ls -ltrh


ap8
0 Kudos
Rajpol
Cadet
Cadet
  • 5,074 Views

ps aux --sort -rss 
Above command helps to find out the process which are consuming high memory.

jfern
Cadet
Cadet
  • 4,994 Views

I don't link I have a-1, but if I were to choose, the combination of | PIPE, grep, and cut are so beautiful.

0 Kudos
marco_ab
Cadet
Cadet
  • 4,983 Views

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

Florian
Moderator
Moderator
  • 4,981 Views

A little find exercise.

  1. Create 10000 files in a sub directory called example
    Spoiler
    $ mkdir example ; cd example
    $ for i in $(seq 1 10000); do touch file-$i ; done
  2. Delete them using find -exec. Use the time command to see how long it takes.
    Spoiler
    $time find . -exec rm {}
    real	0m6.288s
    user	0m3.530s
    sys	0m2.736s

     

  3. Now try again using -delete
    Spoiler
    $ time find * -delete 
    real	0m0.186s
    user	0m0.037s
    sys	0m0.149s
    Much faster, isn't it?
  4. How about changing permissions? Create 10000 files and remove the read permission for other on each.
    Spoiler
    $ for i in $(seq 1 10000) ; do touch file-$i ; done
    $ find . -exec chmod o-r {} \;
  5. As mentioned in another post, delete speeds things up, because it doesn't call external commands. Instead of a calling external commands one at a time with -exec, you can use a tool called xargs to do this less often. 
    Spoiler
    $ find . | xargs chmod o-r
  6. There is a catch, filenames could contain spaces, so a simple find | xargs might not work.
    Have a look at -0 option in xarg's man page and try again.
    Spoiler
    $ 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
Tags (1)
Radesh
Flight Engineer Flight Engineer
Flight Engineer
  • 4,758 Views

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.

 

Join the discussion
You must log in to join this conversation.