Monday, July 27, 2015

Useful Linux Command - with output redirection

This one has been around for a while but in case you have not come across (and in case I forget myself) here is another useful Linux command:

ls > textfile.txt

This is a simple way to get a list of files in a certain folder and rather than write them to the screen it writes them to a text file that could be used in another script perhaps.

The above command will create a simple list of the file names in a particular directory.

If would like more details on the files you can use

ls -l > textfile.txt

Added the  "-l" (the lowercase letter L) will produce a "long" list with the file details.

This could be used to create a spreadsheet where you could sort or filter the files for some other purpose.


No comments: