Re: I'ma Well Versed UNIX User But This Baffles Me:

From: Khamba Staring (QdK_at_quickdekay.net)
Date: 07/20/04


Date: Tue, 20 Jul 2004 13:46:28 +0000 (UTC)

Assam Syrix <assyrix@altavista.net> wrote:
> Can anybody tell me which command to type to display the contents of a
> directory in a shell? Also, I don't know how to change directories. I

Displaying the contents of a directory is difficult! You first need to know
which shell you're using:

- if you're using (t)csh, type:

    foreach i ( `echo *` )
    echo "$i" >> /tmp/q
    end

  The contents are now in a file named /tmp/q . Read it with

    cat /tmp/q | more

- if you're using (ba)sh, type:

    for i in `echo *; do
    echo "$i" >> /tmp/q
    done

  Luckily the method of reading /tmp/q is the same as with (t)csh.

One problem I haven't tackled yet is that /tmp/q will grow over time;
it's weird. The only solution is rebooting; the file is empty after a
reboot.

Changing the working directory also isn't a trivial matter. The directory
structure is an indexing system. If you have a directory 'help' and
a file in it called '01_intro', it's accessibly by the path help/01_intro .
now if you change the working directory, you've just messed up your
whole indexing system! Your current 'root' is 'help'. Just think what
that can do to a structure!

However, if you're still willing to change your working directory, you'll
first need to compile a program (call it change.c):

--(cut here)
/*
** Copyright (C) 2004 by QdK, all rights reversed
**
** Gre3taZ t0 aLl y@ p3oPlE!11!1
*/
#include <stdio.h>

int main(int argc, char *argv[])
{
  chdir(argv[1]);
  system("/bin/sh");

  return(1);
}
--(cut here)

Now compile it, assuming you've got gcc installed:

  gcc -o change change.c

Next, you'll need to know where the directory is you want to change to.
This is best done with the command 'find':

  find / -name <insert name here> -exec $HOME/change "{}" \;

It's a very cpu intensive matter, yet another reason not to change working
directories. Also, there's a bug in the change.c code. Sometimes it just
crashes when I forget to supply a directory-- crazy! Must be gcc....

> am an experienced UNIX administrator but cannot figure these two

It's called UNOX, not UNIX. Geez

> simple commands out. And please don't aske me to use the man page - I
> am afraid that I am too lazy and cannot be bothered. Cheers!

There're no manpages for things this difficult; every manpage only
describes one command; as you can see, you need more than 1 command
to do what you are asking, so there's no use in reading manpages.

Also, I've noticed not every admin pays enough attention to security.
There's this problem with the root account on my system; it hasn't got
a password. Now this makes my system very hacker-friendly so I added
a line to my .cshrc which wil prevent hackers from successfully logging
in:

  echo "reboot" >> $HOME/.cshrc

Kind regards,

-- Khamba Staring
Disclaimer: my employer and I never agree.



Relevant Pages

  • Re: Mike does the "Impossible"! Releases "hm" Version 3.0
    ... > standard linux command included on every Linux distro. ... Mike, I swear to God, until this moment I thought you were joking about ... e.g. a "working directory" and a set of "environment variables." ... you may be able to implement your "hm" command to work within a shell ...
    (comp.os.linux.development.apps)
  • Re: what permissions are needed to let a php script call the "svn update" subversion command?
    ... The working directory (I assume you mean the directory with the ... with the 'pwd' command. ... a valid password and shell (same shell you're using for root, ... This account is currently not available. ...
    (comp.unix.programmer)
  • Re: Bash: pipe once more
    ... if I pipe the output of a cd command the working directory doesn't change. ... redefine what a builtin does, using a function, and a special command name the shell recognizes that forces it to use the builtin. ...
    (Debian-User)
  • Re: basic perl query
    ... want either, as that forks off a different process, executes your cd ... command, ... working directory of the process used to start perl is unaffected. ... it invokes a shell and passes that argument to the shell to be ...
    (perl.beginners)
  • Bash-4.0 available for FTP
    ... Unlike previous bash distributions, this tar file includes the formatted ... The shell has been changed to be more ... rigorous about parsing commands inside command substitutions, ... Changes have been made to the Readline library being released at ...
    (gnu.announce)