Questions tagged [ls]

The ls command lists the contents of a directory.

Filter by
Sorted by
Tagged with
1
vote
2answers
121 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
82 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
155 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 ...
207
votes
3answers
35k 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 ...
86
votes
10answers
97k 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 ...
86
votes
5answers
75k 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 ...
61
votes
9answers
145k 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
32 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
115 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
16k 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 ...
27
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
345 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
54 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 ...
24
votes
5answers
22k 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
46 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
929 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
2answers
41 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/...
82
votes
11answers
248k 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
57 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
216 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 '...
68
votes
6answers
197k views

Difference between ls -l and ll?

I'm relatively new to programming as a whole and some tutorials have been telling me to use ls -l to look at files in a directory and others have been saying ll. I know that ls is a short list, but ...
1
vote
2answers
1k views

Cannot rm file because it doesn't exist? [closed]

I've encountered a really weird problem on a NAS volume I'm accessing on OS X. I have a PNG file that I tried to delete, but something went wrong and it still appears when I run ls or view the ...
1
vote
1answer
84 views

Difference between /$ and ~$

When I log into a server running Ubuntu 18.04.3 (LTS) x64 and run ls nothing shows and there is a ~$ at the end of the command prompt. When I type cd / the prompt changes to /$ and I can see many more ...
2
votes
1answer
74 views

How can I show hidden files with grep and ls? Problem with period ('.') at the beginning of the word

I'm trying to display hidden files in the current directory using grep and ls. The following command works fine: ls -a | egrep '^\.+', but this commands don't work: ls -al | egrep '\<\.+' or ...
1
vote
2answers
105 views

ls: use different color for “user” and “group” columns, when file owned by root

When using ls -lAhF, the 3rd and 4th columns are user and group ownership, ie: drwxrwxrwt 2 root root 60 Nov 15 15:50 .X11-unix/ srwxr-xr-x 1 marti marti 0 Nov 15 15:51 .menu-cached-:0-marti= ...
7
votes
3answers
4k views

ZSH: `ls *(.)` lists regular files only but `ls *(/)` does not list directories only

I'm not sure I am using ZSH's globbing correctly, but I thought ls *(/) would just list the dirctories under pwd, but it doesn't, it recursively lists all files under every directory under pwd (I got ...
2
votes
2answers
115 views

`ls -l ~~` (two tilde)+ tab does not show directories starting with ~~, but users

In the bash shell, why does ls -l ~~ + Tab not show directories starting with ~~, but users? (all users). The ls -l is just an example. If I type ~ + Tab in any directory, I get a list of users.
1
vote
3answers
92 views

For loop to find files of largest size and copy them to another directory

I am trying to create a loop to sort files within each of many directories by size, then copy the largest two to another location, keeping the directory format (below). folder/sample 1 .../...
9
votes
4answers
19k views

Recursively list files with file names, folder names and permission

Is there anyway I can list files by typing a command in the shell which lists all the file names, folder names and their permissions in CentOS?
0
votes
1answer
349 views

How does one have custom LS_COLOR work for ZSH?

I wanted to make custom colors for the ls command with zsh, but I find that all the previous answers to this do not work for me. I tried all these options: Option 1) #LS_COLORS='no=00;37:fi=00:di=...
11
votes
9answers
18k views

display only files starting with . (hidden)

I tried to display only hidden files but don't know how to do it. That is working (but matching also dots in other places) ls -la | grep '\.' Was trying adding ^ but didn't find the solution.
67
votes
4answers
160k views

List subdirectories only n level deep

Festival stores voicepack data in the following example directory structure: /usr/share/festival/voices/<language>/<voicepack name> What is the simplest one-liner (preferably using ls) ...
0
votes
0answers
34 views

How do I change the way lists are presented in the terminal?

I'm new to working with the terminal and recently I have watched a few videos online, and customized it a little bit to suite my workflow (Color Schemes). My issue is that some of the directories I ...
4
votes
5answers
30k views

How to show only hidden directories, and then find hidden files separately

I'm trying to list all the hidden files in a directory, but not other directories, and I am trying to do this using only ls and grep. ls -a | egrep "^\." This is what I have so far, but the problem ...
0
votes
1answer
41 views

Using paths from a function that uses globbing

It is known that parsing the output of ls is generally a bad idea and one solution is to use globbing instead of ls to 'safely' loop through files in a directory. for path in /path/to/search/*; do ...
0
votes
1answer
52 views

`ls -l` doesn't display the human-readable owner and group, how can I check the owner and group of a file?

I want to check the owner and group of a file, but I get: $ ls -hl canal.properties -rw-rw-r-- 1 500 499 514 Nov 4 19:12 canal.properties 500 and 499 are not human-readable, are there any other ...
0
votes
2answers
221 views

entr: recognition of new files recursively

To keep track of newly added files in a directory (and it's subdirs) I want to use entr ls -d /tmp/* | entr -p notify-send "new file added." But when I add new files to /tmp/ or /tmp/foo/ nothing ...
4
votes
2answers
4k views

ls show in megabytes can be set in bash script ?

To check the size in megabytes I have always to do --block-size=Mb. Can I set in bashrc so that when I do ls it should alway publish size in Mb?
0
votes
1answer
742 views

Difference between ls command options:`ls -a` `ls -al` `ls -all`

First look at the output of ls --help command: Several lines ignored in the output -a, --all do not ignore entries starting with . -l use a long listing ...
34
votes
4answers
4k views

Why would the command “ls *” generate an error about invalid options?

There is a thread that talks about ls "*" not showing any files, but I actually wonder why the simple ls * command doesn't output anything in my terminal other than ls: invalid option -- '|' Try '...
5
votes
3answers
28k views

How to list only files in a directory separated by commas

So no directories and no hidden files. Just the files. Listing only files can be done with the line as follows. ls -p | grep -v / Now I want the result of this line to be separated by commas.
0
votes
0answers
24 views

Grub2 shell ls command shows nothing

in the Grub2 shell you have the ls command to show your drives. But, in my case, ls shows nothing, really nothing. lsmod shows a bazillion loaded modules, to be sure, I loaded these again: ls, ...
0
votes
5answers
232 views

How to iterate over files returned by ls

The first and second invocation are for comparison's sake. It's the third I'm trying to get to work. $ ls -a1 *mp3 DaftPunk_VeridisQuo.mp3 French79_AfterParty.mp3 French79_BetweentheButtons.mp3 ...
1
vote
3answers
115 views

Why is my perl regex in my bash script not working? MacOS Terminal

I'm trying to move away from AppleScripts for workflows at my job, and create something simpler that can run in the background instead. For this task, I am given 35-40 files (5 renditions of 7 or 8 ...

1
2
3 4 5
22