The ls command lists the contents of a directory.

learn more… | top users | synonyms

3
votes
2answers
2k 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 ...
3
votes
1answer
350 views

Zsh autocomplete ls command with directories only

Suppose I have following files and directories: % ls bui00293 buiawer builds/ buiowpe/ I want to list the content of ...
3
votes
2answers
94 views

exit a script if an ls line did not find any match

I am writing this script that have this line: ls -lrt /dir1/dir2/filename*.txt | tail -1 | awk '{print $9}' | read variable What I wanted is to exit the script (without using if-statement) if it ...
3
votes
1answer
62 views

`echo test?` prints `test2` but `ls test?` prints nothing

I was playing with bash globbing recently and I noticed the following: First, make 2 dirs: $ mkdir test $ mkdir test2 Then: $ echo test? Outputs (correctly): test2 But: $ ls test? Outputs ...
3
votes
1answer
144 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 ...
3
votes
3answers
134 views

How can I list all files and symlinks in a compact view?

This is my setup in /tmp/test/ if I use ls -l -rw-r--r-- 1 rubo77 rubo77 0 Okt 21 04:15 a -rw-r--r-- 1 rubo77 rubo77 2 Okt 21 04:16 b drwxr-xr-x 2 rubo77 rubo77 4,0K Okt 21 03:58 c ...
3
votes
2answers
132 views

customise ls color for directories contain specified file/s

How can I colorize directories contain files with word INCORRECT inside? Example: I have 3 directories which contain log file. dir_a/log dir_b/log dir_c/log The file log in dir_c contain word ...
3
votes
1answer
996 views

ls -a not showing folder “system”, but echo * shows it

When I create a folder named system in my home folder, or in /tmp (can't try other locations as I am not root, but owner confirmed same problem even on root), ls -a will not show it. Also tried ...
3
votes
3answers
1k views

Really strange FAT32 file listing problem

I'm mounting a FAT32 drive on my NAS (which has a USB port), and hitting a strange issue when I use the ls command on the drive root: ls: cannot access ???²é?u.g: Input/output error ls: cannot ...
3
votes
0answers
866 views

ls and vim color on SunOS 5.8/Solaris 8

I want to use ls and vim with color on Sunos 5.8 SunOS 5.8 Generic_117350-11 sun4u sparc SUNW,Sun-Blade-2500 I have installed ls (GNU coreutils) 6.9 and vim 7.2 In ~/.cshrc: setenv TERM sun-color ...
2
votes
3answers
271 views

When was a file last opened?

How do I determine, when a file was last opened? I've looked at man ls (using GNU coreutils 8.22) and I don't see anything about this timestamp.
2
votes
3answers
440 views

Command substitution in for loop not working

I want to keep all files not ending with .bat I tried for f in $(ls | egrep -v .bat); do echo $f; done and for f in $(eval ls | egrep -v .bat); do echo $f; done But both approaches yield the ...
2
votes
1answer
6k views

Alias for directory listing sorted by time modified in reverse order

When I need to find my recently used files, this command: ls -lt lists in ascending order (by time), when there are lots files, I need to scroll to the top to see needed files, because wont fit in ...
2
votes
3answers
968 views

Where is “showing the output of the 'ls' command vertically” documented?

I found out it's possible to show the output of the ls command vertically using the -1 switch: $ ls -1 But couldn't find it in the manual of ls. Is it a secret option?
2
votes
4answers
12k views

Unix Command to return all files that end with single digit and TXT extension

Which command returns all files that end with a single digit and have the TXT extension ?
2
votes
6answers
929 views

sort ls output by users

On Linux, is there a way to sort ls output by users? What I try to achieve is something like this: user_a   file1 user_a   file2 user_b   another_file user_c   this_file user_c ...
2
votes
1answer
4k views

How to get exact file size and file name?

Right now I am using ls -lt /my/directory (see below) then php parses the output. But inconsistently because the delimiter is space and there might be two or more spaces in between two fields. The ...
2
votes
3answers
156 views

Strange formatting of date in bash script

I am working on a script to sort my downloads folder by the date the files were created. This is the script I am using: #!/bin/bash cd ~/Downloads for FILENAME in * do if [[ -f $FILENAME ]]; ...
2
votes
5answers
191 views

List a directory but only if it contains sub-directories?

In Unix, is it possible to use one command ONLY to list directories if they contain a sub-directory? For example, I would like to list the directory name if it contains a sub-directory called ...
2
votes
3answers
594 views

Can I list only specific subdirectories?

I have a folder tree structure like arndell \_databases \_daily \_weekly claremont \_databases \_daily \_weekly monte \_databases \_daily \_weekly and I am only after all files inside ...
2
votes
2answers
962 views

How do I show all files in a directory except those that have a certain extension AND display them in multiple columns?

Since I write in Python a lot it's kind of annoying to see .pyc files all the time and I would like to just hide them at this point. I tried the following, but I can't seem to figure out how to get it ...
2
votes
3answers
911 views

How universal is the -L (dereference symlink) switch of the 'ls' command?

I have some software that, among other things, needs to: Assess a file's rwxrwxrwx permissions; Work under every possible flavor of Unix and Linux you can find in the wild. Currently, it does that ...
2
votes
4answers
144 views

Get the latest directory (not the latest file)

My folder parent has the following content: A.Folder B.Folder C.File It has both folders and files inside. B.Folder is newer. Now I just want to get B.Folder, how could I achieve this? I tried ...
2
votes
2answers
104 views

Very strange ls > textfile problem when viewing with emacs

I want to list the components of the current working directory in a text file ls -1 > textfile Output looks fine with more. 1010661085645 1010729039145 1010747080245 1010849051345 ...
2
votes
3answers
524 views

Count number of characters per listed filename

Given the following ls result: $ ls Desktop Documents Downloads Music Pictures Public Templates Videos This will give the total number of characters for all files: $ ls | wc -m 67 But how ...
2
votes
2answers
623 views

Working of rm/ls with [0-9]

I am learning the shell commands and came across the short tags eg.[0-9],[[:digit:]] etc.. As a proof of concept i tried deleting all the files with the rm command(i know its not a good practise but i ...
2
votes
2answers
200 views

Difference between `ls -c` and `ls -t`

What is the difference between -c and -t options for the ls Unix command? And how can I sort by date of creation with the ls command?
2
votes
2answers
4k 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 ...
2
votes
2answers
3k views

Linux listing files between two date without touch command

I need a command which will list the files between given date and time (YYYYMMDDHHMMSS - format) in to a text file. I don want to use touch command as its creating permission issue. I am new to this ...
2
votes
1answer
108 views

cd and ls in the same call [duplicate]

I often have to cd to a directory and ls to see the directory listing. Can it be done with one shot, so that I can add to .bashrc as alias. I searched on Google, there were some answers, but ...
2
votes
2answers
168 views

Can I `ls` all files in a directory from “1”, “2”,…,“9”, “10”, “11”, …, “20”, “21”, …?

I have a directory with files named "1", "2",...,"9", "10", "11", ..., "20", "21", ... inside. Can I list them in the order of "1", "2",...,"9", "10", "11", ..., "20", "21", ...? I have tried ls ...
2
votes
4answers
772 views

No such file or directory error when using xargs

I have some files with .mkv extension and I want to calculate their total size using du -h. Some of the files are preceded by whitespace characters. ranveer@ranveer:~$ ls *.mkv ...
2
votes
2answers
1k views

ZSH: `ls *(.)` lists regular files only but `ls *(/)` does not list directories only

I'm not sure I am using ZSH's globbing correctly, but I thought ls *(/) would just list the dirctories under pwd, but it doesn't, it recursively lists all files under every directory under pwd (I got ...
2
votes
3answers
183 views

Preserving color output with cut

Using bash interactively I am trying to use cut to prevent the lines from going longer than my terminal width. But when using a command with colorized output all the color gets removed by cut. For ...
2
votes
3answers
831 views

How can a group own a file?

Whe I do ls -l, two of the fields are username of the owner and name of the owning group. The username is clear - I created the file, it is mine. However the group entry confuses me. My user is a ...
2
votes
2answers
7k views

Solaris + display file time stamp [year][month][day]

I have Solaris 10 machine I need to verify time stamp of some file in my Solaris machine And to get the following format [year][month][day] Example of working command on Linux ls -l ...
2
votes
2answers
141 views

What does it mean when the output of $ls -lasrt includes '.' and '..'

I input the command: $ ls -lasrt And the output includes (there are more results, these are the ones that confuse me): 4 drwxr-xr-x 5 tuc40953 stdchem 4096 Jul 3 17:48 .. 4 drwxr-xr-x ...
2
votes
4answers
172 views

List only file size and name and symlinks

When I use ls -lah I get lots of information for each file. How can I get only the name and filesize? Additionally I would like to keep the listing of symlinks with the arrow like lrwxrwxrwx 1 ...
2
votes
2answers
241 views

ls should display contents of flat directory structure in columns

I've got the a flat directory structure like this. ├── kanban │   ├── 1_backlog │   ├── 2_analyze │   ├── 3_doing │   ├── 4_test │   ├── 5_approval │   └── 6_done Each directory contains text ...
2
votes
1answer
91 views

Which option of ls should be used for understanding metadata changes?

How can one find the latest time of metadata changes to a file? Let's say I changed the ownership of a file and then I did ls -l. It still shows the latest file changes. But I want to see the time ...
2
votes
3answers
3k views

output only file names(with spaces) in ls -Al

I should echo only names of files or directories with this construction: ls -Al | while read string do ... done ls -Al output : drwxr-xr-x 12 s162103 studs 12 march 28 12:49 personal ...
2
votes
3answers
883 views

Find directories that do not contain subdirectories

I'm writing script is ksh. Need to find all directory names directly under the current directory which contain only files, not subdirectories. I know that I could use ls -alR and recursively parse ...
2
votes
2answers
212 views

Move one file at a time based from specific number in the files

Based from this question, The HTML files date format has been changed. All of the HTML files have the date such like below: 20110730dateishere dateishere is intentionally added by me in the files, ...
2
votes
1answer
2k views

Why can't list file/directory relative to .. from a symbolic link directory (No such file or directory)?

I have a /usr/tomcat6/logs directory linked to /var/log/tomcat6. When I changed directory to /usr/tomcat6/logs and try to ls files using a relative pathname ../conf/Catalina/localhost, a No such file ...
2
votes
2answers
2k views

Setting up LS colors with a human-readable script in tcsh

I have a shell script (set_up_my_ls_colors.sh) that, if I call from my shell, it configures my color scheme for ls. The nice thing about the script is that it allows me to configure colors in a ...
2
votes
3answers
8k 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
1answer
2k views

Enable line breaks when assigning multi line outputs to var in bash

I'm using the following very basic shell script I copied off the net to list the contents of my database backup folder and mail them regularily: MYSQLLIST=$(ls -lhG /var/backups/mysql/daily/) ...
2
votes
1answer
1k views

LS_COLORS settings for specific types of files

I'm trying to set up my color scheme for ls, and I'm having trouble finding information about exactly what parameters I have to work with, or where those come from. And especially setting colors for ...
2
votes
1answer
25 views

Regarding identical copies of gedit files

When ever I save a gedit file in a directory, two copies of it get saved with identical content. Ex: If the gedit file is named as file_name and saved in Home directory then when u ls the Home ...
2
votes
1answer
208 views

What file type categories do colors in the terminal represent in various distros (by default)?

I'm discovering new file type categories (if one can call different colors in the terminal in such a manner) almost on a daily basis. Still, I haven't found an exhaustive list of all recognized file ...