Results 1 to 10 of 10

Thread: Learning Commands - Help

  1. #1
    Join Date
    Feb 2013
    Beans
    27

    Learning Commands - Help

    Hi. So I want to lists all files and directories in my home directory and then I Need to display all the files and directories that are in capital letters and if it's a directory it needs to have a "/" at the end of it

    for example
    FILE1
    FILE2
    DIR3/

    I Have this command so far but I'm having trouble with the part where I Have to add the "/" at the end of the directory. Is there a way to do this by a single command or do I have to do something else. I am allowed to make scripts

    ls | more | grep [A-Z]

  2. #2
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Learning Commands - Help

    n/m reread your post and realized I misunderstood what you were asking
    Last edited by steeldriver; February 2nd, 2013 at 08:22 PM.

  3. #3
    Join Date
    Sep 2009
    Location
    United States
    Beans
    40
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Learning Commands - Help

    `More' won't help because its not a stream processor.
    You need to try control statements in bash or awk as you have conditional action.
    Something like following:


    Code:
    [aniket @ aniket-XPS-15z : ~]$ ls -l  | awk '{ if($0 ~ /^d/) print toupper($NF)"/" ;else print toupper($NF)}'
    output:
    Code:
    124
    A.BMP
    ANIKET/
    A.OUT
    DESKTOP/
    DOCUMENTS/
    DOWNLOADS/
    DWHELPER/
    FOO.C
    MUSIC/
    PICTURES/
    PUBLIC/
    SENT
    TEMPLATES/
    TEXPUT.LOG
    ONE/
    VIDEOS/
    [aniket @ aniket-XPS-15z : ~]$

  4. #4
    Join Date
    Sep 2009
    Location
    United States
    Beans
    40
    Distro
    Ubuntu 13.04 Raring Ringtail

    Re: Learning Commands - Help

    Hi,

    I think I misunderstood the question. The reply posted by steeldriver made me realize that. The snippet I posted will just capitalize your current directories.

    You will need something like
    Code:
    [aniket  @ aniket-XPS-15z : ~]$ ls -l  | awk  '{ if($0 ~ /^d/ && $NF ~  /^[A-Z_]+$/) print $NF"/" ;else if ($NF ~ /^[A-Z_]+$/) print $NF}'
    CAPITAL/
    CAPITAL_FILE
    [aniket @ aniket-XPS-15z : ~]$

  5. #5
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Learning Commands - Help

    there's also the -F switch to ls, which appends the trailing / on dirs, so possibly something like this will work?

    Code:
    $ ls
    DIR  DiR  dir  FILE  fIlE  file
    $ ls -F | grep -Ewo '[[:upper:]]*/?'
    DIR/
    FILE

  6. #6
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Learning Commands - Help

    Sounds like a homework question. Is this your homework?

    From the code of conduct that you agreed to when you created your account:

    While we are happy to serve as a resource for hints and for asking questions when you get stuck and need a little help, the Ubuntu Forums is not a homework service. Please do not post your homework assignments expecting someone else to do it for you. Any such threads will be taken offline and warnings or infractions may be issued.

  7. #7
    Join Date
    Feb 2013
    Beans
    27

    Re: Learning Commands - Help

    Thank You! The -F command really works. I used it with the command I had previously. The full command I have is this.

    ls -F | more | grep [A-Z]

  8. #8
    Join Date
    Feb 2013
    Beans
    27

    Re: Learning Commands - Help

    Do you know any good forums people can discuss commands and such?
    Thanks

  9. #9
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Learning Commands - Help

    If you check out the man page of ls you will find out that there is an option which you can use to print a `/' (slash) after each file name which is a directory. Once you are able to print the directory names in the format you want, you can pipe the output of ls to grep in order to list only the all uppercase file names. The pattern you use in grep depends on what do you mean by file names in capital letters...

  10. #10
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Learning Commands - Help

    Quote Originally Posted by toad3000 View Post
    Thank You! The -F command really works.
    -F will also append other indicators (*/=>@|) to the entries. If you scroll down a little bit the man page you will find the option which does exactly what you want.

    Quote Originally Posted by toad3000 View Post
    Do you know any good forums people can discuss commands and such?
    Thanks
    This one. Just don't expect someone else to solve your homework for you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •