我想要一個dir的列表(每行一個項目)。但最後一個字符是一個 「/」沒有斜線的dirs「/」
ls /var/lib/mysql/ | grep -v "\."
這說明:
wachuwar_funkfow/
wachuwar_prueba/
webdeard_arde/
而且我想
wachuwar_funkfow
wachuwar_prueba
webdeard_arde
我會很感激幫助
我想要一個dir的列表(每行一個項目)。但最後一個字符是一個 「/」沒有斜線的dirs「/」
ls /var/lib/mysql/ | grep -v "\."
這說明:
wachuwar_funkfow/
wachuwar_prueba/
webdeard_arde/
而且我想
wachuwar_funkfow
wachuwar_prueba
webdeard_arde
我會很感激幫助
也許,您的ls
是別名或定義爲您的.bashrc
或/etc/profile
或其他地方的函數。
嘗試的完整路徑ls
像
/bin/ls /var/lib/mysql/
非常感謝。這是更好的解決方案,因爲向我展示另一個問題的別名... – abkrim 2012-01-28 10:22:35
這應該被標記爲答案... – 2016-06-21 10:10:10
您應該檢查你的別名ls
。例如,
$> alias ls
alias ls='ls --color=auto'
-F
標誌追加目錄指示器,所以你應該從你ls
別名中,如果你不需要它。
約一行一行。 ls
有可用-1
標誌,所以它應該就像
ls -1 /var/lib/mysql/
wachuwar_funkfow
wachuwar_prueba
webdeard_arde
,如果你有一個命令,這也是一個別名,你可以繞過別名,並直接與這些方法執行命令:
ls # runs the alias
command ls # runs the command
\ls # runs the command
爲了排除在他們的名字點文件,而不是使用grep -v
,你可以使用:
shopt -s extglob
\ls -d !(*.*)
反斜槓繞過別名,它是L- ikely類似的一個:
alias ls=ls -F
alias ls=ls -p
alias ls=ls --classify
alias ls=ls --file-type
alias ls=ls --indicator-style=WORD
其中 「WORD」 是slash
,file-type
或classify
之一。
也許你已經定義了ls
的別名。如果有幫助,請嘗試以下命令:
unalias ls
for dir in `ls -1 .`; do echo $dir; done
它看起來像您的'ls'命令是別名,因爲它通常不會顯示結尾斜槓。在你的bash提示符處輸入'alias'並告訴我們是否有一行看起來像'alias ls ='ls -F ...'' – voithos 2012-01-28 10:17:42