GIDForums  

Go Back   GIDForums > Computer Forums > Computer Software Forum - Linux
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 19-Oct-2008, 09:54
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 845
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Use ls command without showing permissions


Hi, file names get long and it's nice to reduce the left side of ls -l printout. 'man ls' shows me I can:
Code:
ls -go -no group, no owner. ls -got -no group, no owner, sort by time (ascending) ls -gotr -no group, no owner, sort by time descending (r= reverse sort) eg: $ ls -gotr total 488 -rwxr-xr-x 1 5979 Sep 8 22:32 panel_x-1.0 -rw-r--r-- 1 1066 Sep 8 22:40 panel_x-1.0.c -rwxr-xr-x 1 8557 Sep 8 22:42 panel_x-2.0 -rw-r--r-- 1 3545 Sep 8 22:55 panel_x-2.0.c -rw-r--r-- 1 3801 Sep 9 08:51 books_curses_cpp-1.0.cpp.bak
But I'd like to dump the permissions too.
Anybody know how?
  #2  
Old 20-Oct-2008, 00:03
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 845
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Use ls command without showing permissions


I have been enlightened to two methods so far:

ls -latr | awk '{printf("%7s %s %2s %5s %s\\n",\$5,\$6,\$7,\$8,\$9)}'";
and
ls -got | cut -b 1,13-128

and I made shell script to use it as 'myls' which works for my pwd:
Code:
#!/bin/sh echo " ~/bin/myls custom ls command 20081028"; echo "man ls , awk , or cut for more info, but:" echo " -g nogroup, -o noowner, -t sort by time(ascending), -r reverse order"; echo "Was using: ls -latr | awk '{printf("%7s %s %2s %5s %s\\n",\$5,\$6,\$7,\$8,\$9)}'"; echo "Now using: ls -got | cut -b 1,13-128 " ; echo "Listing of: $(pwd):" ls -got | cut -b 1,13-128
  #3  
Old 07-Nov-2008, 21:07
TurboPT's Avatar
TurboPT TurboPT is online now
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,234
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Use ls command without showing permissions


Hey Howard,

Here's another way to "reduce the left": (similar to one of your others -- but no sorting/reversing in this snippet)
Code:
[root@localhost ~]# ll // <<--- aliased as ls -l on my system. total 128 -rw------- 1 root root 1092 Jul 7 2006 anaconda-ks.cfg drwxr-xr-x 4 root root 4096 Oct 27 23:12 Desktop -rw-r--r-- 1 root root 24050 Jan 13 2008 EcllipseConfig -rw-r--r-- 1 root root 44248 Jul 7 2006 install.log -rw-r--r-- 1 root root 5242 Jul 7 2006 install.log.syslog -rw------- 1 root root 1645 Nov 6 21:58 mbox -rw-r--r-- 1 root root 706 Sep 22 23:24 test.php drwxr-xr-x 5 root root 4096 Feb 3 2007 workspace [root@localhost ~]# ll | awk 'BEGIN{OFS="\t"}{print $5,$6,$7,$8,$9}' 1092 Jul 7 2006 anaconda-ks.cfg 4096 Oct 27 23:12 Desktop 24050 Jan 13 2008 EcllipseConfig 44248 Jul 7 2006 install.log 5242 Jul 7 2006 install.log.syslog 1645 Nov 6 21:58 mbox 706 Sep 22 23:24 test.php 4096 Feb 3 2007 workspace
OFS in the BEGIN block of the awk command implies: (O)utput (F)ield (S)eparator.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
  #4  
Old 09-Nov-2008, 08:35
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 845
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Use ls command without showing permissions


linux tools like awk are so cool...
You know these are available 'standalone' for the msdos console as well.
But how to get the first character of $1.... for directory (or file)
That's why I've ended up using this so far:
Code:
----- ~/bin/myls ----- #!/bin/sh echo "Listing of: $(pwd):" ls -got | cut -b 1,13-128 ----- out: ----- Listing of: /mnt/e/ccpl: t d 4096 Nov 8 09:24 cgi-bin d 4096 Nov 5 10:47 sandbox - 518 Nov 4 19:11 index.html
  #5  
Old 09-Nov-2008, 11:19
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Use ls command without showing permissions


Quote:
Originally Posted by Howard_L
...But how to get the first character of $1...

First of all: If you have a way that works for you: Rejoice.

On the other hand, if you want to investigate awk a little more, you could check out awk's printf. It's a lot like printf() for C

So, you could try something like:

Code:
ls -l | awk '{printf("%c %10s %3s %2s %5s %s\n", $1,$5,$6,$7,$8,$9)}'

See? The "%c" for the first field just prints the first character of the field.

Adjust the %s field widths to give it the look that you like.

Left as an exercise for the student: The first line of my "ls -l" is "total xxxxx", which results in a line with the single character 't' as the first line of the output when I run that awk script.

Your assignment:

Either
1. Get rid of that line in the awk output

or, better

2. Print the line exactly as ls -l gives it to you.

Regards,

Dave

Footnote: What if some of your file names had spaces as part of their names?

"I pity the fool..."
---Mr. T
Last edited by davekw7x : 09-Nov-2008 at 12:23.
  #6  
Old 09-Nov-2008, 18:13
TurboPT's Avatar
TurboPT TurboPT is online now
Senior Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 1,234
TurboPT is a jewel in the roughTurboPT is a jewel in the roughTurboPT is a jewel in the rough

Re: Use ls command without showing permissions


Quote:
Originally Posted by Howard_L
But how to get the first character of $1.... for directory (or file)
...alternatively, the -F option with ls command will append a slash to the end of a name that is a directory. See this:
Code:
[root@localhost ~]# ls -lF | awk 'BEGIN{OFS="\t"}{print $5,$6,$7,$8,$9}' 1092 Jul 7 2006 anaconda-ks.cfg 4096 Oct 27 23:12 Desktop/ 24050 Jan 13 2008 EcllipseConfig 44248 Jul 7 2006 install.log 5242 Jul 7 2006 install.log.syslog 1645 Nov 6 21:58 mbox 706 Sep 22 23:24 test.php 4096 Feb 3 2007 workspace/
EDIT:
As Dave pointed out though, this example (and the previous post) falls short if a filename contains spaces.
__________________
Use the force...read the source!!
WYCIWYG -- what you code is what you get!
Last edited by TurboPT : 09-Nov-2008 at 19:11.
  #7  
Old 15-Nov-2008, 19:24
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 845
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Use ls command without showing permissions


I had left this tab open on my browser to make a point of getting back to it.
yes I have not needed to reboot for a week or so in fact:
Code:
$ uptime 21:20:13 up 30 days, 9:16, 1 user, load average: 0.27, 0.18, 0.09
That's with all four virtual windows going with two or three xterms open in each plus etc etc...
(as opposed to the XP box which slows to a crawl after a couple of days)
...anyhow man awk is overwhelming, I see this:vectorsite.net/tsawk.html
and am quickly clued to do this:
Code:
$ echo " pwd: `pwd`" && ls -l | awk \!'/total/ {printf("%c %10s %3s %2s %5s %s\n", $1,$5,$6,$7,$8,$9)}' pwd: /var/www/cgi-bin - 638 Nov 13 22:26 hello-1.pl - 764 Nov 14 10:38 hello-2.pl - 1474 Nov 14 15:52 hello.pl
cool dude...
%10s dave? you must have some big files on there!
Last edited by Howard_L : 15-Nov-2008 at 20:26.
  #8  
Old 15-Nov-2008, 21:17
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Use ls command without showing permissions


Quote:
Originally Posted by Howard_L
Code:
$ echo " pwd: `pwd`" && ls -l | awk \!'/total/ {printf("%c %10s %3s %2s %5s %s\n", $1,$5,$6,$7,$8,$9)}'

But what if one of your files had the string "total" as part of its name?

If you don't want it to print the first line (record) you could make the awk part look like
Code:
awk 'NR>1 {printf("%c %10s %3s %2s %5s %s\n", $1,$5,$6,$7,$8,$9)}'

Regards,

Dave
  #9  
Old 15-Nov-2008, 23:50
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 845
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Use ls command without showing permissions


Right dave, I'd thought about that and thought a $1 != kindof thing might work and find that this does:
Code:
$ ls -la | awk '{if(! match($1 , /^total$/)) printf("%c %10s %3s %2s %5s %s\n", $1,$5,$6,$7,$8,$9)}' d 4096 Nov 16 01:49 . d 4096 Nov 16 01:05 .. - 1509 Nov 16 00:57 awk_notes - 450 Nov 15 20:34 coins.txt d 4096 Nov 16 01:49 total_mess
...but your NR method is much cleaner... The man pages are becoming more clear to me now.
Now I'm looking at those dot directories . hmmm $9 something...
  #10  
Old 16-Nov-2008, 08:33
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,305
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Use ls command without showing permissions


Quote:
Originally Posted by Howard_L
...
Now I'm looking at those dot directories . hmmm $9 something...

This is where your C programming experience can be useful. Maybe the conditional can be something like
Code:
{if ((NR > 1) && ($9 != "." ) && ($9 != "..")) do_some_stuff}

IWFM---YMMV

Regards,

Dave
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hangman and showing correct letters Krandygrl00 C++ Forum 2 20-Mar-2006 13:18
Showing Error as Permission Denied kazim123 Apache Web Server Forum 0 03-Aug-2005 04:32
Image Not Showing hemanth.balaji MS Visual C++ / MFC Forum 2 12-Jun-2005 16:02
Help build the "Member Usergroups, Promotions and Permissions FAQ" JdS GIDForums™ 4 01-Feb-2004 00:58

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 06:24.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.