Tagged Questions
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 ...
4
votes
8answers
143 views
Run a command on all subfolders
If you have a series of subfolders (like from a to z) and want to run a command on each one of them (like rm *.pdf or ls *.pdf), how do you do that? The "manual" approach would be cd a, rm *.pdf, or ...
3
votes
2answers
179 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
3answers
1k 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
5answers
232 views
Is it possible to reference the most recently modified file in a command line argument?
I frequently download PDF files with heinous numeric file names from my browser. These automatically go into ~/Downloads. Ideally I would like to just be able to open these files with:
evince "the ...
2
votes
4answers
79 views
Copy Sequential Files
I have 12 files named dmp_000, dmp_001, etc, all the way to dmp_011. I would like to copy all of them to rdmp_000, rdmp_001, and so on, sequentially so the numbered files coincide. There must be an ...
2
votes
2answers
55 views
Select greatest numbered filename
Simple requirement but can't find anything online which can achieve it.
I have a list of dated files as below...
filename_20120101.dat
filename_20120102.dat
filename_20120103.dat
I ...
2
votes
4answers
189 views
Access the last file (alphabetically) in a directory
I'm trying to open a file with vim from the command line, the file is in a directory filled with automatically generated files that are prepended with a time stamp. Since I don't know the time stamps ...
2
votes
2answers
210 views
How do I output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices
I am having trouble knowing how to output a count of all files with “tty” in the filename in the Linux directory that holds files on system devices.
1
vote
5answers
867 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 ...
1
vote
4answers
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 . ...