LIst dirs without trailing slash "/"

I need a list (one item per line) of the directory. But the last character is "/"

ls /var/lib/mysql/ | grep -v "\." 

It shows:

  wachuwar_funkfow/ wachuwar_prueba/ webdeard_arde/ 

And I would like

  wachuwar_funkfow wachuwar_prueba webdeard_arde 

I would be grateful for the help

+7
source share
6 answers

Maybe your ls alias is either defined as a function in .bashrc or /etc/profile or elsewhere.

Try the full path to ls , for example

 /bin/ls /var/lib/mysql/ 
+10
source

You should check your aliases for ls . For instance,

 $> alias ls alias ls='ls --color=auto' 

-F flag adds a directory indicator, so you should remove it from your ls aliases if you don't need one.

About one item per line. ls have a valid -1 flag, so it should work like

 ls -1 /var/lib/mysql/ wachuwar_funkfow wachuwar_prueba webdeard_arde 
+4
source
 ls /var/lib/mysql/ | grep -v "\." | sed 's/\/$//' 

Recent sed commands look for a line that has a / ending (which is flushed back) and replaces it with an empty line.

+3
source

Perhaps you have defined an alias for ls that does this.

To start ls directly, run as \ls , for example

 \ls /var/lib/mysql/ 

To see what the alias is added to, run: type ls .

If so, remove the alias with:

 unalias ls 

Otherwise, here is a workaround:

 for dir in 'ls -1 .'; do echo $dir; done 
+3
source

if you have a command that is also an alias, you can bypass the alias and execute the command directly using these methods:

 ls # runs the alias command ls # runs the command \ls # runs the command 
+1
source

To exclude files with a dot in their name, instead of using grep -v you can use:

 shopt -s extglob \ls -d !(*.*) 

The backslash bypasses the alias, which is likely similar to one of:

 alias ls=ls -F alias ls=ls -p alias ls=ls --classify alias ls=ls --file-type alias ls=ls --indicator-style=WORD 

Where "WORD" is one of slash , file-type or classify .

+1
source

Source: https://habr.com/ru/post/1393495/


All Articles