ls

How to recursively search for files with certain extensions?

北城余情 提交于 2019-12-03 05:49:27
I need to find all the .psd files on my Linux system (dedicated web hosting). I tried something like this: ls -R *.psd , but that's not working. Suggestions? You can use the following find command to do that: find /path/to/search -iname '*.psd' iname does a case insensitive search. you also can ls ./**/*.psd but: you must have bash version 4+ you must have shopt -s globstar #in your .bashrc or .profile, etc.... will search case sensitive (or you must set shopt -s nocaseglob too) 来源: https://stackoverflow.com/questions/5985752/how-to-recursively-search-for-files-with-certain-extensions

Implementing the ls -al command in C

久未见 提交于 2019-12-03 05:12:26
As a part of an assignment from one of my classes, I have to write a program in C to duplicate the results of the ls -al command. I have read up on the necessary materials but I am still not getting the right output. Here is my code so far, its only supposed to print out the file size and the file name, but the file sizes its printing are not correct. Code: #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <dirent.h> int main(int argc, char* argv[]) { DIR *mydir; struct dirent *myfile; struct stat mystat; mydir = opendir(argv[1]);

Find count of files matching a pattern in a directory in linux

耗尽温柔 提交于 2019-12-03 00:00:22
I am new to linux. I have a directory in linux with approx 250,000 files I need to find count of number of files matching a pattern. I tried using following command : ls -1 20061101-20131101_kh5x7tte9n_2010_* | wc -l I got the following error message: -bash: /bin/ls: Argument list too long 0 Please help. Thanks in advance It might be better to use find for this: find . -name "pattern_*" -printf '.' | wc -l In your specific case: find . -maxdepth 1 -name "20061101-20131101_kh5x7tte9n_2010_*" -printf '.' | wc -m find will return a list of files matching the criteria. -maxdepth 1 will make the

Maximum number of inodes in a directory? [closed]

只愿长相守 提交于 2019-12-02 18:50:45
Is there a maximum number of inodes in a single directory? I have a directory of over 2 million files and can't get the ls command to work against that directory. So now I'm wondering if I've exceeded a limit on inodes in Linux. Is there a limit before a 2^64 numerical limit? tonylo df -i should tell you the number of inodes used and free on the file system. Robᵩ Try ls -U or ls -f . ls , by default, sorts the files alphabetically. If you have 2 million files, that sort can take a long time. If ls -U (or perhaps ls -f ), then the file names will be printed immediately. No. Inode limits are per

Windows equivalent for Unix find command to search multiple file types

ぃ、小莉子 提交于 2019-12-02 15:20:29
While having a cygwin installed in windows gives most of unix command, still i was wondering how to search multiple filetypes in one command using windows "find" command. ie: find . -name *.cpp -o -name *.h -o -name *.java The above command gives me a list of all cpp, h & java, what will be the equivalent using the windows find? This will locate all files with the given extensions in the current working directory and all subdirectories: dir *.cpp *.h *.java /b/s See https://technet.microsoft.com/en-us/library/cc755121.aspx for more info on using dir . findstr /p /s /i . above command searches

Outputting result of “dir” to console in Java

∥☆過路亽.° 提交于 2019-12-02 11:25:27
I want to output the result of the "dir" command to the java console. I have already looked on Google and here, but none of the examples work for me, thus making me rite this post. My code is as follows: try { System.out.println("Thread started.."); String line = ""; String cmd = "dir"; Process child = Runtime.getRuntime().exec(cmd); //Read output BufferedReader dis = new BufferedReader( new InputStreamReader(child.getInputStream() )); while ((line = dis.readLine()) != null) { System.out.println("Line: " + line); } dis.close(); }catch (IOException e){ } What am I doing wrong? Any help would be

Bash regex: how to match n times using 'grep' or 'ls'

假装没事ソ 提交于 2019-12-02 00:04:34
问题 I'd like to match n digits the following way with grep or ls: echo "ABCD150915.7z" | grep "ABCD[[:digit:]]{6}.7z" The above is not working and I've tried quite many ways now.. How can this be done? I understand there're other ways, but please note that I want to know if this specifically is possible: [[:digit:]] and {6} using grep or ls. 回答1: Yes it's possible, using one of two methods: echo "ABCD150915.7z" | grep -E "ABCD[[:digit:]]{6}.7z" Enabling Extended regular expression mode with -E

How to remove dir background in `ls -color` output

☆樱花仙子☆ 提交于 2019-12-01 22:37:26
I use default Linux Mint .bashrc, here is full bashrc , the output is like: some dir has green background, How to remove it? To remove all background colors, stick the following into your ~/.bashrc : eval "$(dircolors -p | \ sed 's/ 4[0-9];/ 01;/; s/;4[0-9];/;01;/g; s/;4[0-9] /;01 /' | \ dircolors /dev/stdin)" The explanation is given in the output of dircolors -p , e.g., Of course dircolors doesn't color its output. I used this script: #!/usr/bin/perl -w use strict; our $comment = "\e[31m"; our $reset = "\e[K\e[m"; our @data; open my $fh, "dircolors -p|" or die "cannot read from dircolors";

Is there any established order for 'ls' arguments?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 19:48:48
I'm a student and as part of my cursus I must recode the ls command and reproduce its behaviour the best possible. On Mac (El Capitan 10.11.6), using the terminal iTerm 2(zsh), I get: user> ls . -R ls: -R: No such file or directory And on Arch (latest version), using the default text interface(bash) I get: user> ls . -R <current directory content> Although I'd rather trust Arch, is it correct for ls to refuse its option after a directory has been specified ? And is there any documentation declaring the arguments order ? See POSIX utility syntax guidelines , entry #9: Guideline 9: All options

Colorize filename according to svn status

…衆ロ難τιáo~ 提交于 2019-12-01 15:07:53
When invoking ls , I would like to have file names with a different color depending on their subversion status. For example, an added file will be cyan, a modified file red and so on. Is it possible with the bare power of bash? Is there something ready on this regard ? As far as I know, it is not possible to achieve that with pure bash (scripting aside). You can quite easily get colorised file listing using scripts (bash, python, perl, whatever your poison). Here's a rather crude proof-of-concept implementation written in python : https://gist.github.com/776093 #!/usr/bin/env python import re