The ls command lists the contents of a directory.

learn more… | top users | synonyms

2
votes
1answer
46 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 ...
6
votes
3answers
267 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 ...
0
votes
1answer
47 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 ...
3
votes
1answer
69 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 ...
22
votes
6answers
45k views

Linux ls to show only filename date and size

How can I use ls in linux to get a listing of filenames date and size only. I don't need to see the other info such as owner or permission. Is this possible?
3
votes
5answers
896 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 ...
38
votes
13answers
18k 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 ...
0
votes
1answer
62 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
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 ...
15
votes
7answers
29k views

How do I list every file in a directory except those with specified extensions?

Suppose that I have a folder containing .txt, .pdf, and other files. I would like to list the "other" files (i.e., files not having the extensions .txt or .pdf). Do you have any advice on how to do ...
1
vote
0answers
41 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 ...
21
votes
11answers
74k 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 ...
1
vote
3answers
2k views

zsh alias being overridden somehow

I'm on a system running OS X 10.8.5. I recently tried to alias ls to ls -G -la command. I opened up ~/.zshrc, put in the alias, relaunched the terminal, but the change didn't take effect. Upon ...
3
votes
5answers
16k views

Sort the output of find -exec ls

Is it possible to the output of find … -exec ls -ls ; sorted alpabetically, by filename? This is my cron command: find /home/setefgge/public_html -type f -ctime -1 -exec ls -ls {} \; This command ...
1
vote
4answers
240 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: ...
8
votes
6answers
4k 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 ...
10
votes
2answers
7k views

Why does a new directory have a hard link count of 2 before anything is added to it?

Say I just create directory newDirectory and then I do ls -ld command. I see that the number of hard links is 2. What exactly makes the hard link 2 from the start? Also is the number of subdirectories ...
38
votes
7answers
7k views

why does ls -d also list files, and where is it documented?

when specifying ls --directory a* it should list only directories starting with a* BUT it lists files AND directories starting with a Questions: where might I find some documentation on this, ...
3
votes
3answers
346 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?
5
votes
3answers
619 views

ls --color: how to color executable hard links?

I created some hardlinks on an NTFS drive, but because of that, they are all executable and colored as executable instead of as hardlinks (regular file with more than one link). I did a test on my ...
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
86 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 ...
0
votes
1answer
51 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
37 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 :: ...
3
votes
4answers
444 views

Determining the number of files and subdirectories in Linux

When displaying directories in linux using ls -ld, I get something like this: user@shell:~/somedirectory$ ls -ld drwxr-xr-x 2014 K-rock users 65536 20011-11-05 11:34 user@shell:~/somedirectory$ ...
5
votes
2answers
6k views

file block size - difference between stat and ls

I've noticed that when I do a: ls -ls file It provides block count, say 8 blocks. When I do: stat file I notice that the block count is 16, twice the number given by ls. The block size on my ...
1
vote
3answers
69 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
415 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
72 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
82 views

sshfs: permission denied when trying to access specific folder

I can access to my specific folder like this: ssh -YX xxx@xxxxxx.xxx.xxxx.xx cd ../the/folder/I/want or with an absolute path ssh -YX xxx@xxxxxx.xxx.xxxx.xx cd ...
2
votes
1answer
218 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 ...
1
vote
1answer
455 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 ...
0
votes
1answer
82 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?
2
votes
5answers
196 views

How can I list the names of directories that contain files 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 files matching the ...
3
votes
5answers
450 views

Search files for a string and if found check if a file with paired name exists in the same directory

I have many different files with the same ending .ft1 that may or may not contain one specific word special. For the files that contain this word, I want to check whether another file with a different ...
0
votes
1answer
36 views

Using `tree`, how do I output files before subdirectories?

I tried to combine --dirsfirst and -r, but directories still show up on top, only in reverse alphabetical order. It seems like -r is applied first, which is also indicated by the man pages. Any other ...
0
votes
0answers
26 views

How can binary names in command prompt be colored

I recently saw in a presentation that the typed in commands that matched something in /bin /sbin /... were colored green. It looked nice and felt more structured. How can this be achieved with ...
4
votes
1answer
2k views

Pass colors from ls through pipe to awk 'print' statement

This is a follow-up to my question from yesterday, Show sum of file sizes in directory listing. Thanks to Zero Piraeus and a point in the right direction by Mauritz Hansen, I now have function ...
1
vote
0answers
32 views

`ls\` logs out of terminal session?

Like many, I have an alias ll=ls -l[.]+ set. A moment ago, I typed ll and then accidentally hit \ on the way to return. I hit return again to finish the command (on the continued line prompt), ...
0
votes
0answers
11 views

List extensions of files and their amount [duplicate]

I want to list file extensions and the number of files for this extensions at once. I tried this: ls -R | grep -Eo "\..+" | sort -u|wc -l but it only count the number of file extensions, without wc -l ...
0
votes
3answers
81 views

How to list all files *.html bigger than {size} excluding some {*parts*}

I need a command to list files. But I have three problems: I want files ending with .HTML and .HTM If any file has parts like: google docs or form in the name, I want to exclude it. I want just ...
0
votes
2answers
205 views

Fix LS Colors for directories with 777 permission? [duplicate]

When I run ls on a folder with directories that have a 777 permission, the ls colors are purple text with a green background, which is unreadable: What can I do to make this more pleasant to look ...
4
votes
2answers
8k views

Basic commands in Unix not working i.e: -bash: ls: No such file or directory

I'm new to Unix and in the process of installing a program for my dissertation I must have played with the PATH for the basic Unix commands such as ls. Every time I type ls and the directory name I ...
1
vote
1answer
69 views

How to make ls warning me about parent directory is symlink

I just found a scenario which i (or someone new to linux) might accidentally rm file because user thought it's duplicated file. Let's say i have this two binary files: [xiaobai@xiaobai note]$ ls ...
2
votes
1answer
858 views

How to remove all but last 10 files [duplicate]

I accumulate sequentially named files as the result of an automated process, and I would like to keep only the last 10 around. I tried this, which had the effect of deleting everything: ls -r | more ...
5
votes
2answers
556 views

How do I get the total size of everything in a directory in one line? [duplicate]

I know I can use du -h to output the total size of a directory. But when it contains other subdirectories, the output would be something like: du -h /root/test . . . . 24K /root/test/1 64K ...
55
votes
7answers
20k 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. Is the star in front of ls means how deep it can list the ...
1
vote
1answer
118 views

Why do these two find-commands give different results?

I wanted to see all files modified within the last 10 days and who owned them, so I entered the following to give me an idea how many results would be returned; find . -maxdepth 1 -mtime -10 I then ...
1
vote
2answers
2k views

How to change the output color of the ls command in terminal in OS X and iTerm2?

I know that a similar question has been asked in: How to colorize output of ls ? although I didn't really understand the answer and couldn't really make it work. However, I have tried something ...
3
votes
5answers
526 views

Look if a folder has some files with certain extensions

Suppose I have a file structure: $ cd /home/Desktop $ ls -d */ Abc/ Qwe/ Zxc/ Rty/ $ Now I want to iterate through every directory and see if they have any ".pdf" files. Could some one please ...