Help with these unix commands!


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with these unix commands!
# 1  
Old 03-02-2007
Help with these unix commands!

Hi to all,

I have just started to learn Unix, and am having problems trying to understand the following two unix commands. if any1 could help i would greatly appreciate it.

1) ls -s | sort -nr | head -3

2) man -k c | grep -i ' c* ' | grep 1

i understand that for 1) the command will locate the file and not the contents of the file. for 2) i understand that the command is to do with the unix manual.

as you can see i am a beginner.

thanks in advance
vish
# 2  
Old 03-02-2007
The best shot will be to check the man pages for "man, head, ls, grep, sort" and their respective parameters. Also, you can execute the commands in your shell, this will answer your questions best.
# 3  
Old 03-02-2007
man -k "KEYWORD" #List all man pages that is same as that of of KEYWORD

Probably the commands that you posted might beprinting all all man "KEYWORD" pages in man section (1).
# 4  
Old 03-04-2007
Quote:
Originally Posted by Vn3050
Hi to all,

I have just started to learn Unix, and am having problems trying to understand the following two unix commands. if any1 could help i would greatly appreciate it.

1) ls -s | sort -nr | head -3
Code:
ls -s  |  ## print the filenames in the current directory preceded by the size in blocks
sort -nr |  ## sort the output numerically in reverse order
head -3  ## print the first three lines

In other words, show the sizes and filenames of the 3 largest files in the current directory.

Quote:
2) man -k c | grep -i ' c* ' | grep 1
Code:
man -k c |  ## print the commands whose names and descriptions contain the letter c
grep -i ' c* ' | ## search for output lines which contina an upper or lowercase "c"
grep 1 ## print only lines found by the previous grep which contain the number 1


Quote:
i understand that for 1) the command will locate the file and not the contents of the file. for 2) i understand that the command is to do with the unix manual.

as you can see i am a beginner.

thanks in advance
vish
# 5  
Old 03-04-2007
Quote:
Code:
grep -i ' c* ' | ## search for output lines which contains an upper or lowercase "c"

Actually that is not correct, as written here and in the original post it will match any lines in which the input contains two spaces, the 'c' is rendered pointless by the use of *. This is a typical example of an 'excessively greedy' regular expression.

Last edited by reborg; 03-05-2007 at 07:59 PM.. Reason: correct an inaccuracy, two spaces, not one.
# 6  
Old 03-05-2007
Quote:
Originally Posted by reborg
Code:
grep -i ' c* ' | ## search for output lines which contains an upper or lowercase "c"

Actually that is not correct, as written here and in the original post it will match any lines in which the input contains a space, the 'c' is rendered pointless by the use of *. This is a typical example of an 'excessively greedy' regular expression.
Quite right. It actually matches any line which contains two spaces separated by zero or more upper or lower case Cs.
# 7  
Old 03-05-2007
thanks for all your help!

i am also stuck on the following question, but after learning a bit more unix. i have written an answer to it. Can anyone check to see if it is correct and what improvements need to be made?

Question:

Write a pipeline that updates the content of a file (a file of your choice) by replacing all matches of the word ‘and' with the symbol ‘&' and by replacing the end of each line with the user login name. If the command completes successfully it should print ‘YES', otherwise it should print ‘NO'.

Answer:

cat text.txt | sed -e s/and/$USER/g -e s/$/”&”/g | cat -> text.txt
&& echo yes || echo no

thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unix Commands help

Having trouble doing the following things, I know it has something to do with using metacharacters but I'm not able to get it working correctly. I need a command to get a long directory listing of all the files that have: exactly two characters following the letters zot. all files that... (1 Reply)
Discussion started by: lakers34kb
1 Replies

2. UNIX for Dummies Questions & Answers

$ commands in unix

What are the various commands which use $ in unix and what do each of these indicate? eg: echo $? returns the success status of the previous commands..similarly $$ returns some numeric value..wat exactly are these? From where can a download a document which can help me getting more details about... (2 Replies)
Discussion started by: DDS
2 Replies

3. UNIX for Dummies Questions & Answers

ALL unix commands

Hello Folks Where can I find all the unix commands with explanations , on the internet. I am searching but most of the sites are listing a few of the important ones. PLease guide through thanks (4 Replies)
Discussion started by: supercops
4 Replies

4. UNIX for Dummies Questions & Answers

unix commands...

i want to know how to do a few things using unix commands. firstly say I have a .txt file that contains random lines like Hello Goodbye I'm tired 5 74 using the grep command how can I get a list of lines that contain ONLY digits? also using pipes to combine ls and grep commands how... (5 Replies)
Discussion started by: ez45
5 Replies

5. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

6. UNIX Desktop Questions & Answers

Unix commands

What is the unix command that will display the current UTC time, hours, and minutes only. What is the unix command for sorting in descending order. What is the unix command for display the first 10 characters in a file. (4 Replies)
Discussion started by: charlton
4 Replies

7. HP-UX

Unix Commands

HP 9000/800 Server running HP-UX UNIX Server, users are connected via LAN and dialup connection. Need help to write SHELL SCRIPT or UNIX Commands which would perform the following: -ping IP address of all login/connected users to our server -send customized text message to all the login... (1 Reply)
Discussion started by: Moinul Haque
1 Replies

8. UNIX for Dummies Questions & Answers

Unix Commands?

I would be happy to streamline some of the commands I am trying to learn with easy to remember terms, like dir for ls -l. I am wondering if you script certain commands for every time you start-up your system, can use those aliases there? If so, would that prove a problem for administrators who... (2 Replies)
Discussion started by: wmosley2
2 Replies

9. UNIX for Dummies Questions & Answers

Maingrame to UNIX sending UNIX commands

I want to know if there is a way to send unix commands thru FTP from a mainframe to kick off Autosys Jobs. I just need to send a command from the mainframe to UNIX and have UNIX execute that command. (2 Replies)
Discussion started by: skammer
2 Replies

10. UNIX for Dummies Questions & Answers

Unix Commands

Where can I get a list of basic commands ? I want to get up to speed as soon as possible ? thanks..... (4 Replies)
Discussion started by: drukkie
4 Replies
Login or Register to Ask a Question