6
votes
1answer
66 views

Filetype and dereference when listing directory with LS command

I'm trying to combine arguments to the ls command to list a directory content. What I'm basically trying to achieve is listing the directory dereferencing all links, but showing explicitly that the ...
3
votes
1answer
45 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 ...
1
vote
3answers
420 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 ...
2
votes
4answers
69 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 ...
4
votes
4answers
157 views

What is the Linux command to display how many file names in the directory end in two digits

What is the Linux command to display how many file names in the directory end in two digits? Using ls with a command like this : ls -l | wc –l *[0-9][0-9]
1
vote
1answer
43 views

GeeXbox ls shows no date?

Recently, I tried connecting to my GeeXbox via WinSCP but got an error indicating the output of ls could not be parsed. Apparently, my ls does not include a time stamp! What might be the cause and ...
66
votes
8answers
9k views

Why *not* parse `ls`?

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with ...
5
votes
2answers
263 views

Why doesn't my loop over the output of ls work?

I am trying to feed Directory names into a for loop. My code is as follows: td='/Test/TopDir/' cd "$td" for x in $(ls -d */ | cut -f1 -d'/'); do echo x=$x done The top directory I run this on ...
7
votes
6answers
773 views

Is it possible to remove folder prefix from a `ls` command

I am in a bash script and I want to get the list of all files (let say all jar files). I execute the command ls -1 lib/*.jar and I get the output: lib/mylib_1.jar lib/mylib_2.jar ... Is there any ...
3
votes
1answer
44 views

Customize bash to always include a certain parameter

When using the "ls" command, bash prints in the following format: file1 file2 file3 file4 file5 file6 file7 file8 But when given the parameter "-1", it prints: file1 file2 file3 etc... Is there ...
1
vote
3answers
310 views

How to display “human-readable” file sizes in find results?

I'm trying to find all large files on my Centos server. To do that I'm using: find / -maxdepth 10 -size +100000 -ls I tried changing -ls to -lsh but it is not allowed. How can I display these ...
2
votes
3answers
146 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 ...
1
vote
2answers
827 views

Differing outputs of the commands “ls .*” and “ls *.”

The command ls .* when run gives as output the following : All the files in the current directory starting with a . (hidden files) All the files in the hidden directories present in the ...
21
votes
9answers
2k 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 ...
3
votes
1answer
1k views

Using regex in ls and mv

I have a directory structure like this ├── UK │   ├── BuyBand_go_UK.png │   ├── BuyBand_go_UK.svg │   ├── BuyBand_K.png │   ├── BuyBand_K.svg │   ├── BuyBago_UK.png │   ├── BuyBago_UK.svg │   ├── ...
1
vote
4answers
335 views

Tail -f the most recent log file

In a few spots I got this to work ls -rt /path/to/log/file/ | tail -1 | xargs tail -f But I can't figure out why it won't always work (This is quick fix until I get the log rolling fixed here)
1
vote
1answer
180 views

The result of echo * and echo .*

Thereotically, the result of command echo * should be "Any file in the current directory". Should it include the dotfile? Similarly, Should the result of ls * include the dotfile?
2
votes
2answers
2k 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 ...
29
votes
7answers
3k 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, ...
2
votes
2answers
496 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
3answers
774 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 ...
5
votes
4answers
471 views

Shell command to get all the files from a complex directory structure

I'm looking for a shell command in order to get all the files in a complex directory structure. By complex directory structure I mean that there's a root folder with more than 150 subfolders and for ...
1
vote
2answers
521 views

Ignore all matches to negated extglob pattern in recursive ls

I would like to recursively list all files in a directory which match a given input pattern using ls. (Oh, and this is in Bash). The only way I can think of to do this using ls is to shopt -s extglob ...
4
votes
2answers
477 views

Get the complement of the result of an ls command

Let's say I have a directory with multiple files, all of which are either binary files (files with no declared extensions) and source files (.c extension). I do this: $ ls and get: README.md ...
2
votes
1answer
1k views

How does wc -l `ls` give the actual number of lines?

Can anyone explain to me how does this command work. wc -l `ls` while this command gives the total number of java lines or txt lines.
0
votes
1answer
359 views

difficalty to save traceroute output in shell variable?

I need to filter and store traceroute output in shell variable (array). But I am getting some unusual output. As I try to explain in following lines. My present directory is temp, having some ...
2
votes
2answers
2k views

Displaying the last N modified files?

How can I list the 10 most recently modified files of a certain extension, not all files, or the files modified during the last 2 days for example?
4
votes
4answers
333 views

List any file ending with .in and corresponding .out with shell script

I have a directory full of files ending with different extensions, how would I list/select only the files ending with .in and corresponding .out that share the same basename? e.g. file1.txt file1.in ...
1
vote
2answers
313 views

List info about files/directories with spaces

I am trying to use ls to get information about files and directories. My current command fails to properly get the name whenever a file/directory has a space. I am using this to list all ...
4
votes
3answers
1k views

Using OR patterns in shell wildcards

Contents of my dir are $ ls -lrt total 0 -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 night.txt -rw-r--r-- 1 user1 admin 19 Oct 8 12:31 noon.txt -rw-r--r-- 1 user1 admin 38 Oct 8 12:31 day.txt I ...
1
vote
6answers
3k views

ls: Do not show directories that match same pattern in wildcard searches, only files

Supposing I have something like the following, a typical business PC situation: drwxr-xr-x 1 whatever whoever 3 Oct 3 16:40 invoices2009 drwxr-xr-x 1 whatever whoever 4 Oct 3 16:40 ...
15
votes
6answers
12k views

How to match case insensitive patterns with ls?

I would like to list all files matching a certain pattern while ignoring the case. For example, I run the following commands: ls *abc* I need to see all the file that have "abc" as a part of the ...
1
vote
1answer
425 views

M-x ansi-term colors in Emacs 24.x

I have noticed that some colors in LS_COLORS don't work when running a shell inside M-x-ansi-term in Emacs. For exmaple; di 00 94 is supposed to turn on bold on light blue on directories on ...
6
votes
4answers
649 views

ls colors for permissions

Is there a way to control the color output of ls to highlight specific permissions on files? (e.g. write permissions). Any options in LS_COLORS that would do this? (the image above is from Dired+ ...
6
votes
7answers
11k views

List only regular files (but not directories) in current directory

I can use ls -ld */ to list all the directory entries in the current directory. Is there a similarly easy way to just list all the regular files in the current directory? I know I can use find find . ...
4
votes
3answers
963 views

How can I do the equivalent of tail -f with ls? [duplicate]

Possible Duplicate: Is it possible to follow a command (run repeatedly)? as one would follow a file using tail -f? I would like to monitor files that are being downloaded to a directory in ...
1
vote
3answers
598 views

Display a menu of files names and let the user select a file by entering a number

I have created a script that allows the user to select a file by copying and pasting that file. Then perform a grep on that file. I want to know is it possible to put a number in front of each files ...
12
votes
1answer
5k views

ls taking long time in small directory

Running Ubuntu, I open a terminal and do sudo bash cd / ls | head -n 1000 And predictably about 20 directories are returned. However, if I do an ls, and don't pipe it into anything, the ls just ...
3
votes
2answers
142 views

How do I create a structured list of all the files and directories under a particular directory (recursively)?

I need to have an "image" of a file system without actual contents of the files - just all the names and the structure, so that I can read the file and know what files were stored there and how were ...
7
votes
6answers
6k 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 ...
3
votes
2answers
115 views

Executables show with character * next to their name in output of ls

I noticed that when I list my executables with ls on my Z shell they show up with a character * next to their name (e.g. see the file in red .test_color_scheme)     What is causing ...
3
votes
2answers
903 views

recursive 'ls' giving absolute filenames

When I do 'ls -R' in a directory, I get something like ./dir1 dir2 file1.txt file2.txt ./dir1/dir2 file3.txt file4.txt but I would like a command that gives me ./dir1/file1.txt ./dir1/file2.txt ...
2
votes
1answer
1k 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/) ...
4
votes
2answers
4k views

How to list ALL directories according to their size? [without including the parent directory]

I have a bunch of random folders, some of them are hidden (beginning with a period). I want to list all of them, sorted by their sizes. I have something on the lines of this in mind: ls -d -1 -a */ ...
4
votes
4answers
1k views

file $(ls /usr/bin/* | grep zip) command gives me errors. What's wrong?

I'm a total noob when it comes to unix/linux commands and I decided to read a book. I've reached a chapter where they try to explain how to pass the output of commands as expansions to the shell. ...
6
votes
3answers
2k views

How do i open all files that are the result of a ls command?

I'd like to open all text files that are the result of a ls command using a text editor. How do i do this?
17
votes
11answers
2k views

Linux - command to list files (except ls)

Imagine you were working on a system and someone accidentally deleted the ls command (/bin/ls). How could you get a list of the files in the current directory? Try it. I tried many ...
10
votes
4answers
18k views

Why is Debian's root shell colorless?

Are there any security concerns? What is the best way to enable it?
4
votes
2answers
895 views

How can I search for a file with fixed name length using ls?

In a directory, I have files like lazer_100506 lazer_100707 lazer_091211 lazer_110103 lazer_100406_temp lazer_100622#delete etc How can I get a listing of only the first four files? $ ls ...
4
votes
1answer
288 views

Set ls color listings based on regex instead of globbing

Is it possible to set regex patterns for color matching in the LS_COLORS variable? So instead of just *.jpg=38;5;220 Can I do \.(jpg|gif)=38;5;220 That's just an example, I'd like to get more ...