LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-13-2011, 03:10 PM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,375
Blog Entries: 30

Rep: Reputation: 163Reputation: 163
column alignment in "ls -l" command


Is there a way to get the "ls -l" command to align its columns (e.g. force a fixed size) when the command is executed individually for each file to be listed (e.g. in a script loop or such)? Right now, I get ragged/jagged columns because "ls -l" is trying to make each listing compact horizontally. But as file sizes, and lengths of owner names, and such vary, the overall length of each output instance varies, making the columns ragged.
 
Old 03-13-2011, 03:25 PM   #2
LionOfGod
LQ Newbie
 
Registered: Mar 2011
Location: Ontario
Posts: 26

Rep: Reputation: 0
Im no pro, but cant you just pipe it?
Code:
ls -l | less
Or something like that??
EDIT
sorry im an idiot, of course that wont work X|
EDIT
Why dont you open up vi, or a text editor, and run the command from their? that way you can scroll to the sides

Last edited by LionOfGod; 03-13-2011 at 03:31 PM.
 
Old 03-13-2011, 03:54 PM   #3
jsteel
Member
 
Registered: Mar 2007
Location: England
Distribution: Arch
Posts: 392

Rep: Reputation: 34
Is an "ls -1" (that's a "one") which will list everything in one column a solution? Or do you need the other information that is provided by "ls -l"?
 
Old 03-13-2011, 04:20 PM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 259Reputation: 259Reputation: 259
You could use the output of ls -lh by printf to reformat it:
Code:
$ printf "%9s %9s %9s %9s %9s %9s %9s %9s\n" $(ls -l foobar)
(adjust to your needs). I would use awk to process the output of ls -l, as then it's known to be $1..$8.
 
1 members found this post helpful.
Old 03-13-2011, 04:36 PM   #5
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,375

Original Poster
Blog Entries: 30

Rep: Reputation: 163Reputation: 163
Quote:
Originally Posted by LionOfGod View Post
Im no pro, but cant you just pipe it?
Code:
ls -l | less
Or something like that??
EDIT
sorry im an idiot, of course that wont work X|
EDIT
Why dont you open up vi, or a text editor, and run the command from their? that way you can scroll to the sides
The command is being run from inside a script, once per file, as the script processes files.

Quote:
Originally Posted by jsteel View Post
Is an "ls -1" (that's a "one") which will list everything in one column a solution? Or do you need the other information that is provided by "ls -l"?
I need the other information, which is why I'm doing "ls -l" (actually, "ls -dGil" for the script I'm editing on today, but there are others).

Quote:
Originally Posted by Reuti View Post
You could use the output of ls -lh by printf to reformat it:
Code:
$ printf "%9s %9s %9s %9s %9s %9s %9s %9s\n" $(ls -l foobar)
(adjust to your needs). I would use awk to process the output of ls -l, as then it's known to be $1..$8.
That might work. I'll give both ways a try. As long as the format "ls -l" uses stays constant, then $1..$8 or whatever should be consistent. Someone on IRC also suggested formatting with the find command and -printf.
 
Old 04-08-2011, 08:58 AM   #6
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,375

Original Poster
Blog Entries: 30

Rep: Reputation: 163Reputation: 163
The ultimate solution when listing one file at a time, is to use "find" with fixed -printf formatting, instead of "ls". It is more complex, but more powerful. This is more useful in a script than as a manually typed command. Be sure to use "-maxdepth 0" if what you list could include directories and you don't want the while directory tree to be recursed through.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 08:54 AM
ns:"error when calling class OldSim"&tclsh:"invalid command+child process exits abn." shojaru Linux - Newbie 0 03-05-2009 05:23 AM
Collection Values of "ps" command CPU column scbops Programming 13 01-07-2009 02:50 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
Viewing 132 column using "less" command kvvkumar Linux - Software 2 05-11-2007 11:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration