Not able to list sub-directories properly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Not able to list sub-directories properly
# 1  
Old 06-09-2016
Linux Not able to list sub-directories properly

HI,

This is my home directory /home/xeccc5z under that I have so my directores and one among is server

under the directory server again i have three files named linux,windows,aix

am trying to execute the following command which should go into server directory and display the files inside that directory

Code:
cd /home/xeccc5z/server|ls

but for the above command rather displaying linux,windows,aix its displaying all the directories under /home/xeccc5z/

can some one suggest me please
# 2  
Old 06-09-2016
Perhaps
Code:
cd /home/xeccc5z/server && ls

or
Code:
ls /home/xeccc5z/server

# 3  
Old 06-09-2016
can you tell why the PIPE "|" is not working
# 4  
Old 06-09-2016
Quote:
Originally Posted by xeccc5z
can you tell why the PIPE "|" is not working
A pipe ties the stdout of a program to the stdin of another.
cd does not stdout and ls does not read its arguments from stdin, but from the command line arguments.
This User Gave Thanks to Aia For This Post:
# 5  
Old 06-09-2016
Quote:
Originally Posted by xeccc5z
can you tell why the PIPE "|" is not working
Hello xeccc5z,

In general, when you start a process it has its own "environment" including all environment variables and current working directory. Any changes that process makes are limited to that process and its children. Imagine the chaos that could ensue if processes could affect their siblings, or even worse, their parents. When you have pipeline you have a parent, the shell in which you specified a pipeline and a number of children all "piped" together, each child is has an independent environment.
Code:
  
(cd /etc && ( ls | grep x))

Here the whole thing is in () so that it runs in a child process, and hence the cd does not affect the current shell, but does affect the pipeline which is running in a (grand-)child process. Also that's not what pipes are for. They're for directing input/output, not controlling the state of the shell. If you want the behavior you're describing, use a subshell:
Code:
( cd /etc; ls )

You could go through following URL to understand about PIPES more.
The Unix Command Line: Pipes and Redirects

Thanks,
R. Singh

Last edited by RavinderSingh13; 06-09-2016 at 03:11 AM.. Reason: Added link now for user.
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

2. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

3. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

4. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

Hi , I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order. Please help me in this regard and many... (4 Replies)
Discussion started by: nmakkena
4 Replies

5. Shell Programming and Scripting

Want to Get List of All directories

:confused: Hi, Is there any one-lier through which I will be able to reach to last directory excluding all files only directrory and sub-directoris should be displayed from the current path. Thanks in advance (7 Replies)
Discussion started by: niceboykunal123
7 Replies

6. Shell Programming and Scripting

List of directories into a nested list

I have a list of directories like this a a/b a/c a/d a/d/e a/d/f a/d/g a/d/g/h a/i I would like to convert this list into another list, nested like this a{b{} c{} d{e{} f{} g{h{}}} i{}} Here is a pseudo algorithm for this Add a: (1 Reply)
Discussion started by: Ilja
1 Replies

7. UNIX for Dummies Questions & Answers

how to list directories only

I would like to know how to list directories only without a / at the end. I would like to only see them in my current dir. for example ls - d */ gives dir1/ dir2/ dir3/ dir4/ but is there a way to get only dir1 dir2 dir3 i need it to use them as inputs in a foreach loop... (3 Replies)
Discussion started by: yodadbl07
3 Replies

8. Filesystems, Disks and Memory

deleting directories from a list

I have a need to remove a bunch of old user home directories from my OS X server. Using BASH and ls, I've been able to redirect the directory structure to a file with 'ls -l >userslist'. I've then manually sifted through the list for directories whos owner doesn't match the a given directory name... (1 Reply)
Discussion started by: amacgeek
1 Replies

9. UNIX for Dummies Questions & Answers

How to list only directories?

How to list directories (not sub-directories) from a given path? (4 Replies)
Discussion started by: videsh77
4 Replies

10. UNIX for Dummies Questions & Answers

List directories

Is there any way to list only directories in particular file system? Malay (3 Replies)
Discussion started by: malaymaru
3 Replies
Login or Register to Ask a Question