Advertisement
andmalv

[Tip] Listar y enumerar archivos

Mar 28th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.44 KB | None | 0 0
  1. # En este caso, listará y enumerá los usuarios del Sistema.
  2.  
  3. # Con nl
  4.    
  5.     cut -d ':' -f 1 /etc/passwd | nl
  6.  
  7. # Con cat
  8.  
  9.     cut -d ':' -f 1 /etc/passwd | cat -n
  10.  
  11. # Con grep
  12.  
  13.     grep -noE '^[^:]+' /etc/passwd
  14.  
  15. # Con while
  16.  
  17.     i=1
  18.     while read User; do
  19.         echo -e "\t $[i++]: $User"
  20.     done < <(cut -d ':' -f 1 '/etc/passwd')
  21.  
  22. # Con for
  23.  
  24.     i=1
  25.     for User in $( cut -d ':' -f 1  '/etc/passwd' ); do
  26.         echo -e "\t $[i++]: $User"
  27.     done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement