LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-04-2017, 06:54 PM   #1
Andeez.91
LQ Newbie
 
Registered: Sep 2017
Posts: 3

Rep: Reputation: Disabled
learning Unix


Hello! Can someone help me with an explanation of this command?

ls /etc | grep conf | grep -V "\." | sort > ~/conf

I hope you can explain each section and what it all means and what this is supposed to do... the only things i think i understand is that it is a pipe.. and its supposed to redirect to the conf file?

thank you so much for your help!
 
Old 09-04-2017, 07:03 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 17,862

Rep: Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598Reputation: 2598
Well, you could just
Code:
man <cmd>
for each cmd and read the manual and/or google would do as well.


Anyway... basically it lists the /etc dir, looks for the string 'conf' in the o/p, attempts to eliminate strings with literal '.'s in them (although that won't work; uppercase V is version, lowercase v is 'invert-match' ie don't match), then sort (sic) the results into a file (conf) in the user's home dir .

HTH
 
Old 09-04-2017, 08:11 PM   #3
andros705
LQ Newbie
 
Registered: Feb 2016
Posts: 11

Rep: Reputation: Disabled
A much better option (which is doing the same thing)
Code:
ls /etc | awk '/\.conf$/' > ~/conf
"ls /etc" lists all files from the /etc directory, then it passes the results to the awk command which is using the Reqex to filter out all the files which do not end with ".conf", after that it writes the result to the "conf" file located inside the users home directory.

There is no need for the "sort" command because "ls" is already returning the sorted results (depends on the configuration through)

"|" (Pipe) means pass the result of the last command to the next command
">" (Redirection) means write the result to whatever is on the right side (file, device, socket)

Last edited by andros705; 09-04-2017 at 08:12 PM. Reason: Fix typo
 
1 members found this post helpful.
Old 09-05-2017, 04:20 AM   #4
aragorn2101
Member
 
Registered: Dec 2012
Location: Mauritius
Distribution: Slackware
Posts: 553

Rep: Reputation: 277Reputation: 277Reputation: 277
Quote:
Originally Posted by Andeez.91 View Post
ls /etc | grep conf | grep -V "\." | sort > ~/conf
Hi and welcome to LQ,

Code:
COMMAND2 | COMMAND2
Yes, the output of command1 is being used as input to command2, e.g.
Code:
history | grep ls
is looking for the pattern "ls" in the output of the history command.

Code:
COMMAND > FILE
Yes, this is IO-redirection. The output of command is written to a file instead of being sent to stdout (basically your screen/terminal).

For the argument to grep and how it works, or for how the sort command works, check out the man pages:
Code:
man grep
man sort
Since your thread title says "learning ...", I think you should read a bit more. This type of command is quite straightforward.

Check out:
Introduction to Linux - A hands on guide (and some Bash scripting guides as well) at
http://www.tldp.org/guides.html
and other stuff at http://www.tldp.org/

Last edited by aragorn2101; 09-05-2017 at 04:25 AM.
 
1 members found this post helpful.
Old 09-05-2017, 04:26 AM   #5
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,852

Rep: Reputation: 337Reputation: 337Reputation: 337Reputation: 337
Learn the basics, you will be a master.

Check out this link: https://www.guru99.com/linux-pipe-grep.html

Keyword: grep and pipe tutorial

Good luck!
 
1 members found this post helpful.
Old 09-05-2017, 04:39 AM   #6
GazL
LQ Veteran
 
Registered: May 2008
Posts: 5,927

Rep: Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904Reputation: 3904
Quote:
Originally Posted by Andeez.91 View Post
Hello! Can someone help me with an explanation of this command?

ls /etc | grep conf | grep -V "\." | sort > ~/conf

I hope you can explain each section and what it all means and what this is supposed to do... the only things i think i understand is that it is a pipe.. and its supposed to redirect to the conf file?

thank you so much for your help!
Yes, it's broken and likely doesn't do what its author intended. If you're looking to learn from example, I'd look elsewhere.
 
1 members found this post helpful.
Old 09-05-2017, 09:01 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Summer Midwest USA, Central Illinois, Winter Central Florida
Distribution: SlackwareŽ
Posts: 13,673
Blog Entries: 37

Rep: Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862Reputation: 2862
Member response

Hi,

Welcome to LQ!

Quote:
Originally Posted by Andeez.91 View Post
Hello! Can someone help me with an explanation of this command?

ls /etc | grep conf | grep -V "\." | sort > ~/conf

I hope you can explain each section and what it all means and what this is supposed to do... the only things i think i understand is that it is a pipe.. and its supposed to redirect to the conf file?

thank you so much for your help!
If you really wish to learn UNIX and command line work then I suggest that you can read & learn from the following;
Quote:
Just a few links to aid you to gaining some understanding;
Quote:
"Knowledge is of two kinds. We Know a subject ourselves, or we know where we can find information upon it."- Samuel Johnson
Hope this helps.
Have fun & enjoy!
 
1 members found this post helpful.
Old 09-05-2017, 11:58 PM   #8
Andeez.91
LQ Newbie
 
Registered: Sep 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you so much everyone! I am literally just starting to learn but am in an advanced course and all of the tools and explanations given have really helped me. thanks again!
 
Old 09-06-2017, 02:58 PM   #9
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,843

Rep: Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371Reputation: 3371
Kind of a complex command for a newbie.

You will have to learn your shell's rules to start. A command in one shell may change in a different. I assume you have some version of bash.

Off hand it looks like

list etc
pipe output to
the command grep conf
Pipe that output to.... You get the idea now hopefully.

https://www.cyberciti.biz/faq/howto-...in-linux-unix/
 
Old 09-11-2017, 08:44 PM   #10
Andeez.91
LQ Newbie
 
Registered: Sep 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
learning the AWK and SED commands currently. Would anyone be able to have a IM chat going with me so i can ask questions in real time? any help is greatly appreciated.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
re-learning unix admin from the ground up rignor LinuxQuestions.org Member Intro 1 03-24-2011 08:59 AM
HP UNIX alternative for learning purpose icehari Other *NIX 10 01-15-2010 11:38 PM
Evolve my idea of learning UNIX on a macbook. Jolle Linux - Newbie 1 09-19-2006 09:50 AM
Learning Delphi to port software to Unix/POSIX aldimeneira Programming 1 02-13-2006 11:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration