[Courses][Linux comands] tee, file, stat, find

Carla Schroder carla at bratgrrl.com
Wed Mar 10 10:30:18 EST 2004


The Unix/Linux world is chock-full of weird little specialized commands. 75% 
of using Linux is finding the little buggers. Here's a random assortment for 
your entertainment:

tee  
   view output that is being directed to a file on standard output. For 
example, you want to save the output of "make", and watch it live:

$ make install | tee makeoutput.txt

file
   determine the file type. One of Linux's most finest features is it can tell 
the real file type all by itself, and is not fooled by silly file extensions. 
Extensions are for us frail humans. 

$ file makeoutput.txt
makeoutput.txt: ASCII text

stat
   this command gives you the complete dish on files:

$ stat dmesg.txt 
  Size: 7384            Blocks: 16         IO Block: 4096   regular file
Device: 307h/775d       Inode: 39104       Links: 2
Access: (0644/-rw-r--r--)  Uid: ( 1000/   carla)   Gid: ( 1000/   carla)
Access: 2004-03-10 08:55:32.000000000 -0800
Modify: 2004-03-10 08:52:26.000000000 -0800
Change: 2004-03-10 09:07:46.000000000 -0800

This is useful when you're deleting files, because it shows the number of 
links. Every file has at least one link, from the parent directory. If there 
are hard links to a file, that is like having copies of the file, so they all 
need to be deleted. How do you find these? Shoo, Linux thinks of everything:

$ find ~ -inum 39104
/home/carla/dmesg.txt
/home/carla/linkdmesg
 
And we can confirm with stat:

$ stat dmesg.txt linkdmesg
  File: `dmesg.txt'
  Size: 7384            Blocks: 16         IO Block: 4096   regular file
Device: 307h/775d       Inode: 39104       Links: 2
Access: (0644/-rw-r--r--)  Uid: ( 1000/   carla)   Gid: ( 1000/   carla)
Access: 2004-03-10 08:55:32.000000000 -0800
Modify: 2004-03-10 08:52:26.000000000 -0800
Change: 2004-03-10 09:07:46.000000000 -0800

  File: `linkdmesg'
  Size: 7384            Blocks: 16         IO Block: 4096   regular file
Device: 307h/775d       Inode: 39104       Links: 2
Access: (0644/-rw-r--r--)  Uid: ( 1000/   carla)   Gid: ( 1000/   carla)
Access: 2004-03-10 08:55:32.000000000 -0800
Modify: 2004-03-10 08:52:26.000000000 -0800
Change: 2004-03-10 09:07:46.000000000 -0800

If you're doing a system-wide search, it's best to do it as root, so find can 
search read-protected directories.

# find / -inum 39104 

When you're fooling around with Linux, and need some files to test and play 
with, let find dig them up for you. Let's say you want to find files with 
lots of inodes, in this example, 10:

$ find ~ -links 10

Maybe you want some nice named pipes to amuse yourself:

$ find /tmp -type s
/tmp/.ICE-unix/736
/tmp/.ICE-unix/dcop599-1078934183
/tmp/orbit-carla/linc-3e6-0-33869d73c9cb9
/tmp/orbit-carla/linc-3ed-0-41da98e3204cc

Or soft links:

$ find /etc  -type l
/etc/X11/xkb/compiled
/etc/X11/Xresources/libranet-Xcursor
/etc/X11/app-defaults/XScreenSaver

As always, read the man and info pages. They contain complete command options. 
If you're struggling with how to read dommed man pages, try 'man man'. Be 
bold- experiment to your heart's content, as an ordinary user of course!

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~
Carla Schroder
www.tuxcomputing.com
this message brought to you
by Libranet 2.8 and Kmail
~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the Courses mailing list