ls

Listing only directories using ls in bash: An examination

狂风中的少年 提交于 2019-11-26 08:54:29
问题 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? 回答1: */ 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

How can I generate a list of files with their absolute path in Linux?

a 夏天 提交于 2019-11-26 08:38:37
问题 I am writing a shell script that takes file paths as input. For this reason, I need to generate recursive file listings with full paths. For example, the file bar has the path: /home/ken/foo/bar but, as far as I can see, both ls and find only give relative path listings: ./foo/bar (from the folder ken) It seems like an obvious requirement, but I can\'t see anything in the find or ls man pages. How can I generate a list of files in the shell including their absolute paths? 回答1: If you give

List files not matching a pattern?

走远了吗. 提交于 2019-11-26 08:17:06
问题 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? 回答1: ls | grep -v '\.jar$' for instance. 回答2: 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. 回答3: Little known bash expansion rule: ls !(*.jar) 回答4: POSIX defines non

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

家住魔仙堡 提交于 2019-11-26 03:28:45
问题 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