You are Here:
Download Linux Lite 5.6 Final today - See Release Announcements



X Close Ad
X Close Ad
Generating and saving *.txt files from command line orders output.

Author (Read 7935 times)

0 Members and 1 Guest are viewing this topic.

 

Moltke

  • Platinum Level Poster
  • **********
  • 1047
    Posts
  • Country: ve
  • Reputation: 120
  • Linux Lite Member

  • Linux Lite: 5.0 64bit

  • CPU: amd athlon 64 x2

  • MEMORY: 4Gb

  • VIDEO CARD: amd radeon hd 6750

  • Kernel: 5.x

Hi Everyone! Hope you're all having a nice life! I'm aware this might be no news but still. As the title states (title suggestions are welcome by the way ;) ) this post is about how to generate and save a *.txt file from command line orders output, and in case you wonder the resulting *.txt files will be saved in your home directory.  I'm pretty sure you've heard of histoy>history.txt which saves a text file containing all your bash history, but say you run:
$ cd music, which takes you to the music directory right? Now, wouldn't it be nice to save a list.txt file of all your audio files and anything else in this folder? I certainly think it is. All you have to do is:
music$sudo su
music$pass: your passwd
music$ ls
music$ ls>ls.txt which will generate and save a *.txt file with the contents of the directory.
why root you ask? well, not sure whether or not it has to do with *ls command or that you're working with directories but your non-root user has no permission to perform that action, I think it's harmless, but apparently you're not allowed unless root, maybe someone more experienced than me could explain the why.

I noticed that naming the resulting *.txt the same as the command line order, i.e pactl list cards>pactl list cards.txt won't work but  pactl list cards>pactllistcards.txt will. However, I  do suggest to use a command/output-related name so it's easier to search/find.
I won't explain what command does what. I'm assuming you already know this, if you don't a quick Google search will help, anyway, here are a few ones I tried:
df -h>df.txt
timedatectl>timedatectl.txt
sensors>sensors.txt 
lspci>lspci.txt
pactl list cards>pactllistcards.txt
top>top.txt  *I know, this one is probably useless like this,  but I thought of trying anyway, however, the *.txt file is quite not readable or at the very least I found it difficult to and you have to wait a couple of seconds for it to come with an output, otherwise you get a blank page, then do ctrl+c to stop so it saves the .txt file. 
uname -a>uname.txt
systemd-analyze>boottime.txt
systemd-analyze blame>blame.txt
glxinfo | grep -i render>glxinfo.txt
lsb_release -idc>lsbrelease.tx
printenv>var.txt
command info>info.txt
du -h>du.txt
lscpu>lscpu.txt
cat /proc/cpuinfo>cpuinfo.txt
sudo lshw>lshw.txt *sudo allows to gathers much more information.
lshw>lshw.txt *without the sudo command less information is gathered and you'll see a warning that it might be incomplete and that you should run the command with sudo instead.
sudo lshw -short>lshwshort.txt *same thing as the sudo lshw command above.
lshw -short>lshwshort1.txt *you know by now right? ;)
sudo fdisk -l>fdisk.txt
sudo dmidecode -t memory>dmidecodemem.txt
sudo dmidecode -t system>dmidecodesys.txt
sudo dmidecode -t bios>dmidecodebios.txt
sudo dmidecode -t processor>dmidecodeproc.txt
ifconfig>ifconfig.txt
netstat>netstat.txt
I think that there might be tools which are probably easier and better for this task, but I also think it is quite handy to have these *.txt files so you can compare changes from time to time as well as to keep a record on your files, directory contents as well as some valuable system's information in an easy-friendly approach.
I hope you find this information as useful as it is to me. If you happen to know more ways to take advantage of this handy procedure or better yet, improve it! Please, do share your valuable knowledge with your fellow Linux users ;)
Last Edit: October 03, 2017, 08:16:53 PM by Moltke
Without each others help there ain't no hope for us :)
Need a translation service? https://www.deepl.com/es/translator
 


Re: Generating and saving *.txt files from command line orders output.
« Reply #1 on: October 01, 2017, 04:19:31 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Country: 00
  • Reputation: 305
    • Try to Grow

  • Linux Lite: 3.2 64bit

  • Kernel: 4.x
Thanks Moltke :)
 

Re: Generating and saving *.txt files from command line orders output.
« Reply #2 on: October 03, 2017, 08:07:01 PM »
 

Moltke

  • Platinum Level Poster
  • **********
  • 1047
    Posts
  • Country: ve
  • Reputation: 120
  • Linux Lite Member

  • Linux Lite: 5.0 64bit

  • CPU: amd athlon 64 x2

  • MEMORY: 4Gb

  • VIDEO CARD: amd radeon hd 6750

  • Kernel: 5.x
 I thought of posting here but since it wasn't software related I wasn't sure at all. So, for future reference, any tutorials should go here in this section? Thanks.
Without each others help there ain't no hope for us :)
Need a translation service? https://www.deepl.com/es/translator
 

Re: Generating and saving *.txt files from command line orders output.
« Reply #3 on: October 04, 2017, 02:12:22 PM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Country: 00
  • Reputation: 305
    • Try to Grow

  • Linux Lite: 3.2 64bit

  • Kernel: 4.x
Yes tutorials go here.
This one could have also went in the Scripting and Bash section.
 

Re: Generating and saving *.txt files from command line orders output.
« Reply #4 on: October 07, 2017, 11:26:59 AM »
 

gold_finger

  • Documentation Writer
  • Platinum Level Poster
  • *****
  • 1094
    Posts
  • Country: us
  • Reputation: 325
  • Linux Lite Member

  • Linux Lite: 3.2 64bit

  • CPU: Intel Core2 Duo E7500 3.0GHz

  • MEMORY: 4Gb

  • VIDEO CARD: Intel 4 Series Integrated Graphics
Quote from: Moltke
why root you ask? well, not sure whether or not it has to do with *ls command or that you're working with directories but your non-root user has no permission to perform that action, I think it's harmless, but apparently you're not allowed unless root, maybe someone more experienced than me could explain the why.


There is no need to use sudo or su for the ls command.  When you do that you'll end up with problem that the generated file is owned by root instead of regular user.  Regular user will be able to read file, but won't be able to make changes or delete it without also being root.  Don't know why you experienced a problem with it.  Maybe you accidentally mis-typed something.  This should work without a problem as regular user:
Code: [Select]
ls > ls.txt


Also, if you want to get rid of the weird characters generated in output of that command (assuming directories may be part of the output) use this instead:
Code: [Select]
ls --color=never > ls.txt

The terminal colorizes directory listings to make them stand out from regular files.  If you generate a text file from command line above and the output contains directories, you'll see strange characters around those directory listings because text editor can't do colors.  For example, generate a text file listing contents of your Home directory, then open it with text editor to see what I'm talking about.
Code: [Select]
cd ~
ls > home.txt


Now do it again with the "--color=never" option.
Code: [Select]
ls --color=never > home.txt
Try Linux Beginner Search Engine for answers to Linux questions.
 

Re: Generating and saving *.txt files from command line orders output.
« Reply #5 on: October 07, 2017, 11:42:33 AM »
 

bitsnpcs

  • Platinum Level Poster
  • **********
  • 3237
    Posts
  • Country: 00
  • Reputation: 305
    • Try to Grow

  • Linux Lite: 3.2 64bit

  • Kernel: 4.x
@gold_finger very useful Thanks :)
 

Re: Generating and saving *.txt files from command line orders output.
« Reply #6 on: October 08, 2017, 10:32:19 PM »
 

Moltke

  • Platinum Level Poster
  • **********
  • 1047
    Posts
  • Country: ve
  • Reputation: 120
  • Linux Lite Member

  • Linux Lite: 5.0 64bit

  • CPU: amd athlon 64 x2

  • MEMORY: 4Gb

  • VIDEO CARD: amd radeon hd 6750

  • Kernel: 5.x
Quote from: Moltke
why root you ask? well, not sure whether or not it has to do with *ls command or that you're working with directories but your non-root user has no permission to perform that action, I think it's harmless, but apparently you're not allowed unless root, maybe someone more experienced than me could explain the why.


There is no need to use sudo or su for the ls command.  When you do that you'll end up with problem that the generated file is owned by root instead of regular user.  Regular user will be able to read file, but won't be able to make changes or delete it without also being root.  Don't know why you experienced a problem with it.  Maybe you accidentally mis-typed something.  This should work without a problem as regular user:
Code: [Select]
ls > ls.txt


Also, if you want to get rid of the weird characters generated in output of that command (assuming directories may be part of the output) use this instead:
Code: [Select]
ls --color=never > ls.txt

The terminal colorizes directory listings to make them stand out from regular files.  If you generate a text file from command line above and the output contains directories, you'll see strange characters around those directory listings because text editor can't do colors.  For example, generate a text file listing contents of your Home directory, then open it with text editor to see what I'm talking about.
Code: [Select]
cd ~
ls > home.txt


Now do it again with the "--color=never" option.
Code: [Select]
ls --color=never > home.txt
Hi @gold_finger
Thanks! This is very helpful! I tried ls command again and it worked without asking for root..weird, cause the first time I tried I had to run sudo ls for it to work, but now I didn't have to, have no idea why though. The --color=never option is great too. Thanks again!
Without each others help there ain't no hope for us :)
Need a translation service? https://www.deepl.com/es/translator
 


Tags: *.txt command output. 
 

X Close Ad
X Close Ad

Download Linux Lite 5.6 Final today - See Release Announcements