Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to delete all files in a current directory starting with a dot?

  1. #1
    Join Date
    Nov 2015
    Beans
    86
    Distro
    Ubuntu 16.04 Xenial Xerus

    How to delete all files in a current directory starting with a dot?

    Hello!

    I use Ubuntu 14.04 and in a terminal I became root with sudo su and I wanted to delete root's trash manually. It deleted everything except for a few files that start with a dot. Like .htaccess etc. So I went to that directory (which is "files") and I ran this command:

    Code:
    rm -rf .*
    It did delete those files, BUT I also got an error message that the system couldn't delete "." and ".." What does it mean? Like if I tried to delete the whole directory tree? Like I said, when I was running that command I was in the lowest directory. This one to be exact: /root/.local/share/Trash/files/
    I shot down my PC and then turned it on. Everything seems to be normal at first glance. So now I want to ask is what went wrong and if what I did could really cause any serious damage to the system in general? In other words, should I be worried now or everything is OK?

  2. #2
    Join Date
    Aug 2014
    Beans
    Hidden!
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to delete all files in a current directory starting with a dot?

    In any directory if you run ...
    Code:
    ls -al
    you will see something like...
    Code:
    glen@Xenial:~$ ls -al
    total 908
    drwxr-xr-x  78 glen glen   4096 Sep 19 11:26 .
    drwxr-xr-x   3 root root   4096 Aug 24 16:32 ..
    For an explanation see HERE

  3. #3
    Join Date
    Oct 2006
    Beans
    58,282

    Re: How to delete all files in a current directory starting with a dot?

    Quote Originally Posted by Grigoriy View Post
    Code:
    rm -rf .*
    Code:
    rm -rf ./.*
    would stop you trying to delete the parent folders.

  4. #4
    Join Date
    Nov 2008
    Location
    Boston MetroWest
    Beans
    16,326

    Re: How to delete all files in a current directory starting with a dot?

    "rm -f *" will not delete dot files. You need to use
    Code:
    rm -f \.?*
    That matches any file that begins with a dot followed by one or more additional characters. The backslash "escapes" the dot and tells the shell to treat it as a regular character and not one having special meaning.

    If you use "rm -rf *" and then "ls -la" you'll see the dot files are still there.
    If you ask for help, do not abandon your request. Please have the courtesy to check for responses and thank the people who helped you.

    Blog · Linode System Administration Guides · Android Apps for Ubuntu Users

  5. #5
    Join Date
    Nov 2015
    Beans
    86
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to delete all files in a current directory starting with a dot?

    Thanks a lot for your replies!

  6. #6
    Join Date
    May 2008
    Location
    SoCal
    Beans
    Hidden!
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: How to delete all files in a current directory starting with a dot?

    Quote Originally Posted by Grigoriy View Post

    ... [I] couldn't delete "." and ".." What does it mean? Like if I tried to delete the whole directory tree? Like I said, when I was running that command I was in the lowest directory. This one to be exact: /root/.local/share/Trash/files/
    The single dot (.) by itself is the current working directory. The double dot (..) is the directory just above the current working directory.

    Try this at your home directory to to see what I mean.
    Code:
    cd ..
    -BAB1

  7. #7
    Join Date
    Aug 2016
    Location
    Wandering
    Beans
    Hidden!
    Distro
    Xubuntu Development Release

    Re: How to delete all files in a current directory starting with a dot?

    Quote Originally Posted by bab1 View Post
    The single dot (.) by itself is the current working directory. The double dot (..) is the directory just above the current working directory.

    Try this at your home directory to to see what I mean.
    Code:
    cd ..
    Thanks... learn something new almost daily
    Code:
    cd ..
    Code:
    ls ..
    bin   dev  home  lib64       mnt  proc  run   srv  tmp  var
    boot  etc  lib   lost+found  opt  root  sbin  sys  usr
    Thanks bab1
    With realization of one's own potential and self-confidence in one's ability, one can build a better world.
    Dalai Lama>>
    Code Tags | System-info | Forum Guide lines | Arch Linux, Debian Unstable, FreeBSD

  8. #8

    Re: How to delete all files in a current directory starting with a dot?

    Quote Originally Posted by Grigoriy View Post
    root's trash
    ?
    Are you logging in graphically as root?

    Never heard of it.
    Windows assumes the user is an idiot.
    Linux demands proof.

  9. #9
    Join Date
    Feb 2015
    Beans
    Hidden!
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: How to delete all files in a current directory starting with a dot?

    Quote Originally Posted by Habitual View Post
    ?
    Are you logging in graphically as root?

    Never heard of it.
    Files can end up there ( /root/.local/share/Trash/files/) if the file browser is run as root and files are deleted with the context menu "Move to the rubbish bin" option.

    A full graphical log in is not necessary for that to happen. I used to do the file manager method of managing root files (gksudo nautilus) before I became more comfortable with the terminal and as such found some of my root files ending in that trash location for root.
    Last edited by yetimon_64; September 19th, 2016 at 09:30 PM.

  10. #10
    Join Date
    Nov 2015
    Beans
    86
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to delete all files in a current directory starting with a dot?

    Actually, the main reason why I made that mistake, was that I wasn't aware that "." and ".." are just FILES too!

    It's much more convenient for me to use gksudo nautilus, than a terminal. That's why what I delete ends up in root's trash. And the reason why I need elevated privileges, 'cos I often delete files in /var/www/html and in Truecrypt containers.

Page 1 of 2 12 LastLast

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
  •