我尝试使用排序文件 sort -h
algorithms@algorithms:~$ ls -lh /boot | sort -h
drwxr-xr-x 5 root root 4.0K Dec 28 16:19 grub
-rw------- 1 root root 4.2M Dec 5 13:10 System.map-4.18.0-13-generic
-rw------- 1 root root 4.2M Nov 14 21:30 System.map-4.18.0-12-generic
-rw------- 1 root root 8.2M Dec 5 13:11 vmlinuz-4.18.0-13-generic
-rw------- 1 root root 8.2M Nov 14 21:50 vmlinuz-4.18.0-12-generic
-rw-r--r-- 1 root root 1.5M Nov 14 21:30 abi-4.18.0-12-generic
-rw-r--r-- 1 root root 179K Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 17 Nov 14 …Run Code Online (Sandbox Code Playgroud) 我正在运行 Ubuntu Bionic 并探索 Bash Refs。这是一个有趣但神秘的输出ls。这是shell的文件描述吗?
命令
ls /d*
Run Code Online (Sandbox Code Playgroud)
产出
autofs disk hidraw0 i2c-4 loop1 loop21 loop9 psaux sda5 stdout tty19 tty30 tty42 tty54 tty9 ttyS19 ttyS30 vcs vcsa6
block dri hidraw1 i2c-5 loop10 loop22 loop-control ptmx sda6 tty tty2 tty31 tty43 tty55 ttyprintk ttyS2 ttyS31 vcs1 vfio
bsg drm_dp_aux0 hidraw2 i2c-6 loop11 loop23 mapper ptp0 sg0 tty0 tty20 tty32 tty44 tty56 ttyS0 ttyS20 ttyS4 vcs2 vga_arbiter
btrfs-control drm_dp_aux1 hidraw3 i2c-7 loop12 loop24 mcelog pts sg1 tty1 tty21 …Run Code Online (Sandbox Code Playgroud) 如何递归地列出(ls)文件夹/目录的内容但深度仅为一个文件夹/目录?
我有以下文件夹结构:
folderA:
folderB1:
folderC1:
fileD1:
fileD2:
fileC2
fileC3
folderB2:
folderC4:
fileD3:
fileD4:
fileC5
fileC6
Run Code Online (Sandbox Code Playgroud)
我在 的父文件夹中,folderA并想列出其中的所有内容及其子文件夹,但不列出子文件夹。所以我想看看:
folderB1/folderC1
folderB1/fileC2
folderB1/fileC3
folderB2/folderC2
folderB2/fileC4
folderB2/fileC5
Run Code Online (Sandbox Code Playgroud)
那可能吗?目前,我使用ls -R folderA它让我陷入了数百个我不感兴趣的子文件夹的兔子洞。我想在某个深度停下来。理想情况下,会有一个选项,例如depth 1列出 folderA 及其子文件夹的内容并停止。
我正在使用 macOS X High Sierra。
我有许多文件夹,每个文件夹中都有音频文件。我想挑出每个文件的 30% 并将它们(不是复制)剪切到另一个文件夹。鉴于我知道每个文件夹中的文件数,我可以看到这篇文章可以帮助我做到这一点。可悲的是,数字可能会改变,我想要一个可以做到这一点的管道 bash 线。这可能吗?如何选择 30% 的文件并将它们剪切到另一个文件夹?
第一次和第二次调用是为了比较。这是我试图开始工作的第三次。
$ ls -a1 *mp3
DaftPunk_VeridisQuo.mp3
French79_AfterParty.mp3
French79_BetweentheButtons.mp3
French79_Hometown.mp3
$ find . -maxdepth 1 -type f -name '*mp3'
./French79_AfterParty.mp3
./French79_Hometown.mp3
./DaftPunk_VeridisQuo.mp3
./French79_BetweentheButtons.mp3
$ for x in "$(ls -a *mp3)"; do mv "./$x" "./electro_$x"; done
mv: cannot stat './DaftPunk_VeridisQuo.mp3'$'\n''French79_AfterParty.mp3'$'\n''French79_BetweentheButtons.mp3'$'\n''French79_Hometown.mp3': No such file or directory
Run Code Online (Sandbox Code Playgroud) 先看ls --help命令的输出:
输出中忽略了几行
-a, --all do not ignore entries starting with .
-l use a long listing format
Run Code Online (Sandbox Code Playgroud)
-a,-all应该是一样的-l标志,但-al帮助中没有,但此标志有效所以我的问题是:
-a和-all返回相同的输出,但说明显示他们都在同一条直线?-al旧形式,-all因为两者相同,但我没有找到手册-al. ..的ls -a输出?以上命令的输出包括如下:
ls -a :
. .. article.png bgame newtest
Run Code Online (Sandbox Code Playgroud)
ls -all :
total 32
drwxr-xr-x 4 shahab shahab 4096 Sep 19 12:15 .
drwxrwxr-x 33 shahab sudo 4096 Oct …Run Code Online (Sandbox Code Playgroud) 所以我使用了:
getent passwd $2 | awk -F: '{print "|Username: " $1 "\n|Password: " $2 "\n|Uid: " $3 "\n|Gid: " $4 "\n|Comment: " $5 "\n|Home: " $6 "\n|Shell: " $7 "\n"}'
Run Code Online (Sandbox Code Playgroud)
将用户信息输入到一个整洁的列表中。
我想对文件夹做同样的事情。我想要来自“ ls -l”命令的所有信息,但不是像测试块那样出现,我希望它逐个列出。
我可以使用一个awk命令,ls并且可以使用我之前使用的相同方法吗?
[xxx]$ mkdir dir{1..10}
[xxx]$ ls
dir1 dir10 dir2 dir3 dir4 dir5 dir6 dir7 dir8 dir9
Run Code Online (Sandbox Code Playgroud)
当我这样创建 10 个目录时,为什么 dir10 会出现在 dir1 之后?不应该是最后一个目录吗?
另外,如果我尝试以下命令:
[xxx]$ mkdir -v dir{1..10}
mkdir: created directory 'dir1'
mkdir: created directory 'dir2'
mkdir: created directory 'dir3'
mkdir: created directory 'dir4'
mkdir: created directory 'dir5'
mkdir: created directory 'dir6'
mkdir: created directory 'dir7'
mkdir: created directory 'dir8'
mkdir: created directory 'dir9'
mkdir: created directory 'dir10'
[xxx]$ ls
dir1 dir10 dir2 dir3 dir4 dir5 dir6 dir7 dir8 dir9
Run Code Online (Sandbox Code Playgroud)
似乎现在目录是以正确的顺序创建的,但是当我列出它们时,目录 …
我正在尝试.whl按以下方式捕获所有文件
ls -l /python/*.{whl,}
ls: cannot access /python/*.: No such file or directory
-rw-r--r-- 1 root root 23000 Jun 14 11:02 /python/argparse-1.4.0-py2.py3-none-any.whl
-rw-r--r-- 1 root root 154423 Jun 14 11:02 /python/certifi-2019.9.11-py2.py3-none-any.whl
-rw-r--r-- 1 root root 387834 Jun 14 11:02 /python/cffi-1.14.0-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r-- 1 root root 133356 Jun 14 11:02 /python/chardet-3.0.4-py2.py3-none-any.whl
-rw-r--r-- 1 root root 2728298 Jun 14 11:02 /python/cryptography-2.9.2-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r-- 1 root root 11223 Jun 14 11:02 /python/enum34-1.1.10-py2-none-any.whl
-rw-r--r-- 1 root root 58594 Jun 14 11:02 /python/idna-2.8-py2.py3-none-any.whl
-rw-r--r-- 1 …Run Code Online (Sandbox Code Playgroud) 目前我正在编写一个 bash 脚本,它应该按照创建日期的顺序循环遍历目录中的一些文件。为此,我使用(使用真实代码而不是echo):
for i in $(ls -tr)
do
echo $i
done
Run Code Online (Sandbox Code Playgroud)
大多数情况下都可以正常工作。
但是现在我发现了一种破坏脚本的文件类型:aha_-_a ()a.txt.
此文件名包含一个空格,后跟一个左括号“(”,这似乎会触发换行符。结果是:
aha_-_a
()a.txt
Run Code Online (Sandbox Code Playgroud)
但它应该是:
aha_-_a ()a.txt
Run Code Online (Sandbox Code Playgroud)
您知道如何获得所需的行为吗?