Redirection of command output — a scrollable alternative to |more

I’m sure many Linux people already know this, but I discovered it today and figured I’d keep it on hand for when I need it again (that’s what this blog is for, after all).  I knew it was possible to redirect output to a file using >, redirect input from a file using < and chain the output of one command as the input of another using | but I didn’t know it was possible to redirect the output of a command (or series of commands) using <(...) too.

I’m used to doing things like ls -lrt | more to page the results of a directory listing, for example, but as a Windows user, I’m too used to being able to scroll my terminal (or command prompt) output to go back and forward and you just can’t do that in a pure terminal like I have been dealing with recently.

Enter the <(...) construct:

vi <(ls -lrt)

Now the output of ls -lrt is redirected to the vi editor as some kind of pseudo-file.  I can page up and down to my heart’s content.

I also discovered the du and comm utilities today (told you I was new) and using a combination of all of them can now compare the size of folders under two separate parents:

vi <(comm <(cd /dir1; du .) <(cd /dir2; du .))

This changes the current directory to /dir1, spools the size of all subfolders to a pseudo-file, changes the current directory to /dir2, spools the size of all subfolders to another pseudo-file, spools the comparison of the two pseudo-files to a third pseudo-file and shows that file in vi, for me to look around.

Perfect for eyeballing the results of a local rsync.  It took a whole batch file to do the same last time I tried in Windows.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: