ls

Preserve ls colouring after grep'ing

℡╲_俬逩灬. 提交于 2019-11-27 00:55:28
问题 If I do $ ls -l --color=always I get a list of files inside the directory with some nice colouring for different file types etc.. Now, I want to be able to pipe the coloured output of ls through grep to filter out some files I don't need. The key is that I still want to preserve the colouring after the grep filter. $ ls -l --color=always | grep -E some_regex ^ I lose the colouring after grep EDIT: I'm using headless-server Ubuntu 8.10, Bash 3.2.39, pretty much a stock install with no fancy

List files not matching a pattern?

谁都会走 提交于 2019-11-26 22:22:00
Here's how one might list all files matching a pattern in bash: ls *.jar How to list the complement of a pattern? i.e. all files not matching *.jar? ls | grep -v '\.jar$' for instance. Christian Use egrep-style extended pattern matching. ls !(*.jar) This is available starting with bash-2.02-alpha1. Must first be enabled with shopt -s extglob As of bash-4.1-alpha there is a config option to enable this by default. Little known bash expansion rule: ls !(*.jar) POSIX defines non-matching bracket expressions, so we can let the shell expand the file names for us. ls *[!j][!a][!r] This has some

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

一世执手 提交于 2019-11-26 22:18:55
问题 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. 回答1: If you really want to use ls , then format

Sort files numerically in bash

人盡茶涼 提交于 2019-11-26 20:59:03
问题 I need to sort .flv files numerically and i was able to do it with the following command: ls *\.flv | sort --version-sort -f but with many files(hundreds) it's not sorting correctly. ls *\.flv | sort --version-sort -f | tail -n 20 e680.flv e681.flv e682.flv e683.flv e684.flv e685.flv e686.flv e687.flv e688.flv e689.flv e690.flv e691.flv e692.flv e693.flv e694.flv e695.flv **e696.flv** s572.flv s602.flv s654.flv but the strange this is, if i'm ruining the command without "*.flv" it's working.

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

允我心安 提交于 2019-11-26 18:35:16
问题 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/\

Listing only directories using ls in bash: An examination

折月煮酒 提交于 2019-11-26 18:02:30
This command lists directories in the current path: ls -d */ What exactly does the pattern */ do? And how can we give the absolute path in the above command (e.g. ls -d /home/alice/Documents ) for listing only directories in that path? */ is a pattern that matches all of the subdirectories in the current directory ( * would match all files and subdirectories; the / restricts it to directories). Similarly, to list all subdirectories under /home/alice/Documents, use ls -d /home/alice/Documents/*/ Albert Four ways to get this done, each with a different output format 1. Using echo Example: echo *

Regular Expression usage with ls

戏子无情 提交于 2019-11-26 12:43:51
问题 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 . 回答1: You are confusing regular expression with shell globbing. If you want to use regular expression to match file names you could do: $ ls | egrep '.+\..+' 回答2: You don't say what shell you are using, but they

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

瘦欲@ 提交于 2019-11-26 12:34:51
问题 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? 回答1: Use find: find . -name \*.txt -print On

how can i show the size of files in /proc? it should not be size zero

≯℡__Kan透↙ 提交于 2019-11-26 10:57:05
from the following message, we know that there are two characters in file /proc/sys/net/ipv4/ip_forward, but why ls just showed this file is of size zero? i know this is not a file on disk, but a file in the memory, so is there any command which i can see the real size of the files in /proc? root@OpenWrt:/proc/sys/net/ipv4# cat ip_forward | wc -c 2 root@OpenWrt:/proc/sys/net/ipv4# ls -l ip_forward -rw-r--r-- 1 root root 0 Sep 3 00:20 ip_forward root@OpenWrt:/proc/sys/net/ipv4# pwd /proc/sys/net/ipv4 Those are not really files on disk (as you mention) but they are also not files in memory - the

How to get file creation date/time in Bash/Debian?

☆樱花仙子☆ 提交于 2019-11-26 09:22:16
问题 I\'m using Bash on Debian GNU/Linux 6.0. Is it possible to get the file creation date/time? Not the modification date/time. ls -lh a.txt and stat -c %y a.txt both only give the modification time. 回答1: Unfortunately your quest won't be possible in general, as there are only 3 distinct time values stored for each of your files as defined by the POSIX standard (see Base Definitions section 4.8 File Times Update) Each file has three distinct associated timestamps: the time of last data access,