Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command to list all files except . (dot) and .. (dot dot)

Tags:

linux

shell

ls

I'm trying to find a command that would list all files (including hidden files), but must exclude the current directory and parent directory. Please help.

$ ls -a \.\..
like image 344
nondoo Avatar asked Mar 14 '14 14:03

nondoo


People also ask

What is the command to list all the files?

Use the ls command to display the contents of a directory. The ls command writes to standard output the contents of each specified Directory or the name of each specified File, along with any other information you ask for with the flags.

How do I list only files in terminal?

Open the command-line shell and write the 'ls” command to list only directories. The output will show only the directories but not the files. To show the list of all files and folders in a Linux system, try the “ls” command along with the flag '-a” as shown below.

How do I get a list of files in a folder by size?

To list all files and sort them by size, use the -S option. By default, it displays output in descending order (biggest to smallest in size). You can output the file sizes in human-readable format by adding the -h option as shown. And to sort in reverse order, add the -r flag as follows.

Which command is used to list hidden files?

The "ls" command has many options that, when passed, affect the output. For example, the "-a" option will show all files and folders, including hidden ones.


2 Answers

Regarding the ls(1) documentation (man ls):

-A, --almost-all do not list implied . and ..

you need (without any additional argument such as .*):

ls -A 

or better yet:

/bin/ls -A 
like image 102
Basile Starynkevitch Avatar answered Sep 30 '22 20:09

Basile Starynkevitch


$ ls -lA

works best for my needs.

For convenience I recommend to define an alias within .bashrc-file as follows:

alias ll='ls -lA'
like image 35
Alan Avatar answered Sep 30 '22 21:09

Alan