This might be the solution you are searching for. Let me explain more about what I meant by the title.
We all know the famous Linux command given below which lists all the files and subfolders in a directory along with the details.
ls -l
This command output contains many details like permission, ownership, size etc.
Now, it turns out that you just need all the file names and corresponding permissions. You want them in a text file to do some subsequent tasks. That's where my blog post comes in, how can you filter the output of a Linux command?
I will use the awk
command as shown. awk
will accept data from standard input, work on it and send it out via standard output.
Here the output of the ls -l
command is fed to the awk
command using the pipe |
command. The '{print $1,$9}'
part will print the first and ninth columns. You can also use a file as the input for awk
command as shown below.
awk '<command>' <input file path>
If you want to save the output of a command to a text file you can do it by using the >>
operator