ls

Command to list all files except . (dot) and .. (dot dot)

会有一股神秘感。 提交于 2019-12-05 09:39:02
问题 I'm trying to find a command that would list all files (including hidden files), but must exclude the current directory and parent directory. Please help. $ ls -a \.\.. 回答1: Read ls(1) documentation (perhaps with man ls ). At least, take the habit of trying ls --help or better yet (since ls might be aliased, e.g. in your ~/.bashrc ) /bin/ls --help You'll get something starting with: Usage: ls [OPTION]... [FILE]... List information about the FILEs (the current directory by default). Sort

how to `git ls-files` for just one directory level.

痞子三分冷 提交于 2019-12-04 22:43:50
I'm using msysgit (1.7.9), and I'm looking for the right invocation of the git ls-files command to show just the (tracked) files and directories at the current level, either from the index, or the current working directory if that's easier. Essentially it would give a directory listing similar that that you would see on Github. Coming from Windows, I'm not too familiar with the right way of doing the globbing(?). I think you want git ls-tree HEAD sed'd to taste. The second word of ls-tree's output will be tree for directories, blob for files, commit for submodulesm, the filename is everything

Bash list files with range

柔情痞子 提交于 2019-12-04 22:37:06
My script has to list all files between a given range of date within a file name (ex: 20130133.212001.log). The start date and end date will be given by user. I now have start_year, end_year, start_month, end_month....so on till end_second. My plan was to use ls syntax: ls *{start_year..end_year}{start_month..end_month}{.....}.log But the problem is if month or date has 01 bash is taking it as 1. Indeed my bash version is older than 4. I can't considering updating the bash version. Any other method that I use to list files in such range. [EDIT] $> cat tmp.sh #! /bin/bash start_year=2013 end

Hiding function names from ls() results - to find a variable name more quickly

痴心易碎 提交于 2019-12-04 09:08:12
When we have defined tens of functions - probably to develop a new package - it is hard to find out the name of a specific variable among many function names through ls() command. In most of cases we are not looking for a function name - we already know they exist - but we want to find what was the name we assigned to a variable. Any idea to solve it is highly appreciated. If you want a function to do this, you need to play around a bit with the environment that ls() looks in. In normal usage, the implementation below will work by listing objects in the parent frame of the function, which will

Outputting result of “dir” to console in Java

与世无争的帅哥 提交于 2019-12-04 07:03:45
问题 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

Is there any established order for 'ls' arguments?

谁说胖子不能爱 提交于 2019-12-04 03:55:26
问题 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

Colorize filename according to svn status

这一生的挚爱 提交于 2019-12-04 02:49:08
问题 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 ? 回答1: 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

Portable way to achieve ls' -v flag (i.e. sort by version)?

被刻印的时光 ゝ 提交于 2019-12-04 01:34:32
问题 I'm working on a some build scripts that I'd like to depend on only standardized features. I need to sort some files by version. Say the files are bar-1.{0,2,3} bar-11.{0,2,3}. By default, ls gives me: bar-1_0 bar-11_0 bar-11_2 bar-11_3 bar-1_2 bar-1_3 Getting what I want is easy using 'ls -v': bar-1_0 bar-1_2 bar-1_3 bar-11_0 bar-11_2 bar-11_3 The problem is that 'ls -v' is not standard. Standard sort also seems to lack the option I want, though I could be looking at old versions of the

writing command line output to file

杀马特。学长 韩版系。学妹 提交于 2019-12-04 01:21:47
问题 I am writing a script to clean up my desktop, moving files based on file type. The first step, it would seem, is to ls -1 /Users/user/Desktop (I'm on Mac OSX). So, using Python, how would I run a command, then write the output to a file in a specific directory? Since this will be undocumented, and I'll be the only user, I don't mind (prefer?) if it uses os.system() . 回答1: You can redirect standard output to any file using > in command. $ ls /Users/user/Desktop > out.txt Using python, os

How to recursively search for files with certain extensions?

前提是你 提交于 2019-12-03 15:14:02
问题 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? 回答1: You can use the following find command to do that: find /path/to/search -iname '*.psd' iname does a case insensitive search. 回答2: 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) 来源: