LS redirection to a file in same folder


 
Thread Tools Search this Thread
Operating Systems Solaris LS redirection to a file in same folder
# 1  
Old 02-22-2011
Lightbulb LS redirection to a file in same folder

Hello,

I need an input from you all.
I want to redirect the output of 'ls' command to a file
but the file should not display the output file name in it.
scenario:
------------

$pwd
/home/user1
$ls
file1 file2
$ls > file3
$cat file3
file1 file2 file3

In this i dont wish the file3 to be part of the output.
I know if i do redirect to some other folder (ls > /tmp/file3) file3 will not be displayed. Smilie
But can the same be achieved by some option in ls by redirecting to a file in same folder. Smilie

Thanks in advance
Aravind
# 2  
Old 02-22-2011
Is the following possible
Code:
ls | grep -v file3 > file3

# 3  
Old 02-22-2011
alternatively:

Code:
ls > .file3

# 4  
Old 02-23-2011
MySQL

Thanks jlliagre
Your suggestion works fine in RHEL.
Quote:
RHEL/FC9 output
$cat .3
1
2

But on AIX i am still getting the same file name
Quote:
AIX 6.1 output
$cat .3
.3
1
2

But i got a suggestion from web to fix this on AIX too. SmilieSmilie
Quote:
$ls | sort | tee > 3
$cat 3
1
2
Thanks every one for your inputs Smilie
Aravind
# 5  
Old 02-23-2011
AIX "ls" exhibits a very non standard behavior. This won't happen if "ls" isn't run as root though.
Here is an alternative more robust than the "sort | tee" hack:
Code:
ls >/tmp/ls.$$ && mv /tmp/ls.$$ file3

# 6  
Old 02-23-2011
Bug

Thanks again SmilieSmilie
But i am not able to understand this logic Smilie when running this command on AIX.
>> ls | sort | tee 3 displays
1
2

but
>> ls | sort > 3
cat 3 displays
1
2
3
But are input redirection only. Still i am little baffled why the output file (3) is not getting recorded when using "TEE"?
Can you give me some input on this please?

-Aravind
# 7  
Old 02-23-2011
As I wrote this hack isn't robust and might just not work depending on various factors so shouldn't be relied upon.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

2. Shell Programming and Scripting

want to move set of file from one folder to another folder

Hi all, let me explain my requirments i am having 5 folder with different name for eg) abc , cdf , efd, rtg, ead each 5 folders contain 15 files i want to move 10 files to some other folder, remain 5 files should be there in the same folder. give me some suggestion on this. (6 Replies)
Discussion started by: natraj005
6 Replies

3. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

4. UNIX for Dummies Questions & Answers

Output file redirection

Suppose I have a file named a When I write cat a>a The following error message is displayed cat: a: input file is output file and my file a is truncated to zero size. Also the exit status of the last command is 1 Can someone tell me what actually happens when I do so? (1 Reply)
Discussion started by: aagajaba
1 Replies

5. Shell Programming and Scripting

File redirection question

Hi all, I am working with the Grinder tool (unrelated to my question) to redirect the output of a program to a file as follows: java -cp $CLASSPATH net.grinder.TCPProxy > grinder.txt This is a proxy server which pipes output to a file. When I do something on my proxy, more and more goes to... (1 Reply)
Discussion started by: Annorax
1 Replies

6. Shell Programming and Scripting

fbackup redirection to a file.

Hi, I have a fbackup step as below /bin/nice /etc/fbackup -f /dev/rmt/0m -i / -I /opt/monitrol/tmp/Index.full Now the errors that i will get in case of the fbackup step, I want to redirect them to a file. Please help me how to redirect to a file. Thanks, Avik. (5 Replies)
Discussion started by: avik.nandi
5 Replies

7. Shell Programming and Scripting

Move the file from one folder to another folder

Hi, I have a requirement to move a file from one folder(a) to another folder(b) only when folder (b) have a write permission. Folder permission is 755 If the permission is otherthan 755 we need to come out of the loop I will appreciate your help Thanks Soll (1 Reply)
Discussion started by: sollins
1 Replies

8. Shell Programming and Scripting

file redirection problem

my querry is suppose i have duplicate std i/p with FD-3 --exec 0<&3 now redirected std i/p to a file ----exec 0<file1 suppose i am reading the file line by line --while read LINE cutting some fields and comparing it with a variable and if a match is found ... (0 Replies)
Discussion started by: mobydick
0 Replies

9. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies

10. UNIX for Dummies Questions & Answers

File redirection

Is it possible to sh a command and receive the standard output on the scrren and use file redirection ie ls -lt > test. Also On SCO-UNIX there was a tellme command which displayed a message when a script had finished running is there something similar for HP UNIX as it is not working. (4 Replies)
Discussion started by: namtab
4 Replies
Login or Register to Ask a Question