Questions tagged [ls]

The ls command lists the contents of a directory.

Filter by
Sorted by
Tagged with
152
votes
8answers
188k views

What causes this green background in ls output?

There are two directories shown by 'ls'. Normally directories anywhere are blue on black background. But the first one is blue on green and impossible to read. Why is this? How to make it blue on ...
0
votes
0answers
47 views

ls --help doesn't work in terminal, why? [duplicate]

Whenever I type a command to get information on, for example: ls --help I get an error: "ls: illegal option -- -" "usage: ls [-ABCDEF...]" Can anyone help me on why my --help isn't working?
7
votes
5answers
3k views

Best way to only list files that I own

What would be the best shell command "one liner" that I could use to list all of the files in a directory, only showing those that I own?
118
votes
6answers
179k views

How do I do a ls and then sort the results by date created?

In what order are the dated ordered by? Certainly not alphanumeric order. ls -lt sorts by modification time. But I need creation time.
0
votes
0answers
18 views

How to keep directories sorted by interest or frequency of usage?

Current situation Let's say I have a cloud sync directory $CLOUD_DIR with sub-directories which I want to keep sorted by interest. In order to do that I use lexicographical order and use number to ...
2
votes
1answer
44 views

`ls -d */` is not working on one specific directory

ls -d */ runs fine in all other directories that I tried, but in one specifically, I get this: ls: invalid option -- '/' Try 'ls --help' for more information. I pasted the command in the terminal, ...
0
votes
2answers
35 views

Can i run 'ls' on text file that contain list of files and directories?

I have a text file that contain list of files and directories and i want to filter only the files. I tried this but it didn't worked: cat file.txt | ls -l | grep ^-. This is the file: /etc /etc/...
11
votes
2answers
41k views

-bash: cd: .ssh/: Permission denied

When I type in cd .ssh in terminal, it returns with -bash: cd: .ssh/: Permission denied. Now I cannot add my ssh keys to ssh. When I type ssh-add ~/.ssh/idname it says /Users/Dan/.ssh/idname: ...
2
votes
1answer
101 views

The tilde ~ key combination doesn´t show up in bash

I am using an acer swift one laptop with Windows 10, the keyboard setting is on standard German. I downloaded bash today from git-scm.com/download/win and tried some commands. Starting of with the ...
0
votes
0answers
24 views

File browser and bash ls give different results

Im using a NAS server with AFP service for quite some while. Now I switched finally to debian buster and wanted to use my photomaniging software again. go everything up and running. A week ago I ...
0
votes
0answers
22 views

Why do newer versions of GNU `ls` have different output in command substitution when dealing with newlines? [duplicate]

The folder "/tmp/folder" contains one file, whose filename consists only of a single newline. The output of ls -A /tmp/folder, even inside a non-interactive script, is: ''$'\n' Here are the ...
130
votes
10answers
112k views

List files sorted numerically

I have a bunch of files from log1 to log164. I'm trying to LIST the directory (sorted) in a UNIX terminal but the sort functions are only providing the format like this: home:logs Home$ ls -1 | sort ...
2
votes
2answers
61k views

How do I get a list of all directories and files with absolute paths each line?

Using ls -R /, i get every file and directory listed that exists, but not with the full file path. What do I need to write on the command line in order to get a list in such a format, that every ...
0
votes
2answers
62 views

Sort contents of folder by their git time

I want to sort the files in a folder by the time they were added to git. I looked at git ls-files sort by modification time, but this gives me all the files in git by time. I want only the files/...
2
votes
1answer
39 views

Search directories containing numbers larger than a certain threshold in their name

This is the command that I have and would like to modify with an additional condition: find /home/user/backups/ -mindepth 2 -maxdepth 3 -name "*~EEEE000.tif" -print This is the output of ls /home/...
55
votes
3answers
32k views

List all files with the same inode number?

Lets say, when I do ls -li inside a directory, I get this: 12353538 -rw-r--r-- 6 me me 1650 2013-01-10 16:33 fun.txt As the output shows, the file fun.txt has 6 hard links; and the inode number is ...
0
votes
2answers
38 views

aws ec2 ls command is showing the user@ip:directory/folder on the last line - How can I remove this from my ls output?

When I perform an ls command in my aws ec2 server, I am getting the correct list of files which I need, but for some reason the user@ip:directory/folder is showing on the last line of my results? Is ...
-1
votes
0answers
39 views

Is there a DIR command for raspbian (debian I guess) and where can I get it?

I've come across some posts mentioning that there does exist a DOS-like dir command available for some versions of Linux. Is there one that runs on the RPi-4, and if so where can I download it from? ...
1
vote
2answers
88 views

diffrence between ls -l *.<sometthing> | wc -l and ls -l | grep <something> | wc -l

I have a folder with a huge file list that I want to count. I was doing ls -l *.json | wc -l and it was working fine, till the list apparently gone huge enough that this command didn't work any more. ...
9
votes
4answers
12k views

How to inspect group permissions of a file

I would like to inspect group permissions of a file from a bash script. Specifically, I need to check whether a file has the group writeable bit on. That's it. Simple as that. However: I also need ...
-3
votes
0answers
66 views

What does “.:” mean in the output of “ls”

I often see this path syntax in many place. For example, command output of my command find|xargs ls -1sh gives me: ./defaults: total 8.0K 4.0K defaultAlarmProvider.test.js 4.0K defaultCategories....
56
votes
14answers
41k views

What's the most resource efficient way to count how many files are in a directory?

CentOS 5.9 I came across an issue the other day where a directory had a lot of files. To count it, I ran ls -l /foo/foo2/ | wc -l Turns out that there were over 1 million files in a single ...
2
votes
3answers
1k views

Full file date (without GNU utilities)

I am trying to obtain the full date (created or modified) of a particular file for passing to another program. I have tried variations of options with the ls command but none provide a full date for ...
1
vote
2answers
118 views

Why does ll -d */ result in an additional forward slash?

The command ls -d */ only lists directories as follows Desktop/ Downloads/ Pictures/ snap/ Videos/ Documents/ Music/ Public/ Templates/ The command ll -d */ limits the results to ...
1
vote
0answers
26 views

Oh My Zsh - execute ls after auto cd [duplicate]

Oh My Zsh has this lovely feature where you can just type dir-name instead of cd dir-name to access the directory called dir-name. In my old .bashrc I had a function that overwrites the builtin cd ...
0
votes
1answer
42 views

Set LS_COLORS in Alpine

I am trying to set the directory colors in alpine to be white. I tried to create ~/.profile with LS_COLORS=$LS_COLORS:'di=1;44:' ; export LS_COLORS in it. But it had no effect. I see many examples ...
1
vote
4answers
118 views

Bash - print reversed file list using glob

Is there a way to reverse a file list via glob? So I would get the same result as with: ls -r * I'm using this in a shell-script and shellcheck keeps complaining: ^--------^ SC2045: Iterating ...
203
votes
3answers
34k views

Why is 'ls' suddenly wrapping items with spaces in single quotes?

I just noticed that on one of my machines (running Debian Sid) whenever I type ls any file name with spaces has single quotes surrounding it. I immediately checked my aliases, only to find them ...
82
votes
10answers
90k views

Is there any option with 'ls' command that I see only the directories?

Sometimes, I need to check only the directories not files. Is there any option with the command ls? Or is there any utility for doing that? EDIT: I'm using Mac OS X, and ls -d gives me . even though ...
85
votes
5answers
74k views

The result of ls * , ls ** and ls ***

I know using the command ls will list all the directories. But what does the ls * command do ? I used it and it just lists the directories. Does the star in front of ls mean how deep it will list the ...
59
votes
9answers
140k views

How do I echo just 1 column of output from ls command?

Lets say when I do ls command the output is: file1 file2 file3 file4 Is it possible to display only a certain column of output, in this case file2? I have tried the following with no success: echo ...
0
votes
0answers
31 views

Newline delimited ls command? [duplicate]

I'm currently writing a help system for my window manager and I need to have a list of files that are delimited by newlines. I'd use the ls command but if there's the enough files ls will display ...
0
votes
1answer
86 views

why does the output of `ls` look different when piped through ``tr “\n” “\n”`?

The man page for tr(1) says: tr - translate or delete characters SYNOPSIS tr [OPTION]... SET1 [SET2] DESCRIPTION Translate, squeeze, and/or delete characters from standard ...
10
votes
4answers
15k views

ls colors: why are some of my fonts black and others green in ls output

I uploaded some font files to AWS (running Amazon Linux) and moved them to the /usr/share/fonts directory using a cp command in .ebextensions. When I SSH in from my mac and use ls -a, I see some ...
26
votes
3answers
9k views

Why does ls sorting ignore non-alphanumeric characters?

When sorting file names, ls ignores characters like -,_. I expected it to use those characters in sorting as well. An example: touch a1 a2 a-1 a-2 a_1 a_2 a.1 a.2 a,1 a,2 Now display these files ...
3
votes
0answers
295 views

Include special characters when sorting files

I'm trying to make Linux include special characters when sorting filenames. The sort order I'm trying to achieve is: first all special characters, then numbers, then letters (case insensitive). The ...
0
votes
2answers
45 views

list filenames stored in text file with a certain timestamp

I have stored a couple of file names in a text file by the name new1.txt in my home directory, now i'm using a loop to list all the files in the directory they are present in. I am able to write the ...
23
votes
5answers
21k views

How to list files and directories with directories first

I have two questions. First, which command lists files and directories, but lists directories first? Second question: I want to copy a list of files into a single directory, but make the target ...
10
votes
3answers
6k views

Tell if a folder/file is hidden in Mac OS X

I know you can set or unset the hidden flag of a folder/file by doing chflags hidden foo.txt and chflags nohidden foo.txt. But is there anyway of telling whether the folder/file is currently hidden ...
0
votes
0answers
19 views

How to solve -ksh: /bin/ls: cannot execute [Argument list too long] error? [duplicate]

I wrote a command line expression to generate count of files and directories in source file but I get -ksh: /bin/ls: cannot execute [Argument list too long] How to solve this issue? I used ...
0
votes
0answers
18 views

Why the following redirection doesn’t work? [duplicate]

i typed the following command which cp | ls -l It didn’t work as i expected. I wanted that the output of the which command will be a path name. So the ls command will show the information about the ...
0
votes
1answer
920 views

External Hard Drive Issue on mac

After the cd /Volumes command when I type ls it shows me my hard drive name twice, with different permissions. After that when I try to use mkdir to create a directory in the external hard drive I'm ...
13
votes
4answers
1k views

How to add new line between `ls -l` output

This is standard ls -l output. user@linux:~$ ls -l total 0 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file01 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file02 -rw-rw-r-- 1 user user 0 Nov 1 00:00 file03 ...
1
vote
1answer
1k views

change LS_COLORS behaviour

I am trying to modify LS_COLORS behavior. Presently it (say for sh or py), changes color depending on if it is executable or not, as shown here But, I want all my script, executable or not, have ...
1
vote
2answers
35 views

Find a file and send email

I want to find a file for every 60sec. If the file exists between the time range then an email should trigger. i tried below but not working. Apprecite your help ! THanks Advance #!/bin/sh cd /my/...
79
votes
11answers
242k views

Show sum of file sizes in directory listing

The Windows dir directory listing command has a line at the end showing the total amount of space taken up by the files listed. For example, dir *.exe shows all the .exe files in the current directory,...
1
vote
2answers
55 views

Drop stderr from ls

When I run ls on a filename that doesn't exist the output reports that. I'd like to drop that output but still report when a file is found. Is this stderr that reports the output below? $> ls foo ...
3
votes
1answer
203 views

Why does `ls` add a leading whitespace to its output for certain directories?

If I use the ls command in my home directory each line of output has a leading whitespace: $ ls bin Documents ... It only seems to do this for my home directory. Why does it do this? Note: I ...
10
votes
3answers
2k views

How to colourise hidden files in `ls` file listings?

LS_COLORS environmental variable lets you decide on colours for different file types for GNU coreutil's ls command, such as directories, regular files, links etc. I suppose that dot files are ...
4
votes
2answers
1k views

How to avoid single quotes in file name during python saving file?

If Python saves file on extended 4(Linux) partition that contains unusual symbol(so far uncovered square brackets [] ). It automatically quotes file name. For example: file[].txt will be saved as '...

1 2 3 4 5 22