The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,275ā€…    Votes:  3ā€…    āœ… Solution
Tags: command-line   ls   hidden-files  
Link: šŸ” See Original Answer on Ask Ubuntu šŸ”—

URL: https://askubuntu.com/q/1244495
Title: How can I exclude . and .. when listing hidden items?
ID: /2020/05/28/How-can-I-exclude-.-and-/How-can-I-exclude-.-and-..-when-listing-hidden-items_
Created: May 28, 2020    Edited:  May 28, 2020
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


From the second answer in:

This works on my machine (Iā€™m not using SSH like the OP though):

ls -d .!(|.)

If there are no hidden files or directories you will get an error message:

$ ls -d .!(|.)
ls: cannot access '.!(|.)': No such file or directory

The error message occurs on directories with no hidden files because . and .. are excluded.

shopt consideration

From comments:

ls -d .[!.]* works without extglob

ā‡§ Make Ubuntu's Night Light look like Manjaro KDE's Night Color Ubuntu 20.04 boot freezes after shutting down the PC, but not after restarting from Windows 10  ā‡©