This question already has answers here:
Reusing output from last command in Bash
(14 answers)
Using output of previous commands in bash
(5 answers)
Reference stdout (i.e. output of previous command) quickly in bash?
(2 answers)
Closed 5 years ago.
Is there any way to print the last printed lines on a linux terminal? I'm trying to run a command that does that on my node app so that i can parse that content. Is all the shell content logged in a file, or something like that?
I want to echo the console own content. Get the last outputs of the own terminal.
I dont want command outputs I want to get console.logs() and console.errs()
You need to save it by urself. There are history option for Command you used but not for output unless it has been saved by other program in case of error.
You can use top command. It tells a lot much information regarding the system. You can use ps command and get the information about running processes and then use cat command to store that output in some other file or you can even use pipeline symbol to redirect its output to some file.
Related
This question already has answers here:
How do I run a Perl script from within a Perl script?
(9 answers)
Closed 4 years ago.
Within Linux I would like Perl script A to launch Perl script B. However, I want script A to continue running without waiting for script B to return. And I would like B to be totally independent so that when script A ends, script B is still running.
Is this possible?
You can append an & sign at the end of your second script launch like this:
system("/script/myscript.sh $params &");
or
If your running one of this distros that won't let that work you'll have to use fork
or
Proc::Background
This question already has answers here:
How do I execute a program or call a system command?
(65 answers)
Closed 5 years ago.
There are mainly two questions that I would like to ask, thanks in advance.
(1) How can I open an external program in Linux?
I know in Windows there is a command os.startfile() to open another program, the equivalent for Ubuntu is open(), but there's no response after I run the code, and the alternative one is subprocess.call(). This works well in Windows, but in Ubuntu it fails, could someone provide a standard templete I can use for? (Similarly like to double click the icon of a program)
(2) How can I realize functions like the code is able to open the terminal and write down several commands in terminal automatically using python?
os.system can do this work. for example, you want to run 'ls' under a shell. want_run='ls';os.system('bash -c '+ want_run);
(1)
You can use proc = subprocess.Popen(command, stdout=subprocess.PIPE) and afterwards run proc.stdout.read() to get the output of the command run.
See the subprocess documentation https://docs.python.org/2/library/subprocess.html
(2)
Please provide more info on this question(examples) for what you want to do.
This question already has answers here:
Working with huge files in VIM
(10 answers)
How to edit multi-gigabyte text files? Vim doesn't work =( [closed]
(15 answers)
Closed 6 years ago.
I have a db dump file that is over 5 gigs in size and I'm looking to do a quick edit to the create database and use database command. This dump is provided to me.
I've been using vim to do this from the command line, but it takes a while to load. I'm able to use less to read very quickly. Is there a way to edit the file without having to wait several minutes for the full file to load in vim? This can be a param passed to vim, or different common way to edit files from command line.
I'm looking for a general solution that I can apply to other large files too, so would like a linux command that would allow me to edit the top of the file quickly.
You can use cat:
cat file_with_create_cmd db_dump > new_dump
If you want to use that in a subsequent command instead of writing it to a file, you may use process substitution:
process_dump <(cat file_with_create_cmd db_dump)
This question already has answers here:
Get current directory or folder name (without the full path)
(24 answers)
Closed 7 years ago.
So long story short I have to make a Shell Script where I need to have something like two variables, the first one contains a path read from the keyboard (something like:this/is/the/path/I/need)
I really need to extract the last folder of that path example, and put it in another variable, in my example I need to get out of the path the "need" part and put it in the second variable. How can I do this? The fact that this is read from the keyboard makes it pretty hard to do in my opinion. Thanks!
$ read path
this/is/the/path/I/need
$ directory=$(basename $path)
$ echo $directory
need
$
This question already has answers here:
In linux, how can I test whether the output of a program is going to a live terminal or to a file?
(4 answers)
Closed 8 years ago.
When we using the ls, when can see some output has different colors not the default black colors, so i believe the output should add some escape sequence to adjust the color of the terminal, but when using ls > ls.log, in the ls.log we can not see the escape sequence,so the program need to decide whether the output is a file or terminal if it is the terminal it will the using terminfo to print out the result otherwise it only print out the real result without the escape sequence!
are there any APIs we can use to decide the things i mentioned before the STD out is terminal or normal files. if there are no APIs, what should we do to find the truth!
On Linux, programs are using the glibc function isatty() to decide whether stdout is a terminal or not:
if(isatty(1)) {
printf("stdout is a terminal");
}
See man 3 isatty.