The ls command lists the contents of a directory.

learn more… | top users | synonyms

1
vote
1answer
18 views

Find capacity details and oldest file in Busybox format

I am using Mobax and it has Busybox installed in it. I can successfully get the capacity, available, used and used percentage of the directory and its sub-directories in Linux by typing: clear &&...
2
votes
3answers
35 views

How to get last folder (sorted alphabetically in descending order and matching a pattern) using ls/find/etc?

So I have these filesystem structure /my.parent -> my.folder1 -> my-file1.txt -> my.folder2 -> my-file2.txt -> another-folder-here -> another-file.txt Using ...
1
vote
1answer
51 views

Edited sudoers, but `sudo ls` fails

A user has been added with root access in the /etc/sudoers but, it seems that it can not run sudo commands. [root@compute-0-0 ~]# cat /etc/sudoers root ALL=(ALL) ALL hduser ALL=(ALL) ...
0
votes
0answers
21 views

Is there a way to “flag” some directories so that that get a given color when I do ls [duplicate]

My use case is that a few directories on my system are dist'ed on github. Typically the dotfiles directory, some packages I am writing etc... Because their number grows I'd like to flag them when I ...
56
votes
10answers
134k views

How to list all files ordered by size

I would like to list all files in the order of big to small in size and the files could be present anywhere in a certain folder.
1
vote
1answer
1k views

List files from time X to time Y

How to list out all files created between from 'x' to 'y' time? I want to list out files created between "29-dec-2014 18:00" to "30-dec-2014 18:00". Using ls or stat?
50
votes
3answers
47k 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 ...
24
votes
6answers
28k views

How to turn off color with `ls`?

It is normally nice to have color output from ls, grep, etc. But when you don't want it (such as in a script where you're piping the results to another command) is there a switch that can turn it off?...
15
votes
6answers
48k 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 ...
3
votes
5answers
363 views

When I redirect the output of ls to a file, the filename is included in that file. How can I avoid this?

Observe: $ ls $ ls > list $ cat list list This appears to indicate that when ls is executed that the redirection into file list has already begun and the list file is already created. A fine ...
5
votes
2answers
911 views

“ls $PWD” and “ls .” get different files, strange caching perhaps?

I have a strange problem on my Linux Mint machine (with solid-state drive if that matters). Somehow the machine (on multiple occasions) gets different files, and different content for the same file, ...
2
votes
2answers
55 views

shopt -s extglob not working as expected

I am trying to recursively change file permissions in a wordpress installation affecting everything below the public_html document root folder, excluding certain folders. I have set extglob on with ...
0
votes
1answer
58 views

permission denied, cannot list files within a folder

I have a folder like: drwx--xrwx 9 user group 4096 May 1 11:17 160429_ST-E00110_0195_AHMFVNCCXX However my user other can't do ls: -bash-4.1$ ls 160429_ST-E00110_0195_AHMFVNCCXX ls: cannot open ...
0
votes
1answer
27 views

Move files only if filename based regex does not match file in target dir

Best explained by an example: Source dir: file-a-1.txt file-b-1.txt Target dir: file-a-2.txt Expected result: file-a-2.txt file-b-1.txt Move all files from src dir to target dir only if ...
4
votes
1answer
423 views

How to understand the security context in “ls -Z”?

After referring "man ls", it shows "ls -Z" can display the security context: -Z, --context Display security context so it fits on most displays. Displays only mode, user, group, security ...
1
vote
2answers
45 views

pipe ls to grep (lines vs. “items”)

Consider the following command: ls dir1 dir2 file1 x1 x2 y2 when this output is piped into e.g. grep each file/directory is processed as an 'item'. ls | grep f file1 So obviously there is a ...
1
vote
1answer
36 views

Colour-coordinate symlinks/softlinks based on where they refer to

Is there any way to colour coordinate symlinks/softlinks based on where they're linked, or maybe by who they 'belong' to (similarly to colouring the output of ls for example)? To give you an example ...
1
vote
1answer
38 views

What does '-t' do in mv command? Example below

ls -lrt |grep 'Jun 30th' | awk '{print $9}' | xargs mv -t /destinationFolder I'm trying to move files from certain date or pattern or createuser. It doesn't work properly without the -t option. ...
59
votes
4answers
4k 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 ...
1
vote
1answer
35 views

LS_COLORS mixing matching criteria, e.g. file extension and hardlink

I'm wondering if there is a way to keep the characteristic color of the extension type in ls --color=auto as well as underlining the file if it is a hard link. For instance, if I do LS_COLORS="*....
13
votes
7answers
20k views

How to report number of files in all subdirectories?

I need to inspect all sub-directories and report how many files (without further recursion) they contain: directoryName1 numberOfFiles directoryName2 numberOfFiles
4
votes
1answer
55 views

What's the meaning of a '#' character before owner?

What does the # character preceding the owner name mean? For example: me@server /dir/sub/sub-sub $ ll v* x* -rwxrwxr-x 1 #owner group 1176 Jun 25 2009 vfc.sh -rw-r----- 1 #owner ...
-7
votes
1answer
41 views

meaning of -h in ls command

[root@pdbosl02 daily]# ls -lrth total 12G -rw-r----- 1 oracle dba 3.8G Dec 7 20:43 BKPOSLPRD_jcns9p1f.F_bkp -rw-r----- 1 oracle dba 4.2G Dec 7 20:46 BKPOSLPRD_jdns9p1f.F_bkp -rw-r----- 1 oracle dba ...
4
votes
5answers
1k views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
0
votes
2answers
23 views

Changing the color of only one directory in ls

Is there a way to change the color of only one of the listed directories in the ls command? I have researched the LS_COLORS variable, but this doesn't solve the issue because you cannot list specific ...
18
votes
2answers
7k views

What is the number between file permission and owner in ls -l command output?

The output of ls -l command yields the following result: What is the number field between file permission and owner? i.e. what are those 1, 1, 1, and 2? I checked the --help but that doesn't ...
1
vote
3answers
2k views

Ls with spaces + variables

I want to do something like this, but it doesn't save the variable after the piping ends: fs=( ) echo ${fs[@]} ls -A1 | while read f do echo ${fs[@]} fs+=( "$f" ) echo ${fs[@]} done echo "...
8
votes
1answer
20k views

(Why) is it bad to use ls -A to list hidden files?

I want to list every file, including hidden files, in the current directory. I don't want to include the parent (..) and current (.) directory. I found this: how to glob every hidden file except ...
39
votes
13answers
19k 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 ...
1
vote
1answer
58 views

Make an IF condition out of result we get from remote server

I need to check for files availability in remote server, and based on the files availability i need to make an if condition. I have tried the below commands in a shell script to list the files in the ...
0
votes
4answers
101 views

Is there a “ls” replacement that can handle wildcards?

I just learned that ls cannot handle wildcards (ls '*' does not work) and therefore the shell does it before ls is invoked. So the behaviour of ls may be considered as logically for people working 20 ...
5
votes
0answers
114 views

Is it possible to make ls ignore Windows hidden files?

I'm using the GnuWin32 libraries on a Windows 7 machine. I do not like that the ls command shows NTFS hidden files. I've found two methods to hide these files. One solution is to mount the partition ...
1
vote
2answers
89 views

Copy files that are created today without FIND command and SFTP to another server

I have a directory with 'n' number of files in it. I am trying to write a shell script which will list only the files created on the particular day the script is running, and will use sftp to move the ...
11
votes
15answers
3k views

'ls -1' : how to list filenames without extension

ls -1 lists my elements like so: foo.png bar.png foobar.png ... I want it listed without the .png like so: foo bar foobar ... (the dir only contains .png files) Can somebody tell me how to use ...
8
votes
8answers
12k views

What's the best way to count the number of files in a directory?

If parsing the output of ls is dangerous because it can break on some funky characters (spaces, \n, ... ), what's the best way to know the number of files in a directory? I usualy rely on find to ...
12
votes
3answers
656 views

How can I make “ls” show dotfiles first while staying case-insensitive?

Create the following files in a directory. $ touch .a .b a b A B 你好嗎 My default ls order ignores the presence of leading dots, intermingling them with the other files. $ ls -Al total 0 -rw-r--r-- ...
12
votes
4answers
16k views

What is the Linux equivalent of DOS “dir /s /b filename”?

List all files/dirs in or below the current directory that match 'filename'.
-1
votes
4answers
127 views

What will ls -l | wc -l command display?

Will: ls -l|wc -l Display the number of devices too? (Including files and directories)
2
votes
1answer
52 views

Permission denied when using -exec {} ls with find command

When run following command it gives me permission denied message for all the files. find /data/code/ -name "*.jar" -exec {} ls \; find: `/data/code/project/shared/build/thirdparty/log4j-1.2.8/...
4
votes
3answers
20k views

ls to show only directory/filename and size

First of all, this is not a duplicate of this: Linux ls to show only filename date and size Because I want to print actual directory name additionally. I was always using this command: ls -l | awk '...
2
votes
6answers
9k views

ls command - define number of columns

Is there a way to define the number of columns in ls output? I got this far: ls -C sorts in columns and ls -1 produces one column. --tabsize = option to produce two columns resulted in what looks ...
0
votes
2answers
31 views

Listing numbered files using wildcard sequence with predefined range

I have a folder of numbered data files. I am trying to incrementally extract a predefined range of files. The range of files that I am looking for is predefined in two variables, ns and ne, which ...
207
votes
9answers
386k views

How do I get the size of a directory on the command line?

I tried to obtain the size of a folder (containing folders and sub folders) by using the ls command with option l. It seems to work for files (ls -l file name), but if I try to get the size of a ...
0
votes
3answers
49 views

Seeing mode of file without listing all files

I want to see the mode of file/folder foo, in the form drwxrwxrwx. I would normally do ls -lah | grep foo, but in this case the folder had so many subfolders, that it took a long time for ls to run. ...
2
votes
5answers
263 views

How can I list the names of directories that contain file names matching a regex?

Given a directory X that contains several subdirectories and files, I would like to list the names of the immediate child directories of X that (directly or indirectly) contain file names matching the ...
0
votes
3answers
52 views

Command to print the number of *.pdf files in a chosen directory [duplicate]

I am currently not on a Linux machine. Would the following command produce my wanted result? ls | grep ".pdf" | wc
1
vote
2answers
44 views

Tolerant file system for a failed automount

(I am running openSUSE 13.2) My current setup I have an external backup drive which I mount at boot with the following line in my /etc/fstab: /dev/mapper/cr_backup /backup ext4 comment=...
9
votes
4answers
35k 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 ...
22
votes
8answers
71k views

How to list files without directories, and filter by name (ls options)

I have a directory called uploads. It contains a bunch of files, plus a few subdirectories which in turn contain files. Is there a way I can (in one step) do the following: List ONLY the files in ...
1
vote
1answer
73 views

passing ls variable to grep when doing a file search only works inside directory

I am running a command that I use to find the most recent file in a folder then grep the contents for a matching pattern. Here is the command flow that shows the problem I am having. root@backup /]# ...