The ls command lists the contents of a directory.

learn more… | top users | synonyms

1
vote
2answers
265 views

How do get ls to list directories with a trailing forward-slash?

My shell is bash. How can I get the output of ls to show directories with a trailing forward-slash? When I do ls in tcsh it gives the desired output. How can I get this to occur in bash without ...
-1
votes
1answer
50 views

List just the permissions of a file [duplicate]

I want to know how to just check for the permission of a file. I know ls -l yourfile will show you it but I just need the nine permission letters. Thanks
0
votes
0answers
36 views

Sorting results from ls [duplicate]

I was wondering if there was a way to sort through ls results on the command line. Sometimes I use ls to get the exact name of the folder or file I want to use in a command. So it would be nice if ...
2
votes
2answers
86 views

List PDF files with missing metadata

I have had a few tasks where I needed to make reports on file changes on directories from different servers and have managed to make the reports using simple Unix commands. I used: ls -R -lT /...
3
votes
7answers
176 views

Find directories excluding ending bracket ')'

I'm trying to list all video directories (not files) which don't end in a year e.g. (2015) and more specifically which don't have a year listed, therefore don't end in a closing bracket ). How can I ...
1
vote
1answer
67 views

Help creating a bash shell script based around the ls command [closed]

I'm trying to create a bash shell script that will take an input directory and give me the name and size (with units) within. I'm a bit new to shell scripts, so I've been able to build the script to ...
0
votes
2answers
81 views

bash shell loop through directory listing contents and executability

I'm currently working on a homework assignment and I need to take a given directory path and from that list the files and directories in it. While also including if it's executable or not. I'm also ...
1
vote
7answers
579 views

Matching n letter filename with ls

I am using the ls command in bash, trying to find all files or directory of length n. Let's say n=5 My command is: ls ????? But this would also include characters that are non letters such as ...
1
vote
2answers
163 views

Confused about the behavior of asterisk in ls command

On Centos and Debian I tried this. Does the * with the ls command imply recursive search? If I start to type a dir name and hit tab I see this: # ls /etc/rc<tab> rc0.d/ rc1.d/ rc2.d/ ...
0
votes
1answer
81 views

List file in sub directory with certain permission

So basically I need to list files in sub directory which has all permission for user and group but not other. Basically rwxrwx--- All I got is: ls -d */* to show the sub directories but now how ...
0
votes
2answers
64 views

List files in your home directory [duplicate]

Im having trouble figuring out that, if I'm in let say the directory /home/test/test2 but I want to find the number of files in the /home directory, how would I do it. I know how to do it if it was ...
0
votes
2answers
50 views

File sort by time issue

I have a requirement to identify sequence gap in a set of files. Sequence starts at FILENAME_0001 and ends at FILENAME_9999. After this the sequence is restarted from 0001. To implement a proper ...
1
vote
2answers
71 views

How to order several options of a command (ls)?

Why doesn't ls behave the same after exchanging the order of options -l and -f? $ ls -l -f 0821131236.jpg 0823130821.jpg $ ls -f -l total 33176 -rw-rw-r-- 1 t t 364186 Jan 6 16:06 ...
0
votes
1answer
51 views

Listing files with a certain extension

I'm suppose to write a command that would list all files that end in .tx with an optional t at the end. So far all I got is listing the files that end in .tx which is: ls *.tx Now my problem is ...
1
vote
2answers
163 views

using ls in bash

I have some files like this: a.10 a.15 a.20 a.30 a.40 a.50 if I want to do a same work for all of them I can use for data in `ls a*| sort -n` If I want to do same work one by one. I can use: ...
3
votes
2answers
49 views

Strange discrepancy of file sizes from ls

I've been using ls -sh to check file sizes ever since 1997 or so, but today something strange happened: ninja@vm:foo$ ls -sh total 98M 1,0M app 64M app_fake_signed.sbp 800K loader 804K ...
3
votes
1answer
65 views

Change dir colour in bash output

Under Mac OSX, I am trying to change the dir colour when ls outputs in the bash shell. So I placed this line at the end of my .bashrc file and reloaded. LS_COLORS=$LS_COLORS:'di=0;32:' ; export ...
13
votes
5answers
367 views

How can I find the first missing directory in a long path?

Imagine I have a path that doesn't exist: $ ls /foo/bar/baz/hello/world ls: cannot access /foo/bar/baz/hello/world: No such file or directory But let's say /foo/bar does exist. Is there a quick way ...
2
votes
5answers
566 views

ls | grep works doesn't work with ls --color

I'm trying to list all hidden dirs with the following command ls -lhAF1 | grep -E '^d.*[0-9]{2}:[0-9]{2} \.' which works perfectly fine Explanation for Regex: I'm trying to get all rows that ...
53
votes
4answers
3k 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 ...
11
votes
2answers
443 views

Why does `watch` make `ls /tmp` list contents of $HOME?

I'm trying to watch number of files in my /tmp/ directory. For this I thought this command would work: watch sh -c 'ls /tmp/|wc -l' But it appears to work as if ls had no arguments. Namely, I'm in ~...
1
vote
3answers
212 views

How to exclude the output file from ls output

Let's say I have these files on desktop: aaa.jpg bbb.jpg I want to list these two jpg's and output them to a .txt file: #!/bin/bash cd ~/Desktop ls -1 > all.txt With this code the all....
1
vote
1answer
78 views

ls -lu does not give last access time

The manpage of ls says: -u with -lt: sort by, and show, access time; with -l: show access time and sort by name; otherwise: sort by access time but that doesn't seem to work: test@...
1
vote
2answers
163 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
40 views

files per directory in a single line

I have following directories: Sample1 Sample2 Each of it contains multiple subfolders like Sample1/R1/ Sample1/R2/ Sample1/R3/ Sample2/R1/ Sample2/R2/ Sample2/R3/ Which further contains ...
0
votes
1answer
42 views

my home directory appears in my download directory

In my Downloads folder when I run ls I see the home directory, and I don't know why, I want to remove it but I am afraid to remove my home folder. Can anyone tell me how I can just remove the home ...
1
vote
1answer
84 views

udev creates the right rules, but rights disappear as soon as I try to access files via C++

I'm facing a really strange problem using udev. As I already explained here I'm trying to access some folders/files as a no root user Here are my udev rules for the gpio folder: KERNEL=="gpio*", ...
0
votes
1answer
78 views

Strange directories in /home

There are some strange directories appearing in /home (so far, maybe in other locations too). These directories do not show up in ls but do with bash's tab autocomplete, when doing things like cd. ...
1
vote
2answers
114 views

Listing line number of results in `find` and `ls` [duplicate]

Is it possible with either find or ls to see, in a list of results, if any given entry is the nth result, what n is? So, for example, pretend ls -l returns: total 0 -rw-rw---- 1 bigdog bigdog 0 Jan ...
2
votes
1answer
50 views

size of directory reported by ls [duplicate]

I understand the size reported by ls corresponds with number of inodes inside the directory, not their actual size. I have noticed peculiar behavior, when displaying directory size with ls. Here is ...
1
vote
4answers
152 views

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

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
54 views

ls default sorting inconsistent

Why does adding identical characters to the end of filenames change the sort order as shown below? In any sane string comparison method I would expect the comparison of 2 strings to not differ if the ...
6
votes
3answers
278 views

Flatten the output of a recursive directory listing

Is there a way to list out all the files within a directory tree in a single list, sorted by modification time on Linux? ls -Rlt lists out files recursively, but they are grouped under different ...
3
votes
1answer
77 views

ls & dircolors - differentiate between symlink to directory and symlink to regular file

Is it possible to have the colors for symlinks-to-directories be colored differently than other symlinks? I know I can do: Link target to get the symlinks to take the color settings of their ...
0
votes
0answers
12 views

What are the possible file type characters `ls -l` can make, and what do they all mean? [duplicate]

Running ls -l, I can get a lot of different prefixes for the permissions, for example: lrwxr-xr-x drwxr-xr-x prw-r--r-- These are permission from a link, a directory, and a pipe respectively. What ...
1
vote
0answers
50 views

change ls color on OpenWrt

I am not able to change the color of dir entries for ls command (dark blu is a very annoying color to read) on my OpenWrt device. I've added the line LS_COLORS=$LS_COLORS:'di=0;37:' ; export ...
1
vote
4answers
404 views

How to sort files by part of the filename?

Given the files below: ABC38388.SC01.StatueGrade_MKP ABC38388.SC02.Statue_GKP DEF38389.SC03.Statue_HKP XYZ38390.SC00.Statue_WKP How can I list them all based on the SC value, like this: XYZ38390....
10
votes
6answers
6k views

How do I pipe ls to grep, and delete the files filtered by grep?

I wanted to delete some package in my home file, but the filename was too long (google-chrome-stable_current_i386.deb). So, I decided to use the command ls|grep chrome|rm to pipe the files to grep to ...
3
votes
3answers
351 views

List the first 4 lines of all the files in a given directory

What command could I create that will list the first 4 lines of all the files in a given directory?
0
votes
0answers
17 views

How are the sizes of Linux directories determined? [duplicate]

The results of ls -lh provides, among other things, a listing of subdirectories and their sizes. As the directories' sizes are not determined by the sum of the files within them, how are they ...
1
vote
2answers
93 views

`du -b` shows different size than `ls`

I have a directory with a few hundred files (real files, no symlinks, no subdirectories). When I use ls -la and sum up the sizes in Excel I get 287190 bytes(?). When I use du -b or du --apparent-...
0
votes
1answer
70 views

how to get latest file in each dir

Is there a Unix command to get the latest file in logsarchive of each dir of /app/instance? In the example below, I have 5 folders in /app/instance: as_a, as_b, as_c, aunz, naeu and I need to get the ...
0
votes
1answer
70 views

bash: How to determine the largest number (newest version) from: ls *.tar.gz | cut -c 2-4

Hi I'm trying to get the largest number (newest version) of a file, I got a bunch of tar.gz files in a directory, versions of some software in the format v${version_number}_software.tar.gz, where ${...
0
votes
1answer
38 views

ls without --time-style support

I need the achieve the same output in FMTIME as achieved by the following command: FMTIME=`ls -l --time-style=+%s $FILE | cut -f6 -d' '` but my linux does not support --time-style. I am running :: ...
1
vote
3answers
77 views

How use an if statement to change the output message

When i run this command it still outputs the same message when nothing is in the waste bin directory, how could I get the command to output a different message when there are no files in the bin? ...
1
vote
2answers
509 views

File Permissions Sticky&User Execution

After the website of a client has been hacked, I found some files with the following permissions set What exactly S and T stands for? Also, which one is the command to set them with those ...
2
votes
1answer
399 views

passing variables from 'ls' to 'tar' via 'xargs'

I am trying to do something like ls -t | head -n 3 | xargs -I {} tar -cf t.tar {} to archive the 3 last modified files but it ends up running the tar command separately for each of the files and at ...
2
votes
1answer
99 views

ls after cd in tcsh?

I cannot seem to find an answer to this question. In my .bash_profile I have this line: cd() { builtin cd "$@"; ll; } which executes ll every time I change directories. I would like this ...
1
vote
1answer
577 views

ls: No such file or directory error

I am writing a very basic shell for my school. Even thought commands like "pwd" or "date" works when i try "ls" it shows me that "ls: No such file or directory error" The code of my shell is bellow:...
0
votes
1answer
86 views

How do I do a long listing of files and only show those that are a certain size?

I need to show a long listing of files in a directory but only those that are a certain size in bytes. Can someone tell me how to do this?