Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Possibly a silly question.....

  • 06-06-2008 11:23am
    #1
    Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭


    Is there a way to say "all files in the current directory, including hidden files, except . and .."?

    When I want to specify that, I usually use backticks like this: `ls -A` (e.g. cp `ls -A` <destination>) but it just seems clunky (edit: and also fails miserably when there are spaces). I feel like there's a better way to do it that I'm missing out on.

    edit: It's possible to do it with a for loop also to overcome the spaces issue. I just feel like that's clunky too.


Comments

  • Registered Users, Registered Users 2 Posts: 1,606 ✭✭✭djmarkus


    find . -maxdepth 1


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    That's slightly worse than ls -A in that it includes "."

    You could use: find . -maxdepth 1 | grep -v -e "\.$"

    but that just gives the same as ls -A (effectively) and doesn't overcome the spaces issue.


  • Registered Users, Registered Users 2 Posts: 811 ✭✭✭Rambo


    Khannie wrote: »
    Is there a way to say "all files in the current directory, including hidden files, except . and .."?

    When I want to specify that, I usually use backticks like this: `ls -A` (e.g. cp `ls -A` <destination>) but it just seems clunky (edit: and also fails miserably when there are spaces). I feel like there's a better way to do it that I'm missing out on.

    edit: It's possible to do it with a for loop also to overcome the spaces issue. I just feel like that's clunky too.

    English please
    try dir command


  • Registered Users, Registered Users 2 Posts: 1,606 ✭✭✭djmarkus


    find . -mindepth 1 -maxdepth 1 -exec mv '{}' '{}'.bak \;


    is that kind of what your trying to do? this appends ".bak" to all the files in the current directory and doesnt include .





    Rambo: what are you talking about? we're not using DOS here.


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    Rambo wrote: »
    English please
    try dir command
    lol i know i add nothing to the post, but that has to be the funniest thing i read all day.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,534 ✭✭✭FruitLover


    rambo wrote: »
    english Please
    Try Dir Command

    Potm


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    fruitlover wrote: »
    potm

    ROFL. :D







    a


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    djmarkus wrote: »
    find . -mindepth 1 -maxdepth 1 -exec mv '{}' '{}'.bak \;


    is that kind of what your trying to do? this appends ".bak" to all the files in the current directory and doesnt include .

    That's possibly it alright. I'd just substitute the .bak bit for a destination directory. It's just a long oul' command for something that I feel (only in my gut) should be relatively trivial.


  • Registered Users, Registered Users 2 Posts: 811 ✭✭✭Rambo


    djmarkus wrote: »

    Rambo: what are you talking about? we're not using DOS here.

    I could not understand is first post because it should have said

    Is there a way to save "all files in the current directory, including hidden files, except . and .."?

    I thought is wanted some from directory listing without .. which the dir command does under linux

    when I save files I use the tar command of the directory
    example
    at root /: tar -cf home/myfolder myhome.tar

    very fast and quick


  • Registered Users, Registered Users 2 Posts: 2,534 ✭✭✭FruitLover


    Rambo wrote: »
    I thought is wanted some from directory listing without .. which the dir command does under linux

    And also precisely what 'ls-A' does, as the OP has already discovered, c.f. first post.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Rambo wrote: »
    I could not understand is first post because it should have said

    In fairness....it should have said exactly what it said. :) I'm interested in finding an alternate way of specifying everything in the current directory except "." and ".." because I absolutely shafted myself one day by doing:

    chown -R <user>:<group> .* *

    and this included "." and ".." but it's come up again recently when I wanted to copy the contents of the directory including hidden files (and files with spaces) and couldn't think of a straightforward way to do it so I figured I was missing out on something.


  • Closed Accounts Posts: 7,563 ✭✭✭leeroybrown


    Check if ls on the machine you're using accepts the -Q (quoted output) option. If it does that will get you around the whitespace issue:
    ls -AQ
    

    Piping it through xargs to do the work would also be a good idea:
    ls -AQ | xargs chown -Rh user:group
    

    Finally, note that I've passed a -h to chown. Otherwise the chown will follow symlinks and leave them owned by the old user:group.


  • Registered Users, Registered Users 2 Posts: 1,606 ✭✭✭djmarkus


    This is really a round about way when you can use find -exec.

    find . -mindepth 1 -maxdepth 1 -exec chown -Rh dmarkey:users '{}' \;


  • Closed Accounts Posts: 7,563 ✭✭✭leeroybrown


    djmarkus wrote: »
    This is really a round about way when you can use find -exec.
    Despite my above suggestion for Khannie I agree. I always use find for this kind of stuff as it guarantees that there won't be any filename issues that cause something unpredictable and it tends to be efficient. Nothing beats find when you're dealing with 1TB+ and 1m+ files.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Thanks lads.


Advertisement