ls

Python subprocess Popen: Why does “ls *.txt” not work? [duplicate]

大憨熊 提交于 2019-11-27 16:16:58
This question already has an answer here: Python subprocess wildcard usage 2 answers I was looking at this question. In my case, I want to do a : import subprocess p = subprocess.Popen(['ls', 'folder/*.txt'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() Now I can check on the commandline that doing a "ls folder/*.txt" works, as the folder has many .txt files. But in Python (2.6) I get: ls: cannot access * : No such file or directory I have tried doing: r'folder/\*.txt' r"folder/\*.txt" r'folder/\\*.txt' and other variations, but it seems Popen does not like the *

Size() vs ls -la vs du -h which one is correct size?

核能气质少年 提交于 2019-11-27 16:09:30
I was compiling a custom kernel, and I wanted to test the size of the image file. These are the results: ls -la | grep vmlinux -rwxr-xr-x 1 root root 8167158 May 21 12:14 vmlinux du -h vmlinux 3.8M vmlinux size vmlinux text data bss dec hex filename 2221248 676148 544768 3442164 3485f4 vmlinux Since all of them show different sizes, which one is closest to the actual image size? Why are they different? They are all correct, they just show different sizes. ls shows size of the file (when you open and read it, that's how many bytes you will get) du shows actual disk usage which can be smaller

Unix pipe into ls

烈酒焚心 提交于 2019-11-27 10:43:59
问题 I thought I understood *nix pipes until now... I have an executable called studio which symlinks to my install of Android Studio and I had assumed I could get the linked-to location with which studio | ls -l But that doesn't work. What it gives me is equivalent to having just run ls -l in the current directory. If I run which studio , I get /home/me/bin/studio . And if I run ls -l /home/me/bin/studio I get the expected output showing me the symlink location. So why doesn't the piped version

ls command: how can I get a recursive full-path listing, one line per file?

坚强是说给别人听的谎言 提交于 2019-11-27 09:56:00
How can I get ls to spit out a flat list of recursive one-per-line paths? For example, I just want a flat listing of files with their full paths: /home/dreftymac/. /home/dreftymac/foo.txt /home/dreftymac/bar.txt /home/dreftymac/stackoverflow /home/dreftymac/stackoverflow/alpha.txt /home/dreftymac/stackoverflow/bravo.txt /home/dreftymac/stackoverflow/charlie.txt ls -a1 almost does what I need, but I do not want path fragments, I want full paths. ghostdog74 If you really want to use ls , then format its output using awk: ls -R /path | awk ' /:$/&&f{s=$0;f=0} /:$/&&!f{sub(/:$/,"");s=$0;f=1;next}

Unix's 'ls' sort by name

无人久伴 提交于 2019-11-27 09:13:21
问题 Can you sort an ls listing by name? 回答1: My ls sorts by name by default. What are you seeing? man ls states: List information about the FILEs (the current directory by default). Sort entries alpha‐betically if none of -cftuvSUX nor --sort is specified. : 回答2: For something simple, you can combine ls with sort . For just a list of file names: ls -1 | sort To sort them in reverse order: ls -1 | sort -r 回答3: ls from coreutils performs a locale-aware sort by default, and thus may produce

How can I list (ls) the 5 last modified files in a directory?

老子叫甜甜 提交于 2019-11-27 05:03:08
问题 I know ls -t will list all files by modified time. But how can I limit these results to only the last n files? 回答1: Try using head or tail. If you want the 5 most-recently modified files: ls -1t | head -5 The -1 (that's a one) says one file per line and the head says take the first 5 entries. If you want the last 5 try ls -1t | tail -5 回答2: Use tail command: ls -t | tail -n 5 回答3: The accepted answer lists only the filenames, but to get the top 5 files one can also use: ls -lht | head -6

How to create ls in windows command prompt?

寵の児 提交于 2019-11-27 04:59:58
问题 I want to use ls in windows command prompt and make it run the dir command. How can I do that? 回答1: You could: create a batch file called ls.bat and have it contain the dir command only add the directory where the ls.bat file exists to your PATH environment variable You could then execute ls from a command prompt. 回答2: You can solve this question with one simple command: echo @dir %* > %systemroot%\system32\ls.bat Make sure you run cmd.exe as admin first if you are on vista and up 回答3: Its an

Regular Expression usage with ls

大城市里の小女人 提交于 2019-11-27 04:21:50
I am trying to use ER (Extended Regular Expressions) with ls like ls .+\..+ . I am trying to print all files which contains an extension (I know I could have used ls *.* , but I wanted to try using ER). When I run that code I get this error: ls: .+..+: No such file or directory . You are confusing regular expression with shell globbing . If you want to use regular expression to match file names you could do: $ ls | egrep '.+\..+' You don't say what shell you are using, but they generally don't support regular expressions that way, although there are common *nix CLI tools ( grep , sed , etc)

Delete all files except the newest 3 in bash script

ぃ、小莉子 提交于 2019-11-27 03:13:29
问题 Question: How do you delete all files in a directory except the newest 3? Finding the newest 3 files is simple: ls -t | head -3 But I need to find all files except the newest 3 files. How do I do that, and how do I delete these files in the same line without making an unnecessary for loop for that? I'm using Debian Wheezy and bash scripts for this. 回答1: This will list all files except the newest three: ls -t | tail -n +4 This will delete those files: ls -t | tail -n +4 | xargs rm -- This will

List files recursively in Linux CLI with path relative to the current directory

情到浓时终转凉″ 提交于 2019-11-27 02:35:07
This is similar to this question , but I want to include the path relative to the current directory in unix. If I do the following: ls -LR | grep .txt It doesn't include the full paths. For example, I have the following directory structure: test1/file.txt test2/file1.txt test2/file2.txt The code above will return: file.txt file1.txt file2.txt How can I get it to include the paths relative to the current directory using standard Unix commands? Use find: find . -name \*.txt -print On systems that use GNU find, like most GNU/Linux distributions, you can leave out the -print. Stephen Irons Use