Tagged Questions
3
votes
2answers
58 views
Sort files by modification time
I've seen many questions and answers here using a construction along the lines of
list_dir=`ls -t /path/to/dir/`
for i in $list_dir; do
or
ls -t | while read i; do
Now, I know that you shouldn't ...
22
votes
7answers
2k 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
114 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 ...
1
vote
1answer
74 views
starting vim with command substitution
I am working on a project on two different machines - one running Mac OSX 10.8.3, and one running Red Hat Enterprise Linux. On my Mac, I can do this:
vim $(ls -R */*.@(h|cpp) */*/*.@(h|cpp))
and ...
4
votes
2answers
209 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 ...
28
votes
5answers
2k 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 ...
2
votes
3answers
2k 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 ?
3
votes
3answers
366 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
5answers
1k 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 ...
12
votes
5answers
4k 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
3answers
2k 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 . ...
7
votes
6answers
4k 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 ...
-2
votes
1answer
199 views
Why does this script show all files in the directory and not just PDF files?
I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory:
#!bin/bash
message="."
message1="*.pdf"
ls -al $message ...
2
votes
6answers
2k views
Show only hidden files (dot files) in ls alias
I'm using the command
ls -a | grep '^\.'
for showing only the hidden files.
I added the line
alias hidden='ls -a | grep '^\.'' # show only hidden files
to .bash_aliases file
but this does not ...
4
votes
4answers
789 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
1answer
7k views
Bash: assign ls | grep to a variable and echo it with a string
I want to assign the result of an expression to a variable and concatenate it with a string, then echo it. Here's what I've got:
#!/bin/bash
cd ~/Desktop;
thefile= ls -t -U | grep -m 1 "Screen Shot";
...
4
votes
2answers
508 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 ...
