Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ls]

The ls command lists the contents of a directory.

0
votes
1answer
24 views

Why does ls --ignore=file not work with a *?

I noticed that if I am in a directory with a file named file and I run ls --ignore=file * or ls --ignore=file file It still outputs the file. Why is this? Shouldnt it ignore the file with that ...
0
votes
3answers
31 views

Print multiple filenames to specific lines in txt file

I am trying to print a list of filenames to a text file, with the requirement of printing certain filenames on the same line. For example, I have 4 files. Paleo_R1.fastq Paleo_R2.fastq Vegan_R1.fastq ...
2
votes
0answers
34 views

include special characters when sorting files

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

Infinite loop when attempting to list files

There is a particular directory that I am working with that has about 50,000 files in it. When I try to list the contents using ls -f -1 is generates a list that repeats forever. Here are a couple of ...
0
votes
1answer
26 views

ls reports nonexistent files first, ignoring the specified order

$ ls -lU a.txt test.sh badtest ls: cannot access 'badtest': No such file or directory -rw-r--r-- 1 gqqnbig gqqnbig 11 Apr 15 17:17 a.txt -rw-r--r-- 1 gqqnbig gqqnbig 11 Apr 16 17:22 test.sh Although ...
5
votes
3answers
513 views

How to display lines in a file like ls displays files in a directory? [duplicate]

I have a long file with short lines (one word) f that I would like to inspect. It would fit on the screen if it wasn't for the newlines. If the data was already arranged in columns I could just do ...
2
votes
1answer
34 views

Grouping directories in `zsh`

Using zsh both of these command produce the same result: ls (dir1|dir2)/dir3/*.txt ls {dir1,dir2}/dir3/*.txt Using bash only the following works: ls {dir1,dir2}/dir3/*.txt So, if I want to list ...
0
votes
1answer
33 views

List all extension-only files and folders [duplicate]

I'd like to list all files and folders that only have an extension, like .bashrc, .cache/, and so forth. This seems like it should be straightforward. When I try ls .*, I don't get the expected result:...
-2
votes
1answer
22 views

Move files from one directory to another. But, rename files before the move if the destination directory already contains file of same name? [closed]

I need to move all the text files from /abc/d1 to /abc/d2, but files need to be renamed if /abc/d2 has files with the same name already. cd /abc/d1 mv *txt /abc/d2
1
vote
0answers
70 views

ls command is too slow for some directories

When I run ls command for some directories, it may take about 1.5 seconds to complete even if directory has just a few files, but for most of directories it's very fast. It seems that it's slow for ...
2
votes
1answer
35 views

How to use character classes

In one of my systems, when I run ls [:lower:]*, it will list all files that start with a lowercase letter. In another one, it will give an error: ls: cannot access [:lower:]*: No such file or ...
1
vote
1answer
65 views

“bash: /usr/bin/ls: Permission denied” Arch linux

Today I discovered that the command ls to list files, only returns the error: bash: /usr/bin/ls: Permission denied This happens for every directory I try and also when running the command as root. ...
27
votes
1answer
3k views

Why would /etc/passwd be used every time someone executes `ls -l` command?

Read from APUE, just feel curious: The password file is used every time a user logs in to a UNIX system and every time someone executes an ls -l command.
0
votes
1answer
42 views

How do I list (ls) the content of a folder/directory recursively but to a depth of only one folder/directory?

How do I list (ls) the content of a folder/directory recursively but to a depth of only one folder/directory? I have the following folder structure: folderA: folderB1: folderC1: fileD1: ...
1
vote
0answers
48 views

Sort directories before files and underscore first with ls

When using 'ls' i want to sort directories first and then all files AND sort directories/files with underscore first. Here is an example: _folder2 folder2 _file2 file I can sort directories first ...
1
vote
2answers
59 views

ls won't display Cyrillic characters properly

I've got a problem with Cyrillic alphabet. My terminal will display Cyrillic normally as well most of my programs the only exception I've found so far is ls. Instead of normal Cyrillic it displays ????...
-3
votes
1answer
70 views

List files not owned by root at the / directory

The actual homework question is List all files/directories NOT owned by root and not created in July. I can't find a way to use ls and grep to output a file ~/NotOwnedByRoot.txt find / \!...
1
vote
1answer
67 views

How can I know the type of each element in the output of ls -l?

I was checking what exactly each field is in the output of ls -l. The example in this post solves my question. But again I'm wondering what type of each field is. The strings are obvious. But how ...
2
votes
1answer
48 views

map ls -a to ls -A

I have tried to made an alias ls -a = ls -A, ending up with: bash: alias: `ls -a': invalid alias name I want ls -a without . and ... How can I get that?
0
votes
2answers
64 views

What means ls -d? [duplicate]

When I use the -d, I only have the . that is displayed on the standard output. However, I also have other files in the current directory.
2
votes
1answer
59 views

Reverse the order of file matching as arguments

I have a program that reads files in a certain order. For this example, they all have the same extension, txt {program_name} {input 1...} {output} I happen to name the output file name "a.txt" so it ...
0
votes
3answers
75 views

What is this that “ls /d*” returns?

I am running Ubuntu Bionic and exploring Bash Refs. This is an amusing but enigmatic output from ls. Is this the file description of the shell? The command ls /d* outputs autofs disk ...
2
votes
1answer
68 views

What does a plus (+) after the file permission bits mean? [duplicate]

I ran ls and found a directory that has the + bit set: $ ls -ld /var/log/journal drwxr-sr-x+ 3 root systemd-journal 4096 Oct 1 01:23 /var/log/journal I understand drwxr-sr-x, but what is +? What is ...
1
vote
1answer
68 views

How to use the ls command to show all files except those ending in a specific string

I have a directory with files of all kinds and I wanted to use the ls command to list all of them, except those with a name that ends in .config, but I do not get how to do it.
0
votes
1answer
39 views

Why is my files “last modified” timestamp only showing the year with the 'ls' command? [duplicate]

I'm building a java service that modifies the "Last Modified" field of some of the files it works with. The service keeps copies of files in a folder, it periodically checks a database for changes, ...
0
votes
1answer
37 views

ls don't display correct color with bold in xterm [closed]

I use xmonad with xterm, seeing picture below. It displays color in xterm but ls cannot display correct color with bold font. What is showing now: My Xresources is a copy of solarized/xresources. ...
28
votes
2answers
2k views

Inconsistent color output from `ls` command

I teach an Intro to UNIX/Linux course at a local college and one of my students asked the following question: Why are some of the files in my directory colored white and others are gray? Are the ...
0
votes
2answers
59 views

Trying to do a Proof of Concept of poisoning 'ls' binary to hide files and folders

I am currently trying to modify 'ls.c' source file in order to hide files and folders containing the word hidden. After doing some research, I've found that this could be possible by adding this code ...
1
vote
1answer
91 views

Bash tab completion colors differ from ls colors

I have LS_COLORS and LSCOLORS both defined, but for some reason, I'm being shown different colors when I use ls versus when I tab complete in bash. I'm on MacOS. I have these lines in my .bashrc ...
1
vote
0answers
55 views

How to make ls work as if it was outputting to terminal?

Colors can be adjusted with --color=always, but how to make it display the columns with default settings, nicely fitted to terminal window size?
1
vote
1answer
76 views

How to display ls --color=auto in prompt same as outside of it

When I put $(ls --color=auto) at the beginning of my PS1 it displays all in white and every filename in newlines. But when I call ls --color=auto, it displays in colors and separated by double spaces. ...
10
votes
2answers
535 views

How to keep colored output using sed

I'm using the sed command and I want to keep colored output from the previous command. The output of ls is colored, but the output of sed is not. I'm using OSX. ls -la | sed -En '/Desktop/q;p'
6
votes
4answers
896 views

How to find only directories without subdirectories? [duplicate]

Is there a way in linux to look through a directory tree for only those directories that are the ends of branches (I will call them leaves here), i.e., dircetories with no subdirectories in them? I ...
0
votes
0answers
54 views

ls hangs after the machine hosting the source folder is paused

I have two instances of RHEL 7 Linux, machine 1 and machine 2. Machine 2 has a folder that is mounted to a remote folder from machine 1. It is done with command: mount -t cifs -o user=aaa,pass=...
2
votes
4answers
71 views

Listing files recursively, grouping by user and summing its size

I need to verify the size occupied by each user on my Linux server (all files recursively inside my data folder). With the code below I can get all of my files and their users, but I don't know how ...
0
votes
2answers
41 views

Omit one column in ls -hal

How do I omit the group column in the output of ls -hal? I was using ls -hal|cut -f4 --complement -d ' ' and it works find most of the time, but if I run it in / I get scrambled output: drwxr-xr-x ...
6
votes
0answers
80 views

What would cause glob to list results twice? [closed]

System: Raspbian 8 on a Raspberry Pi 3 An errant space in a sudo command caused a bunch of system directories (/bin, /etc, /usr, etc.) to be moved into a subdirectory. I was able to fix it by putting ...
2
votes
1answer
68 views

How to write a file list with foreign names to a csv file in the terminal?

I have some files with names in foreign languages in my terminal folder. On the terminal when I do 'ls' i see the list on the right in the picture below. When I do ls -t | tail -n +2, I see the real ...
2
votes
2answers
656 views

Is there a way to get ls to listen for changes and update output similar to tail -f?

I have a process that creates many files in a known directory, and the only way to tell how far along it is is to type ls manually. Is there a way to make the output of ls update automatically as new ...
0
votes
2answers
98 views

A specific directory is completely invisible to “ls” and “ls -la”, but I can “cd” into it

This started happening out of the blue. Originally, I was able to "ls" my "Storage" folder and all 3 subdirectories were listed accordingly. ('Beta Profiles' 'OS Backups' 'Software') Starting ...
1
vote
1answer
30 views

Listing content from two directories with wildcard

I have a task to list all files from /bin and /usr/bin that contain an e that is neither at the beginning nor at the end. The wildcard is [!e]*e*[!e] and works. (Tested commands cd /bin & ls -l [!...
0
votes
1answer
60 views

command sort -h does not return a reasonable result [duplicate]

I tried to sort files using sort -h algorithms@algorithms:~$ ls -lh /boot | sort -h drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub -rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic ...
1
vote
3answers
413 views

Match file names with prefix, few digits and a suffix regex

How do I match file names abc_NNN.xyz? here is the directory content [root@ tmp]# ls -ltr total 0 -rw-r--r--. 1 root root 0 Jan 3 00:42 abc_123.xyz -rw-r--r--. 1 root root 0 Jan 3 00:42 abc_234.xyz ...
0
votes
0answers
45 views

Trouble getting to Desktop directory, with Bash on Microsoft's Windows (WSL)

I'm using the Bash terminal for Windows and currently this is what I get when I type ls -a <username@userPC>:/$ ls -a . bin data home lib64 mnt root srv usr .. boot dev init lost+found opt run ...
0
votes
1answer
149 views

Identify the file type if ls -l shows ? (question mark)

I am getting question marks and not able to identify the type of file displayed using ls -l. File types are always displayed as ???. Can you suggest a solution here?
0
votes
2answers
46 views

Move the oldest files into a directory, source directory has more than 10,000 files constantly incoming

I am working on a command to move the x number of oldest files(FIFO) into a directory, is it better idea to pipe the "find" result into "ls" or just use the "ls" .. please suggest. ls -ltr `/bin/...
1
vote
2answers
207 views

ls -I myExecutable is listing the rest of the dir files instead of showing info about the file

Working on Raspian, after compiling using make, I do a ls -I myFile in order to see the permissions of the file and if it is marked as executable as it should and instead of getting something like ...
0
votes
5answers
73 views

List files in ascending order and greater than a given value

I have some log files which has a standard prefix. dev-app.0001 dev-app.0002 dev-app.0003 dev-app.0004 dev-app.0005 dev-app.0006 dev-app.0007 dev-app.0008 I have a metadata file which has when this ...
6
votes
2answers
118 views

Why does GNU Core Utilities stat (including du and ls) report the following sizes (ext4 in GNU/Linux)?

If I have the following contents in a directory: empty_dir: Empty directory. empty_file: Empty file. one_char: File consisting of one character. several_blocks: File consisting of several blocks (but ...
0
votes
2answers
263 views

case insensitive, list files in directory, ending in .jpg [duplicate]

I'm trying to write an alias to list all the files in a directory ending in JP(E)G in its various forms. The ones I'm looking for it to recognise are .jpg .JPG .jpeg and .JPEG. Is there a form of ls (...