Questions tagged [ls]

The ls command lists the contents of a directory.

Filter by
Sorted by
Tagged with
1 vote
2 answers
38 views

how to prevent ls to recursively list files in a subdir

I have, e.g., in the directory /etc/ files without extension and with extension /etc/profile /etc/profile.1 /etc/profile.2 and there is a directory given by the system containig some files: /etc/...
4 votes
3 answers
640 views

ls command line-wrap prevention

I'm looking for an answer to this question that doesn't involve the less command: Is there a way to run the ls command in terminal, and prevent line wrapping for long filenames? For example, upon ...
  • 41
0 votes
2 answers
88 views

How to get only file names from an ls -la (ll) listing?

I need a long (vertical) list of all file names of all files in a directory. How to get only file names from an ls -la (ll) listing? Only the names, not: drwxr-xr-x 9 USER GROUP 4096 Jul 20 10:30 ...
2 votes
2 answers
31 views

Exclude "empty" folders from ls output when using --ignore

Suppose I have a folder with lots of subfolders and they are only supposed to contain archived files and I want to check that there are no other file types. I can use the command ls -l -R /backup --...
  • 123
4 votes
1 answer
72 views

ls command still reads the default configuration even after setting the LS_COLORS

I know there are several related questions asked about this but I could't solve my problem with those. Expected behavior: What I want is to disable all coloring stuff and just make the directories ...
  • 155
1 vote
0 answers
46 views

ls /sys/class/udc > UDC "ls:write error: Device or resource busy"

ls /sys/class/udc > UDC "ls:write error: Device or resource busy" Trying to use my device as an OTG client, but I can't write to the UDC file. lsof returns nothing. Any suggestions ...
  • 111
0 votes
1 answer
35 views

Is there a way to add a "description" field / meta-data that could viewed in ls output (or an alternative to ls)?

I have been using unix systems the majority of my life. I often find myself teaching others about them. I get a lot of questions like "what is the /etc folder for?" from students, and ...
3 votes
2 answers
87 views

file listing: difference between ls and echo *

on a lustre file system with thousands of file in directories, each time I type ls I get a large delay until files are listed. Same happens with other commands that need file listing. But if I type ...
1 vote
1 answer
30 views

How to do pattern matching on `.bashrc` for file extensions

I'm modifying my .bashrc: I want to make it so that .zip,.tar and .tar.gz files (and maybe more later down the road) are shown with a red color. Thing is, I want to match for all those files once. So ...
1 vote
1 answer
59 views

"ls" sees different files in the same folder on the same machine in two different terminals. How is this even possible?

A very strange situation occurred to me just now. I'm managing some stuff on a cloud VM running Ubuntu over SSH in a TMUX session. Right now, I have two panes open, which see different files even ...
  • 231
5 votes
1 answer
565 views

ls: bash: printf: `Y': invalid format character in VS Code, not in Terminal

I upgraded to Linux Mint 21 (based on Ubuntu 22), having number of small issues, one of which is in VS Code, not in Terminal (gnome-terminal), running ls alias: bash: printf: `Y': invalid format ...
0 votes
0 answers
29 views

How to set file permission to 777 using umask [duplicate]

It is true that i may not have understood how umask calculations work. This query is just for a test case (my learning). My intention is that my process should generate a file pdf file1.pdf with full ...
  • 405
1 vote
2 answers
45 views

How to make a for loop to read directory names with spaces in them?

I need to create a script to scan folders in a directory and take the name of each folder, make a .txt file, name it with the name of the folder and put inside that folder. For example: A directory ...
0 votes
1 answer
67 views

for loop parsing of ls and the magic behind *

I know that the following is bad: for i in `ls -1 *.MOV` ;do ... and that the proper syntax is for i in *.MOV ;do ... But what are the mechanics behind it? I mean, what part of *.MOV tells the ...
  • 796
-1 votes
3 answers
109 views

ls: long listing format but ignore files starting with dot

The default behaviour of the ls command is to ignore files starting with dot, but if you use the long listing format with -l they will appear. This is inconvenient and counter intuitive for me, I want ...
  • 194
0 votes
1 answer
41 views

Weird LS output on WSL2

Using ls or exa I get a weird output on windows subsystem for linux : Can someone point out what's wrong? I have no funny aliases here. Just running ls.
  • 459
0 votes
0 answers
11 views

How to interpret the output of "ls -lO" flags on OS X? [duplicate]

This answer says you can list the flags of a file on OS X with ls -lO. However, how to interpret the output? Here is an example: $ ls -ldO Library drwx------@ 72 foo staff - 2304 Feb 2 20:02 ...
  • 101
2 votes
1 answer
156 views

Get specific file for every week using ls command

Could someone help me to get the file for every week using ls command? ls -t {path} | grep -e "-1700" | head -30 | sort -r With this ls command, I got below mentioned output 2022.05.30-1700 ...
5 votes
0 answers
221 views

Ubuntu ls doesn't show all the files, but when I "ls filename", it shows up? [closed]

I am using PHP 7.3 to move some files around, in a larger app. The PHP 7 is running on Ubuntu 20.04.4 in a wsl2 container in Windows 10. On reading through other questions, it seems this is probably ...
  • 51
0 votes
2 answers
107 views

How does ls [[:punct:]]* work?

I am learning bash. Currently, I have a file called _something.txt and when I use: ls [[:punct:]]* I get the following error: ls: invalid option -- 'V' What am I doing wrong?
  • 1
0 votes
6 answers
817 views

How to cut string on last underscore character?

I have list of files like below: [root@ods1 backup]# ls -l total 93892810 -rw-r----- 1 root root 651248 Feb 17 08:34 abc_def_g_17-02-2022.sql -rw------- 1 root root 665248 Mar 23 08:46 bbc_23-03-...
0 votes
1 answer
74 views

how to modify the color of fields of ls -la?

I recently found an example of colored output when using ls: AFAIK that is on MacOS with the BSD implementation of ls. I know how I can change the color of the filenames via LS_COLOR, but I would ...
  • 1,139
0 votes
2 answers
161 views

meaning of file type c in ls -l command [duplicate]

I am wondering what the type c is in the ls command. I was following the symlinks at /dev/stdin and ended up with /dev/pts/0 $ ls -l /dev/pts/0 crw--w---- 1 blue tty 136, 0 Apr 8 21:50 /dev/pts/0 I ...
  • 145
0 votes
0 answers
22 views

Writing filenames into file also saves that filename name into file. How do I get it to stop, reliably? [duplicate]

I'm relatively new to bash. I am learning to work with bash, r, etc., within the realm of bioinformatics. I'm having the following problem. I have a list of files. Let's forget that metadata exists ...
2 votes
2 answers
319 views

Sort files by modification date, then by name

Let us assume a directory that contains pictures from different cameras: DCIM1234.JPG DCIM1235.JPG DCIM1236.JPG DSCN4120.JPG DSCN4121.JPG DSCN4122.JPG DSCN4123.JPG IMG5840.JPG IMG5841.JPG IMG5842....
-1 votes
1 answer
261 views

dircolor doesn't work

I was using bash's autocompletion by pressing TAB key at the end of a pathname. I was also using ls (alias ls='ls --color=auto' in ~/.bashrc). I had trouble recognizing the filenames in the color. (Is ...
  • 92.5k
1 vote
2 answers
611 views

ls -d command only returns `.` eg, and no child directories

I have standard ls installed, I also have lsd installed, which is a nerd-font drop-in replacement for ls. I mention this because the error may have something to do with the alias. For testing right ...
  • 27
1 vote
0 answers
48 views

ls displays no files even though folder contains files

This question is actually derived from a problem I have with a python library which deletes a file tree and then recreates the content, but on attempt of execution of a file inside the directory, the ...
1 vote
1 answer
50 views

Can ls show read-only files in a specific color?

I like using ls --color=auto and I know how to use dircolors to change the colors of ls's output. I want ls to display read-only files in a color different than "normal" files but don't see ...
0 votes
2 answers
89 views

Why I need to `ls -ld` in order to see a hidden directory which `ls -a` is not showing?

I have access to a compute cluster where most of the time I need to run ls -ld /some_dir/my_dir to be able to see and access this directory, otherwise it seems hidden and cannot be seen by ls -a. ...
  • 111
2 votes
1 answer
221 views

What naming convention can I use to ensure that file names sort in a consistent order using ls?

I'm trying to come up with a naming convention for a set of files such that they always sort in a consistent order without requiring any special options, but I'm having a difficult time achieving this....
  • 474
1 vote
2 answers
46 views

ls -v (natural number sorting) command sorts capitalized files/dirs ahead of non-capitalized files/dirs

I'd like to have natural sorting of numbers, but capitalized files/dirs not sorted at the top. Is that possible? Currently ls -lv produces: FOO/ bar/ ZEBRA.x foo.x foo-1.x foo-2.x foo-10.x I messed ...
  • 704
0 votes
1 answer
38 views

Sorting long list of files into multiple sub directories based on name

I have a group of 1000+ files that are labeled using text and date in a folder /home/dir/dir2/oldspot with below format: File taken on 01/07/2020 at 23:08 elevation 5 is aaaaaa-bbbb-cc10dddd-L1-...
0 votes
2 answers
271 views

What does "ls * > file1" do?

What does the following command do in Linux? ls * > file1 Does it simply copy all the file names in the current directory into a new file?
  • 3
0 votes
2 answers
150 views

Sorting list with pipeline and without ls-lS command

The Linux program ‘sort’ can sort a file, or the output from another program. How do I use sort to sort the output of the ls command by 1) file name 2) file size. I know there are options of the ‘ls’ ...
  • 21
1 vote
2 answers
389 views

bash + test if folder is empty but exclude files with a leading dot

We used the following approach in order to verify if a folder is empty: [[ "$(ls -A /var/folder)" ]] && echo "not empty" on /var/folder, we did the following: ls -l /var/...
  • 11.4k
0 votes
0 answers
26 views

Why home directory has only one hard link? [duplicate]

I have 9 directories in my home directory but when I am using ls -la command the total hard links showing is 1 (for the home directory). Although there are total 9 directories inside my home directory ...
  • 121
2 votes
2 answers
257 views

ls finds files in directory with a specific name, but find does not

I'm trying to find all the files that are inside directories whose names start with 80s. ls 80s*/* finds the correct files, but find . -ipath '80s*/*' returns nothing. What is the correct find command ...
3 votes
3 answers
352 views

ls -ls output shows larger number of blocks than the file size

As far as i know the ls command with the "-s" option print the file size in blocks , ls uses the 1024 as block size , but i noticed something weird . For better understanding consider the ...
6 votes
3 answers
591 views

Get a list of files (in the way similar to `ls`) on website/webpage before choosing which to download

Let's say I'm on a webpage on which there are several hyperlinks to pdf documents. I want to download those pdf. Is there a way to get a list of those documents (in the ls way) which then allows to ...
  • 349
0 votes
2 answers
115 views

How to make "ls -1" to print out in quotation marks in combination with xargs?

I do an ls command like this to list multiple directories. Please be aware of the blank space in the folder X y. ls -1d 2021*/"X y"/foobar Output is '20211121-161518-801/X y/foobar' '...
  • 530
0 votes
0 answers
44 views

Compare file attributes between user, group and others

How do i list files in a directory comparing their attributes, if i can not use a regex, e.g. i want to show all files that "user" and "others" have exactly the same rights, or &...
7 votes
1 answer
1k views

Why does this new directory have a link count of 3?

$ sudo su # dd if=/dev/zero of=./myext.img bs=1024 count=100 . . . # modprobe loop # losetup --find --show myext.img /dev/loop0 # mkfs -t myext /dev/loop0 . . . # mkdir mnt # mount /dev/loop0 ./mnt # ...
  • 173
1 vote
2 answers
111 views

How can I sort du results by time *and* restrict to --max-depth=1

I use rsync to back up my files using --link-dest to sync only differences from the last backup folder. Is there anyway I can see a directory listing ordered by date and restricting it to --max-depth=...
  • 437
1 vote
2 answers
102 views

How to sort by the whitespace character

I have this shell script which lists all the names of subdirectories of the current working directory. Is there any way I can sort the names so that directory with whitespaces in the name comes first ...
  • 11
1 vote
1 answer
173 views

ls and sort by number for human

I create catalogs mkdir site_{1..44}. I want to sort them site_1 site_2 site_3 site_4 ... site_44 I execute the command ls | sort -h and I have site_1 site_10 site_11 site_12 site_13 site_14 site_15 ...
  • 39
0 votes
0 answers
62 views

How to figure out what the first character in the lines of the output of ls -l mean? [duplicate]

crw-r--r-- 1 root root 10, 235 Nov 29 20:11 autofs drwxr-xr-x 2 root root 280 Nov 29 20:11 block crw-rw---- 1 root disk 10, 234 Nov 29 20:11 btrfs-control ...
  • 170
0 votes
1 answer
280 views

No such file or directory Error while using find or ls -al in unix directory

I am trying to find reason behind this happening and also a solution . When I try to run below command on Unix directory which has around 16 files and also one of the application process which keeps ...
  • 15
1 vote
2 answers
821 views

Using ls on many files results in error "bash: Argument list too long" [duplicate]

I am trying to populate a txt with all the names of .fits files from a folder with this command: ls *.fits > output_all.txt The number of .fits files in the folder is >330k and I get the error ...
  • 149
1 vote
1 answer
86 views

Why does `grep` seem to give slightly different results with a plain `ls` command? [duplicate]

I have a directory with some files - mkdir _tmpmm touch a1 b2 c3 d4 ls # a1 b2 c3 d4 When I grep for a on the output of ls, I see only the file a1 - although the ls output is showing 4 files on ...
  • 113

1
2 3 4 5
26