Sponsored Content
Top Forums Shell Programming and Scripting Script that displays contents of a directory Post 302593874 by methyl on Sunday 29th of January 2012 05:41:59 PM
Old 01-29-2012
Similar to Corona688, but retaining and revising the question.

Code:
#/bin/sh
echo "Please enter the name of a subdirectory under /home/other"
read dir
if [ -d "/home/other/${dir}" ]
then
      ls -la "/home/other/${dir}"
else
      echo "Directory does not exist: /home/other/${dir}"
fi

See "man test" for the explanation of "if ... -d".

Last edited by methyl; 01-29-2012 at 06:45 PM.. Reason: mispaste and rewrite
This User Gave Thanks to methyl For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

pine email tool displays directory listing

I just moved my mail server (qmail in maildir format) from a solaris box to a RedHat linux box. When I select some inboxes in pine, I get a directory listing of the inbox, its not automatically opening the qmail cur directory. This doesn't happen with all, and it doesn't happen at all on... (0 Replies)
Discussion started by: cross
0 Replies

2. UNIX for Dummies Questions & Answers

list contents of directory

I want to list the contents of a directory, but I do not want to use the ls, is there another way?? (3 Replies)
Discussion started by: carl_vieyra
3 Replies

3. UNIX for Dummies Questions & Answers

Best way to list a directory's contents?

Hey guys! I'm so glad I found this site, I've had so many questions and have been left alone for roughly a year scanning man pages but It's just not quite cutting it for some things. So, I often like to list directories when browsing around my local machine, a friend's machine, or my web... (6 Replies)
Discussion started by: bbilheimer
6 Replies

4. Solaris

Directory should not be deleted, But the contents can be

Hi Guys, I have an user's home directory set to /home/A And A contains the following directories B & C Is there some way in solaris by which i can prevent the directories B and C from getting deleted by the user but the contents of the directories B & C can be deleted ? Also i have... (2 Replies)
Discussion started by: localhost
2 Replies

5. Shell Programming and Scripting

Regular Expression on Directory Contents

This should be an easy question for you gurus. :) How can I create a regular expression to match all files in the current directory that have only one period in their file name, and also not contain the string "abc" before the period? It would match: foo.txt foobar.log It would not... (4 Replies)
Discussion started by: blondie53403
4 Replies

6. Shell Programming and Scripting

Remove contents of directory, but not directory

What's the best way to delete everything in a directory, but not the directory itself, without using shell wildcards? (9 Replies)
Discussion started by: pdc
9 Replies

7. Shell Programming and Scripting

script to delete contents in a directory by date

Hi , I am trying to make a cron job to delete the contents of a directory in a linux environment.The contents created before 2 days should get deleted by this job.Here is what i have written : /usr/bin/find / -name *.log -ctime +2 -exec /bin/rm -f {} \; Is it correct....If not so,please... (9 Replies)
Discussion started by: d8011
9 Replies

8. UNIX for Dummies Questions & Answers

script works well but displays " line 6: =: No such file or directory"

strange :) can you tell why?:cool: #!/bin/bash echo " enter your age " read age if ; then echo " you do not have to pay tax " elif ]; then echo " you are eligible for income tax " else echo " you dont have to pay tax " fi (3 Replies)
Discussion started by: me.
3 Replies

9. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

10. Shell Programming and Scripting

Script Output Displays Multiple Text

Hello there, I'm using a read-while loop to preserve the word Failed within a text file. For example, if the word Failed exist twice in a single text file, my STDOUT should re-direct to a new text file and display Failed twice. My output is attached to this thread. I would like output to... (4 Replies)
Discussion started by: SysAdminRialto
4 Replies
delete directory(1m)													      delete directory(1m)

NAME
delete directory - Deletes a directory SYNOPSIS
cdscp delete directory directory-name ARGUMENTS
The full name of the directory. DESCRIPTION
The delete directory command deletes a directory. The directory cannot contain any object entries, soft links, or child pointers. The master replica must be the only remaining replica in the cell. Use the delete replica command if you need to remove read-only replicas. Privilege Required You must have delete permission to the directory and write permission to the clearinghouse that stores the master replica of the directory. The server principal needs administer permission to the parent directory or delete permission to the child pointer that points to the directory you intend to delete. NOTE
This command is replaced at Revision 1.1 by the dcecp command and may not be provided in future releases of DCE. EXAMPLE
The following command deletes the directory /.:/eng from the namespace: cdscp> delete directory /.:/eng RELATED INFORMATION
Commands: create directory(1m), delete replica(1m), list directory(1m), set directory(1m), set directory to skulk(1m), show directory(1m) delete directory(1m)
All times are GMT -4. The time now is 12:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy