date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,592,644,129,000 |
I think this would best be done with AWK, but not sure. Its been stumping me all day how to do this. I have a text file with * delimiters between the fields on the lines. I need to search for lines beginning with L11*1Z and save the value to a variable or buffer starting with 1Z up to but not including the next * (... |
Assuming there's a BGN after each L11*1Z, then you should be able to use
$ awk 'BEGIN{OFS=FS="*"} /^L11\*1Z/ {x = $2} /^BGN/ {$3 = x} 1' file
xxx
L11*123456*CR
yyy
L11*1ZXDF430*2I*04
zzz
BGN*00*1ZXDF430*123456
fff
L11*768907*CR
L11*12345678*CR
xxx
L11*1ZXDF499*2I*04
zzz
BGN*00*1ZXDF499*123456
xxx
| Text file: find string, save string field to var, find 2nd string, replace field with var, repeat to end |
1,592,644,129,000 |
I have files in the following manner
ar01440_1775_17_vc00_00.png
ar01440_1775_17_vc00_01.png
ar01440_1775_17_vc00_02.png
ar01440_1775_17_vc00_03.png
ar01440_1775_17_vc00_04.png
ar01440_1775_17_vc00_05.png
ar01440_1775_17_vc00_06.png
ar01440_1775_17_vc00_07.png
ar01440_1775_17_vc00_08.png
ar01440_1775_17_vc00_09.png
a... |
Using the 'en_US.UTF-8' locale caused the the '010' to appear before '01' when sorting. Forcing the C locale for the sort works here:
$ LC_ALL=C ls -1
ar01440_1775_17_vc00_00.png
ar01440_1775_17_vc00_01.png
ar01440_1775_17_vc00_010.png
ar01440_1775_17_vc00_011.png
ar01440_1775_17_vc00_012.png
ar01440_1775_17_vc00_013.... | How to sort files in unix |
1,592,644,129,000 |
I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.
I used following command with backticks:
mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`
So I wanted to move the source of command in backticks to the destination directory which is 'd... |
You will notice that ls -R outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3 in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R (on the same line as the filename). This makes you... | mv: cannot stat 'filename_1_2_3': No such file or directory |
1,592,644,129,000 |
I have file which I want to extract and rearrange certain data , Old file contains a raw data this file is Input
reference:cve,2017-8962
sid:45885
reference:cve,2016-10033
reference:cve,2016-10034
reference:cve,2016-10045
reference:cve,2016-10074
sid:45917
reference:cve,2017-8046
sid:45976
reference:cve,2018-6577
ref... |
As you seem to use post-ponned sid:s (multipe references: followed by their single sids: => pairs of references: and sid:), two solution.
Solution 1 : reversing
Simple use the tac command (it's cat in the reverse order) to reverse the input and the output : tac input | awk | tac > output
For awk part, just duplicate ... | Extract and rearrange from file |
1,592,644,129,000 |
A HDD, which is older than 10 years, is getting read using a SATA-to-USB adapter.
When using sudo hdparm -y /dev/sdj, the HDD does not shut down.
But when using the Eject option in the File Manager, the HDD stops rotating.Side fact: The eject option in Microsoft Windows does shut the HDD down as well.
Why does hdparm ... |
The hdparm command only does one thing, namely issuing a specific ATA command which tells the drive to transition to a standby state. This doesn't prevent anything from immediately waking up the drive with a new command however so depending on the drive itself, it may not even try to spin down (the smart ones wait a... | Why does hdparm -y not spin down a HDD while the file managed does? (using Ejection option) |
1,592,644,129,000 |
I have removed the guest account from the command-line using the command
sudo sh -c 'printf "[Seat:*]\nallow-guest=false\n" >/etc/lightdm/lightdm.conf.d/50-no-guest.conf'
How can I restore the guest account?
|
Just remove config file which you created before:
sudo rm /etc/lightdm/lightdm.conf.d/50-no-guest.conf
| How to restore the guest account in Ubuntu 18.04.1 LTS Bionic Beaver? |
1,592,644,129,000 |
I have many text files prepended with digits like this:
12 some text here
some text here
some text here
Or sometimes like this:
123 text here
some more not-so-interesting text here
some text here
even more not-so-interesting text here
And I need them to appear like so:
12
some text here
some text here
some text ... |
Just remember the number and replace the space after it with a newline:
sed 's/^\([0-9][0-9]*\) /\1\n/'
If your sed supports it, you can use an extended regex to improve readability:
sed -E 's/^([0-9]+) /\1\n/'
[0-9] matches a digit
* means "zero or more times"
+ means "at least once"
\(...\) or (...) create a "cap... | sed/awk file data manipulation |
1,592,644,129,000 |
When I analyze the output from Racon, which I got on GitHub, it has dynamic "animated" text as the output from the STDERR.
For example, when I cat the file, it looks like this:
[racon::Polisher::initialize] aligned overlap 624/2265116
The text then "animates" and overwrites itself to say the next number:
[racon::P... |
It might be sufficient to just remove carriage return ( <CR> / ^M / 0x0D / \r) chars (unless we get more info on the input). Pipe it through
tr -d $'\r'
| How to convert "animated" text in a document to static text? [duplicate] |
1,533,751,823,000 |
I want to use a time command in a script and put it into a variable (I will have to use it for many commands) so than I can modify just the single variable.
Simplified, this is how I tried it:
PROFILING="/usr/bin/time -f 'time: %e - cpu: %P'" ; $PROFILING ls /usr
I would expect that to be translated into:
# /usr/bin... |
Word splitting doesn't understand quotes in the expanded variables. Use an array instead:
profiling=(/usr/bin/time -f 'time: %e - cpu: %P')
"${profiling[@]}" ls /usr
Or alias:
shopt -s expand_aliases # needed in scripts
alias profiling="/usr/bin/time -f 'time: %e - cpu: %P'"
profiling ls /usr
Or function:
profiling(... | bash variable with quotes and percentage [duplicate] |
1,533,751,823,000 |
I am looking into the nohup command and I am not sure which shells it support. It seems as if this program works differently in bash and tcsh. What I tried was something very simple.
nohup --help
When I start it from bash it works just fine, but for tcsh is says,
--help: Command not found.
This does definitely not ... |
When in bash, using nohup will use the external utility nohup. The GNU coreutils' version of nohup does indeed have a --help flag that will output some information.
When in tcsh, using nohup will use the shell's built-in command nohup, even in an external utility of the same name exists. See the tcsh manual for more ... | Can I run the nohup command from tcsh |
1,533,751,823,000 |
In "Learning the Bash Shell" by O'reilly (third edition), it is written in page 7:
lp -d lp1 -h myfile has two options and one argument.
How come?
I see what I reckon as two options, each one with an argument:
-d lp1
-h myfile
Notes
lp prints a file (concretely, via a printer, and not on the terminal).
|
While writing this question I understand my mistake, I should read the command this way:
lp
-d lp1
-h
myfile
The word myfile is just a file name that we print with lp it is not an argument of the -h option.
| lp -d lp1 -h myfile has two options and one argument or 2 options and 2 arguments? |
1,533,751,823,000 |
I have some lines which look like:
function( "((2 * VAR(\"xxx\")) - VAR(\"yyy\"))" ?name "name" ?plot t ?save t ?evalType 'point)
function("value(res VAR(\"zzz\"))" ?name "othername" ?plot t ?save t ?evalType 'point)
And, I would like to find a command which would output the string defined in the VAR function, i.e. s... |
If you have a grep that supports Perl Compatible Regular Expression (PCRE) then you can use
grep -Po 'VAR\(\\"\K[^\\]*'
or (more symmetrically - using lookbehind and lookahead)
grep -Po '(?<=VAR\(\\").*?(?=\\")'
Ex.
$ grep -Po 'VAR\(\\"\K[^\\]*'
function( "((2 * VAR(\"xxx\")) - VAR(\"yyy\"))" ?name "name" ?plot t ?s... | Extract one or more patterns from a string |
1,533,751,823,000 |
I installed Ubuntu 16.04 LTS and I was wondering, is there a way to start Ubuntu without starting the display manager (or exiting the display manager like Unity after it starts up) to basically go to the "headless" command-line mode where you just see something like:
Welcome to Ubuntu 16.04 LTS
blah blah
blah blah
jo... |
As mentioned by Thomas Ward in the comments, normally you should use the Server install ISO when you want a setup like this. If you've already got a system installed and what to convert it though, it's not too hard. The link given in the aforementioned comment has some of the best advice I"ve seen for simply disabli... | How do I exit out of a display manager like Unity |
1,533,751,823,000 |
I like using the traditional ex editor for simple command line operations, to re-arrange text within files. For example for a simple moving lines across in a file I would use something like
foo
bar
zoo
dude
to move the text dude after foo I would just do
printf '%s\n' '/dude' 'd' '/foo' '-' 'put' 'wq' | ex file
whic... |
Don't expect visual commands to work in ex mode. Do use the actual ex commands for inserting text, a[ppend] and i[nsert].printf '%s\n' '/abc' '-' '/\/\/' 'i' 'text' '.' 'wq' | ex file
Further reading
Dale Dougherty and Tim O'Reilly (1987). "Advanced Editing". Unix Text Processing. Hayden Books.
| How to use 'itextESC' when using ex as a text editor in command line? |
1,533,751,823,000 |
I am a new to shell script. This is just a variation of some previous questions, but I still cannot find answers. I have the following txt file (one line and no space):
;100=Raspberry;101=Apple;102=Orange;103=Kiwi;104=grape;
I like to pick anything with 101=* or 103=* as an output. So the output needs to look like th... |
.* tries to match as many characters as possible, that's why you get the rest of the line. So instead of . (any char) you have to use [^;] (any char except the semicolon):
grep -o ';101=[^;]*\|;103=[^;]*'
I'm not sure what to tried to achieve with -m 1 in a one-liner. Anyhow you need to combine your output in one lin... | Picks multiple parts of string line |
1,533,751,823,000 |
I am attempting to use a for loop to run command line arguments, I have never attempted this and I am having some trouble.
I am using the following commands:
for((a=1; a<20; a++));
do
./a.out -N 10000 -D .25*a -E 0.7788007831;
done
I am using the getopt function in c to read in values. I want to try different ... |
For one, if you want to refer to a shell variable, you need to use the $foo notation. a is just the letter "a" (in the same way 10000 is just the five digits), but $a expands to whatever the variable contains at the time.
Two, to do arithmetic in the shell, the syntax for arithmetic expansion is $(( expression )), so... | Using a loop to generate command line arguments |
1,533,751,823,000 |
I have a directory of files with similar names, but with incrementing digits as a suffix. I want to remove the lower suffixed files and only keep the files with the highest suffix. Below is an example file listing:
1k_02.txt
1k_03.txt
1l_02.txt
1l_03.txt
1l_04.txt
2a_05.txt
2a_06.txt
4c_03.txt
4c_04.txt
The above l... |
Complex pipeline:
Files list:
$ ls
1l_04.txt 2a_05.txt 4c_03.txt 1k_03.txt 1l_02.txt 4c_04.txt 2a_06.txt 1l_03.txt 1k_02.txt
printf "%s\n" * | sort -t'_' -k1,1 -k2nr | awk -F'_' 'a[$1]++' | xargs rm
Results:
$ printf "%s\n" *
1k_03.txt
1l_04.txt
2a_06.txt
4c_04.txt
| Remove files with smallest filename suffixes |
1,533,751,823,000 |
I have a bunch of files named Linux in various sub-folders where the whole line
DSY_OS_Release=`lsb_release --short --id |sed 's/ //g'`
needs to be replaced with
DSY_OS_Release="RedHatEnterpriseWorkstation"
How can I achieve this using the command line?
I know this sounds like a duplicate question, but I could not f... |
If you don't need to match the whole line, then just use
sed 's/^DSY_OS_Release=.*/DSY_OS_Release="RedHatEnterpriseWorkstation"/'
Depending on your sed implementation, you may use sed -i '...' file, or you may have to redirect to a new file and replace the original afterwards.
As for how to run this on a set of files... | replace a line of complex text within a number of files |
1,533,751,823,000 |
Is there a way or a tool to get percentage of difference between two strings (no new line characters, no files)?
For example, if there are 2 strings and each of them is 10 characters long and differ only in 1 character, then the difference should be 10%.
The strings may have different lengths and can hardly become lon... |
The Levenshtein distance is a useful metric to give an idea of the amount of difference between two strings. It measures the number of insertions, deletions and substitutions needed to get from one string to the other.
For instance, if you compare abcdef and bcdef, all characters are different if you compare them one ... | diff percentage between two strings |
1,533,751,823,000 |
I want to use file A (fileA.txt) with 233 IDs (four numbers, first column) to extract the 23th column from file B, but only from rows (first column also) that match the file A ID
I've tried:
awk 'NR==FNR{ a[$0]++; next }{ if ($23 in a) {$0=$23; print}}' FileA.txt fileB.txt > fileC.txt
|
If I understood correctly, you are going to match IDs in column1 from fileA.txt with IDs in column23 in fileB.txt and if matched print the column23 from fileB.txt, if no, please edit your question with more details.
I assume your files are looks like this:
==> fileA.txt <==
1111 column2 column3 column4 ...
2222 c1 c2... | Use file A with number IDs to extract 23th column from file B rows matching the IDs [closed] |
1,533,751,823,000 |
I'd like to find the most similar line pair contained within a file, using something like levenshtein distance. For instance, given a file along the lines of:
What is your favorite color?
What is your favorite food?
Who was the 8th president?
Who was the 9th president?
…it would return lines 3 & 4 as the most similar... |
I wasn't familiar with Levenshtein distances, but Perl has a module for computing Levenshtein distances, so I wrote a simple perl script to compute the distances of each combination of pairs of lines in the input, then print them in increasing "distance", subject to a "top X" (N) parameter:
#!/usr/bin/perl -w
use stri... | Compare similarity or levenshtein distance between each line pair within a file? |
1,533,751,823,000 |
I found somehow interesting command do specify disk usage which I am using without actually knowing what does the exclude pattern do. Instead excluding some locations or file names or just globs, the exclude pattern consists of the regular expression '*[0-9]G*'
Complete command is du --exclude='*[0-9]G*' -hax / | gre... |
'*[0-9]G*' is in fact a glob expression - not a regular expression.
The command excludes input filenames matching '*[0-9]G*', and then greps for du output lines matching '[0-9]G\>' such as would be produced due to the -h (--human-readable) du option - for example
3.3G /usr/lib
| Exclude parameter in du command |
1,533,751,823,000 |
I saw a video tutorial for the paste command, in which three files foo,bar,baz were connected horizontally with a "+" sign between.
cat foo
51
33
67
cat bar
10
1
13
cat baz
7
100
15
So, he used a paste command to make each line a whole addition and piped this into a while-loop which iterates through each line and p... |
In this case it was just for outputting what is progressed at the moment, and that line for line. Piping while loops is sometimes really useful e.g. displaying a progress bar.
Progress Bar Example:
for i in $(seq 1 100)
do
sleep 0.1
echo $i
done | whiptail --title 'Test script' --gauge 'Running...' 6 60 0
| When do you need "...|while read..."? |
1,533,751,823,000 |
I have a list of "tasks" which I go through to learn the shell-code, I need to use grep to isolate the line in /etc/passwd that contains “ubu”.
I know that the command less /etc/passwd is used to access /etc/passwd, and that grep is used to find/search for a certain string pattern, but that's about it
|
With grep:
$ grep -F "ubu" /etc/passwd
This uses grep -F to search for the literal string ubu in the file /etc/passwd. Without the -F, grep would treat ubu as a regular expression. In this case it wouldn't make a difference, but if the string contained characters, like *, which is "special" in regular expressions, ... | Isolating the line in /etc/passwd that contains "string" using grep |
1,533,751,823,000 |
I'm trying to do something that looks pretty simple but I haven't been able to solve.
I have a directory with a bunch of subdirectories all of them with multiple files (jpg files). I want to execute a command which keep only 4 or N files inside of these directories. The order of the files isn't important as I have see... |
Maybe something like:
for dir in /target/dir/*/; do
(cd -- "$dir" && set -- *.jpg && [ "$#" -gt 4 ] && shift 4 && rm -f -- "$@")
done
Which with zsh, you could shorten to:
for dir (/target/dir/*(/)) rm -f $dir/*.jpg(N[5,-1])
| keep N files in subdirectories |
1,533,751,823,000 |
The data in my text file and the output format expected is as shown.
I tried:
cat test2.txt | tr -d "\t"
But that's not working. Please help. As I have to read the file in the expected output format and do further loop processing.
|
Using awk:
BEGIN { RS = "" ; }
{
printf "%s %s %s %s %s %s %s\n", $1, $2, $3, $4, $5, $6, $7
}
produces:
WEBA 30-MAR-17 NA NOT_STARTED 01-APR-17 25-MAR-17 Target_Not_Started
WEBA 29-MAR-17 NA NOT_STARTED 01-APR-17 25-MAR-17 Target_Not_Started
WEBA 28-MAR-17 NA STARTED 01-APR-17 25-MAR-17 Target_Started
| Read multiple lines stored in a text file and format it in bash [closed] |
1,533,751,823,000 |
I have a named fifo and I am writing random number to this fifo.
When I write to fifo I want to find written text in numbers.txt file and write the result row to stdout.
Content of numbers.txt file is:
1 one
2 two
3 three
... and so on
I want to search text which piped to grep in this file.
For example If I write 1 t... |
cat <> myfifo opens the named pipe for both reading and writing. As long as the pipe is open for writing, the reader doesn't reach the end of the file. So cat never reaches the end of its input, so it never closes its output which is the pipe to grep, so grep never reaches the end of the input for the -f option.
Grep ... | Piping continious stream to grep as search term for search in a file |
1,533,751,823,000 |
I'm using this command to watch youtube videos from command line
youtube-dl https://www.youtube.com/watch?v=19jv0HM92kw -o - | mplayer -vo caca -
and I find it very amusing. However the player only shows on portion of my screen and I can't figure out on how to change the screen dimentions, as the mplayer arguments... |
Set CACA_GEOMETRY environment before run mplayer, like:
youtube-dl https://www.youtube.com/watch?v=19jv0HM92kw -o - | CACA_GEOMETRY=80x25 mplayer -vo caca -
(google power, 1st hit: http://www.mplayerhq.hu/DOCS/HTML/en/caca.html )
| mplayer text mode set screen dimentions |
1,533,751,823,000 |
when I'm executing my bash-script, I'm getting the wrong PID. I'm needing the PID to kill the process at the end of it. This is a simplified script that is affected by the issue:
echo 'PASSWORD' | sudo -S ping -f '10.0.1.1' &
PING_PID=$BASHPID;
echo $PING_PID;
The output is for example
[1] 14336
PC:~ Account$ PING... |
$BASHPID is the PID of the current bash process. You are looking for $!; see man bash, especially special parameters and job control. Also, ping needs sudo only if you are using -f (flood). Using sudo may complicate things, because as far as bash knows you are running sudo, not ping, therefore $! will return the PID o... | Bash-Script returning wrong PID |
1,533,751,823,000 |
I need to delete recursive subfolders in a single line.
For one subfolder:
find folder -name "subfolder" -exec rm -r "{}" \;
or
find folder -name "subfolder" -type d -exec rm -r "{}" \;
But in the case of several subfolders in a single line? (subfolder1, subfolder2 or foo, bar, dummy…)
|
What I would do :
find folder -name "subfolder[0-9]*" -exec rm -r {} \;
using a glob
or
find folder \( -name 'foo' -o -name 'bar' -o name 'base' \) -exec rm -r {} \;
| Delete recursive subfolders with find |
1,533,751,823,000 |
I recently came across this command in bash:
cat > filename << EOF
I do not understand the << EOF part. Googling the << operator, I only came across regular shift arithmetic left. Playing around with it gave me no insight either.
Any explanation would be appreciated!
|
It's here document, described in man bash:
Here Documents
This type of redirection instructs the shell to read input from
the current source until a line containing only delimiter (with
no trailing blanks) is seen. All of the lines read up to that
point are then used as the standard input for a comman... | What does this bash operation do? [duplicate] |
1,533,751,823,000 |
I wanted to know the frequency of A and B in column $3 and $4 for each different character present in column $1.
Command line in linux.
Example my input:
ID01 a1 A B
ID01 a2 A B
ID01 a3 A B
ID02 a1 B B
ID02 a2 B B
ID02 a3 B B
OA03 a1 A A
OA03 a2 A A
OA03 a3 A A
EA04 a1 -- --
EA04 a2 -- --
EA04 a3 -- --
I want this ou... |
One way to adapt your associative array based awk solution would be to concatenate the contents of $3 and $4 for each $1, and then at the END make use of the fact that gsub returns the number of replacements to count occurrences of A and B in the respective strings. For example:
awk '{
a[$1]=a[$1]$3$4;
next;
}
E... | Frequency of "A and B" for each specific character of other column |
1,533,751,823,000 |
How do I understand what the various options/flags mean?
For example:
1) uname -a - What does -a denote here?
2) pyang -f - What does -f denote here?
I just want to understand if there is some reference/doc that tells the usage of these? Please clarify.
|
With almost all Linux commands, I think the fastest and easiest first course of action is to append "--help" to the command. This gives you a good summary, which is often enough.
If you need more details, the man command is a good second choice.
For example:
$ uname --help
Usage: uname [OPTION]...
Print certain ... | What do the options after a specific command mean? |
1,533,751,823,000 |
It turned out that our production machine, running under CentOS, didn't have any timeout command, and we need to upgrade its core utilities (current version is coreutils-5.97).
Is it safe to upgrade this package?
Applications deployed on this machine are ran by Apache Tomcat Web server.
|
coreutils try really hard to be backwards compatible, though there isn't much point updating all utilities as that would add extra risk for no gain. You should be able to add just timeout using something like:
tar -xf coreutils-8.25.tar.xz && cd coreutils-8.25 &&
./configure --quiet && make && make check &&
cp src/tim... | Risks of Updating CentOS' coreutils-5.97 |
1,533,751,823,000 |
I have a CSV file that I need to parse, but the first n lines of this file are worthless garbage.
Fortunately, I know the proper header line starts with foo, and that every line before the first appearance of foo at position 0 can be deleted.
tl;dr How do I make this
an unknown
number of lines
with worthless junk
that... |
Per comments and further research, here's what ultimately worked for me
sed -i '/^foo/,$!d' path/to/file
| Delete lines from pattern match backwards |
1,533,751,823,000 |
I have a long list of folder as follow:
001_bat_3513
002_mon_3213
003_bat_3515
004_btt_3540
005_bat_4513
055_bpt_8523
056_bot_3513
058_bat_1513
.
.
From this list:
How can I copy the folders ( and all its content) that has the part " bat" in its name?
|
You can use shell globbing for this:
cp -rp *bat*/ /destination/
Here *bat*/ will expand to directories having bat in their names.
Or using find, which will work even if there are so many files that you get an error because the command line is too long:
find . -maxdepth 1 -type d -name '*bat*' -exec cp -rpt /destinat... | Copy folders has specific part of name and it is content |
1,533,751,823,000 |
I am using a Debian Virtual Box with the Bash shell and I am trying to use the ps command with the -c switch to find an ID of a process by searching its name. This is what I write:
ps -c processname
It then tell me:
error: unsupported option (BSD syntax)
This is the URL for the website that told me to use the syn... |
Try this syntax instead.
ps -A | grep processName
If your results include the process grep, remove it with:
ps -A | grep processName | grep -v grep
In my experience most linux programs work the same (ps) but there are differences that will always creep up.
Check YOUR current version with the manual pages for the cor... | ps command not working properly? [closed] |
1,533,751,823,000 |
I want to run a command every several minutes until I turn it off.
After some searching, I found lots of ways of doing the first half (running a command periodically and indefinitely), what about I want to turn it off?
Edit
By "turn it off" probably I mean "turn it off using another shell command".
Edit
Just to clarif... |
You have two options: Modify the Python script, or write a shell script wrapper.
To modify the Python script:
You should loop around what it is you want to be doing.
Install a signal handler to catch the INT signal (sent by Ctrl-C) and TERM signal (sent by plain kill). When the signal is caught, set a variable tellin... | How can I run a command periodically and indefinitely till it's turned off? |
1,533,751,823,000 |
I understand why it could be less than best practice if I write C code that executes shell commands by calling system() and that it's better to use exec and fork but then a very experienced C programmer told me that it's wrong to make a shell by forking and execing but he never answered why. Can you tell me? I could ... |
The two main reasons to run a program directly without calling the shell are:
Performance: Most programs that you would call from your C program are likely much smaller than the shell, which makes them start much more quickly.
Environment control: Dealing with an additional layer of environment variables to deal with... | Can all of fork(), exec() and system() be wrong? [closed] |
1,460,992,633,000 |
For example : To build a kernel we can use make it will take more than one hour , to accelerate the process we can use make -j4 all this may finish almost four times as quickly.
Generally : How to force an application to use a specific nombre nof cpu ?
|
There is no general solution to this problem - cpu usage of applications is entirely down to what the application does, and how it works internally.
In order to parallelism tasks for efficiency reasons, you often need to restructure the process flow. This varies greatly, depending on algorithm, so it's never as simple... | How to force an application to use a specific cpu? [duplicate] |
1,460,992,633,000 |
My problem: I cannot set my default shell for user 'student' on CentOS 7 to fish-shell. I installed fish-shell by downloading the .gz, configuring, make, make install.
output of which fish
/usr/local/bin/fish
running su from the standard 'student' account, I am able to escalate myself to root, which fish is set as ... |
Looks like one of your previous attempts to change the /etc/passwd file has left some rubbish in the lock file.
That lock file prevents multiple updates that would cancel each other out. If you are the only one using that system, remove the file /etc/passwd.lock and try again.
| Can't set my shell as fish shell due to error when using chsh due to lock file [closed] |
1,460,992,633,000 |
If I execute the below rsync command in command-line , I am getting the proper return status
/usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime"
echo $?
255
The hostname is unreachable , so I am getting a return value of 255
This is fine for me. But If I put the same command in ... |
try this.
#!/bin/bash
datetime=`date +%Y.%m.%d`
ret_value=`/usr/bin/rsync -azv -p /home/zaman x11server:/home/zamanr &> rsyncjob/output."$datetime"; echo $?`
echo $ret_value
The issue is that the command you are running doesn't produce an output since you are piping it to a file. Appending the command to echo the la... | return value of command not displayed in script |
1,460,992,633,000 |
I know that whatis command is used to output a brief description about an executable program (Command).
So both
whatis cd
whatis type
Will print: nothing appropriate (Because from my understanding they are both shell builtins). However how come, it works for
whatis echo
even though, echo is a shell builtin, is the... |
This works for echo because is both a shell builtin and a command. By default, the builtin is used.
$ type echo
echo is a shell builtin
$ type -P echo # ignores builtins
/bin/echo
$ echo foo # builtin
foo
$ /bin/echo foo # external command
foo
| Whatis command (shell builtin vs executable programs) |
1,460,992,633,000 |
I am trying to set up a LAN chat with two users using Linux server and none of them is root.
I have tried this two methods:
write account_name on both computers
And:
nc -l port_number on first computer
nc IP_adress port_number on second computer
But the problem is whenever I write something and person on the other ... |
Have a look at talk and talkd.
See https://wiki.archlinux.org/index.php/Talkd_and_the_talk_command and http://linux.die.net/man/1/talk for details.
| Chat over LAN in Linux |
1,460,992,633,000 |
I have a file which has the names of many files in a directory in the following format:
A20150824.0950-0955_jambala_CcnActiveSessionCounterJob
A20150824.0945-0950_jambala_CcnActiveSessionCounterJob
A20150824.0940-0945_jambala_CcnActiveSessionCounterJob
A20150824.0935-0940_jambala_CcnActiveSessionCounterJob
A20150824.0... |
Assuming:
hour=09
Just use that:
grep "\.$hour" file
With the single quotes in your example, the variable is not interpreted as variable. Therefore the pattern searches for $hour. Also the dot has to be escaped, else it would match any character.
| How to grep the following lines from a file? |
1,460,992,633,000 |
Objective
I'm trying to execute the following command in my Python script:
rdiff-backup --terminal-verbosity=5 --remote-schema "ssh %s -p1019 -i
C:/Users/Adam/.ssh/private-passphrase rdiff-backup --server"
C:/Users/Adam/Desktop [email protected]::/media/exthdd1/backup
My source directory is from a Windows OS an... |
The problem was indeed in /etc/fstab - I added the gid and uid values to the target drive's line of the user pi.
| rdiff-backup operation not permitted [closed] |
1,460,992,633,000 |
I like the elinks browser and I would like to know how does it render the HTML into text, using ANSI styles.
I suppose there is a library behind elinks to handle the rendering, or there should be. Is it possible to use that library in another project (e.g. to create a bridge to NodeJS)?
I would like to know where to ... |
I've taken a brief look at the source code. The HTML parsing and rendering code is a core part of elinks, and while it appears to be somewhat modular, it is not a separate library. It might be possible to separate it, but not without a good deal of work.
If you're curious, the src/README file provides an overview of... | How does Elinks render HTML? [closed] |
1,460,992,633,000 |
I need to run a command to grep one of these strings from command line as web host disabled account to run website from browser until virus files are removed and I managed to collect few strings that can find those files.
I would appreciate if someone knows if I can run a command for this.
Text to find:
bigdeal777
Goo... |
If you can put those in a file you can use grep's -f flag to read the patterns from a file and you can use -l to show just the files that have a match
Putting those together you can do something like
grep -R -l -f scanner.txt *
So the -R will cause it to search recursively (I'm assuming you want that), -l will print ... | How to grep from command line for theses multiple strings? |
1,460,992,633,000 |
I run grep some-string -r . &. While it is running in bkg, I cd to another directory. It seems that grep interprets the hard link . differently then. What happens before and after I change the current directory? Will both the original and the new directories not be searched completely?
I wonder if . as a command line ... |
Each process has its own "current working directory", which can't be changed from outside the process.
So when you do
grep some-string -r . &
your shell starts grep in the background, and grep's current working directory is initialised to the same value as the shell's at that moment. grep's definition of . here is it... | . as a command line argument to a command running in background |
1,460,992,633,000 |
i want to move myfile.tar.gz to folder
My command is
mkdir backup
mv myfile.tar.gz /backup
arrrgh, and the file gone
in /backup directory not exist, try using find command not shown
how to find it?
Thank you
|
You created a directory called backupunder the directory where you were at that moment.
However you moved the file myfile.tar.gz to /backup. The / means that you moved the file to a new file called backup under directory /.
The only thing you did was rename myfile.tar.gz to backup and put it under /.
| use `mv` command and my file gone [closed] |
1,460,992,633,000 |
I used to use gconftool-2 to edit keys in this way (here I change the cursor shape in gnome-terminal):
gconftool --type string --set /apps/gnome-terminal/profiles/Profile0/cursor_shape ibeam
But it doesn't work anymore, and I feel like there is a problem with the DBus daemon, even though I can't explain why.
This com... |
Got it! Credits to this answer. I added the following lines to my .zshrc or .bashrc:
sessionfile=`find "${HOME}/.dbus/session-bus/" -type f`
export `grep "DBUS_SESSION_BUS_ADDRESS" "${sessionfile}" | sed '/^#/d'`
And the settings are now refreshed as soon as I use gconftool-2.
| gconftool-2 doesn't refresh with the dbus anymore? |
1,460,992,633,000 |
I was messing around with a log4j properties file and accidently made a folder with the following text ${foo} however I also have an environment variable named foo that points to a folder so thus if I do rm -rf "${foo}" it removes the folder $foo is pointing to, instead of the folder ${foo}. How can I specify to delet... |
String interpolation causes this. There are a number of ways to selectively prevent this from happening.
The bash hackers wiki has some good examples, though the specifics may vary if you're not actually using bash.
In short, you can prevent interpolation with single quotes, or you can escape the characters.
[me:~/wor... | Remove a folder with the same name as an environment variable |
1,460,992,633,000 |
I have a directory(INPUTDIR) with sample names as subdirectories(508_C,540_C,570_D etc).Within those each subdirectories there is another directory called FASTQ which contains two kinds of files.
e.g.
540_Ct_1.fastq.gz
540_Ct_2.fastq.gz
I want to create two lists,the first having all _1.fastq.gz filenames with path... |
cd INPUTDIR
find . -name \*1.fastq.gz > list1
find . -name \*2.fastq.gz > list2
The paths in the "list" files will be relative to the current directory. If you want absolute paths, use
find "$PWD" -name \*1.fastq.gz > list1
| Creating a list containing filenames with paths |
1,460,992,633,000 |
I know that is not a exciting question, but yet I don't understand why some programs needs
program -h
and other
program --help
sometimes is very boring recognize it
|
In practice, programs should have both options. The -h is the "short form" and --help is "long form".
Short form command options are usually one or two characters while long form options are more descriptive (such as yum update -y and yum update --assume-yes meaning "assume yes to all questions").
Programs that don't... | why some programs needs -h and other no |
1,460,992,633,000 |
I'm training myself to use XMONAD or something of the sort, but in order to do that, I need to know, from terminal, how to open the following programs:
Bluefish Editor
Settings (I'm using Ubuntu but will install XMONAD ENV.)
Ubuntu Software Center
View time
|
Like this?:
$ bluefish &
$ software-center &
$ unity-control-center &
and one of
$ date
$ cal
$ xclock &
In practice, some programms write out some or many warning messages to stdout or stderr, which may clutter the terminal too much to use one terminal running multiple background programs, because you may see lot... | Need to know how to start some GUI programs from terminal to use XMoand |
1,460,992,633,000 |
Probably it would be easier to do just with a script, but I wonder why can't I do that with one command. What I have tried so far:
$ (ls >/dev/null &) && echo $!
3135
$ (ls >/dev/null &) ; echo $! #bad idea, but if that worked, I could just add `sleep 0.1`
3135
$ ls >/dev/null & ; echo $!
bash: syntax error near unexp... |
This should do what you want:
$ ls > /dev/null & echo $!
Because you were forcing the background command into a subprocess in all sorts of ways, the first shell did not have any background process and hence $! was not updated.
Now the background process is started by the same shell that gets to do echo $! so now it d... | Background a process and execute something with one command |
1,460,992,633,000 |
The unix program pal is one of a variety of command-line calendar programs.
Based on the man page, each line refers to an event, and it does not mention event descriptions that span multiple lines at all.
I am trying to insert a multiline event description, and tried with Line1\nLine2, as well as Line1\rLine2, both of... |
This isn't possible. I dug through the source code and you can force a line break (CTRL+V,CTRL+M), but this actually messes up the display. The event stays on the same line but the line break starts over at the beginning and overwrites the characters.
Given the following two examples:
00000325 Popeye statue unveiled... | Does the unix calendar program `pal` support line breaks? |
1,460,992,633,000 |
I am using Konsole in Kubuntu.
I was wondering what is the difference between a profile in Konsole and the profiles in our bash?
I am reading that we can create different profiles per Konsole session and use different bash per session.
What is meant by using different bash per session here?
I thought that the default ... |
The Konsole profile contains settings specific to Konsole eg terminal font, text colour, background colour, settings for shorcuts to manipulate tabs etc.
/etc/passwd defines the default shell for the user, of which bash is just the most common option. Alternatives to bash are zsh, ksh, csh etc. You can google each of ... | What is the different bash per terminal session for Konsole? |
1,460,992,633,000 |
When I type time + number in zsh:
# atupal at local in /tmp/atupal/setup/bin [10:01:49]
$ time 1
/tmp/atupal/setup/bin/lib/python2.7
# atupal at local in /tmp/atupal/setup/bin/lib/python2.7 [10:01:54]
$ time 2
/tmp/atupal/setup
# atupal at local in /tmp/atupal/setup [10:01:59]
$ time 3
/tmp/atupal/setup/app
# atupal a... |
oh-my-zsh creates a few alias in .oh-my-zsh/lib/directories.zsh named 1, 2 ... 9 which expand to cd -, cd -1, etc. So time is functioning correctly, but the unexpected alias 1 actually does something. The reason why time's normal output isn't given is due to the fact cd is a builtin command that doesn't require forkin... | zsh: What does the command "time + number" do in zsh |
1,460,992,633,000 |
To solve the bug reported here the solution seems to be commenting, not just adding a certain line in a file - as explained here and here.
That is - to make that bug disappear in Xfce, a certain line has to be added. But as that is not enough, the suggested solution is to comment that very line.
I have the impression... |
They are commenting a line in a configuration file. Really, it would be working around a bug of some sort. In other words, having the line in the configuration file activates the broken code. Commenting it out in the configuration file leaves the broken code dormant, and things work again.
It only fixes it from the... | In which way is a commented line active in a program file? |
1,460,992,633,000 |
A bash script is running as I defined it in Startup Applications. It is possible to display on terminal a variable used in that script? If yes, how?
|
The quick answer (assuming this is a bash script as tagged) is no, variables are not shared between separate shell instances. The only way I know of to access a variable from a script started in a different shell is to have the script write the variable to a file and then access that file.
| How can I use a variable from a script? |
1,460,992,633,000 |
When I want to redirect an output of a.out program I will use
./a.out > output.txt
This doesn't work when the program reads something from stdin.
How would you redirect output in this case?
I can do it only with
./a.out < inputs.txt > output.txt
Can I do the same but reading inputs from stdin?
EDIT: I realized that ... |
One option would be to write your prompts to stderr rather than stdout. They'll be visible on the terminal but not in output.txt.
Another option is not to use redirection for your output but take an output filename as a parameter and open that file yourself. You can then use stdout for your prompts. (This is more flex... | Redirecting output of program reading from stdin |
1,326,796,718,000 |
I was using these steps to build an application from Csipsimple but the problem is, they have mentioned it's for Linux and I tried, as a first step:
subversion git quilt unzip wget swig2.0 python make
I get a command not found error. First thing is, that I'm using fedora 13. I searched for the swig, python, quilt, su... |
That is a list of the programs you NEED to have installed in order to compile Csipsimple. It is not a command, and it will give an error.
Use your package management system from Fedora and install all those programs and the Android SDK as required on the page you linked to, than continue with the "Check out source cod... | Unable to follow steps for building application in Linux Os? |
1,326,796,718,000 |
I just downloaded a Ubuntu v10.10 vmware image for Windows. I'm trying to install a web application that can only run on Linux MySQL, Apache and PHP. How do I open a terminal in Ubuntu?
|
Try: Accessories > Terminal
;-)
| Ubuntu x86 10.10 terminal |
1,326,796,718,000 |
I have a script with this usage:
myscript [options] positional-args... -- [fwd-params]
Because [options] can have long, or short variants, I like using getopt. But I'm having troubles.
I use getopt like this:
args=$(getopt -o a:,b --long alpha:,gamma -- "$@")
eval set -- "$args"
while : ; do
case "$1" in
-a |... |
Well, if the user passes the arguments -a 1 -b pos1 pos2 -- fwd1, getopt takes the -- as the marker making all following arguments non-options. It's not a positional argument itself here.
If you want the -- to appear as-is, your user would have to explicly add the marker, and another -- one after to separate the two s... | getopt with several `--` |
1,326,796,718,000 |
I want to run a shell command once at a specific time in the future on Guix. My idea was to use the at command, but that seems to not be available on Guix.
The imperative nature of my desire goes against the declarative philosophy of Guix somewhat, which I expect is the (indirect) reason at is not available.
For examp... |
You have to use mcron via a posix or guile (scheme) script then run mcron &. Or install cron, crond or crontab as root.
scripts goes under ~/.config/cron.
Posix scripts should have the .vixie or .vix extensions.
Guile scripts should have .guile or .gle extensions.
The GNU documentation: mcron
| How to run a one-off command at a specified future time in Guix? |
1,326,796,718,000 |
I am a student and I am trying an excercise that involves assigning a word with quotes, double quotes and other symbols to a file name.
The problem is that I am not getting the expected results.
I am using the scape bar to scape the symbols, but when I list the name of the file this appears with unexpected single quot... |
It seems that I expected ls to work as ls -N. It seems in other machines the expected behaviour was different due to version or maybe configuration issues. About the quotes, it seems that they are not commands, but the prompt appears when the quotes are not properly closed as it interprets it as unfinished. All the ex... | Quote characters work as commands that redirect to the standard input |
1,326,796,718,000 |
I am just trying out the FISH - (the FriendlyInteractiveSHell) - CLI & whenever I type in an erroneous Command, a new Prompt appears under the faulty Command prompt with a number in square brackets. I have searched through FISH's FAQs etc., but no joy in explaining the meaning of the error-number? If I hit Enter, the ... |
The number in brackets is the exit status of the last command.
What this means depends entirely on the command. There is a strong understanding that returning 0 means success, but anything else signals some error and the command can choose the exact code.
| FISH CLI What do the error numbers at the prompt mean? |
1,326,796,718,000 |
Using sudo visudo I add the line username ALL=(ALL) NOPASSWD: /home/user/script.sh in sudoers but the script.sh does not run on double click.
If I add the line username ALL=(ALL) NOPASSWD:ALL in sudoers then the script.sh runs and works when double clicked. How can do it?
Thanks.
|
Setting my comment as an answer. Add this line as the first executable statement in your script
[[ $UID -ne 0 ]] && exec sudo $0 "$@"
This checks to see if you're running as root and restarted the script under sudo with the same arguments. Normal precautions and warnings apply in configuring sudo and with running thi... | How to run a bash script by double clicking by entering the path in sudoers? |
1,326,796,718,000 |
Say I do:
ls somedir
is there a way I could re-run it with a different command?
Example:
ls somedir
<run same command as above but with cd instead of ls>
|
The variable $_ is the last argument of the previous line you typed. So, for example, cd $_ would do what you described
bash-4.2$ ls X
1
bash-4.2$ cd $_
bash-4.2$ ls
1
There's also some command substitution options as well; eg ^ will replace commands on the previous line
bash-4.2$ ls X
1
bash-4.2$ ^ls^cd
cd X
bash-4... | How to run previous command with another command [duplicate] |
1,326,796,718,000 |
xargs provides a command xargs -P 0, the doc mentions that is spawns as many processes as possible to run the commands in parallel. But is it stopping, e.g., at the number of available CPU, or litterally several tens of thousands of threads? If it is the second option, isn't it less efficient than spawning around the ... |
I ended up doing the test myself. So -P 0 does try to run all processes at the same time (the limit being around the maximum number of allowed threads per the OS, which can be several thousands, I think), but it is a very bad idea to use it on CPU intensive tasks as this makes the system really slow.
I tested with aro... | What is `xargs -P 0` exactly doing, and is it a good idea to use it? |
1,326,796,718,000 |
i have a "sites" folder with a number of site folder named:
bu.my-url.com
dud.myurl.com
[must-be-indentical_string].myurl.com
etc
On each site folder, I'd like to check if the /themes/amu_[must-be-indentical_string] is identical to the site folder name
/sites/[must-be-indentical_string].myurl.com/themes/amu_[must-be... |
You could do:
#! /bin/sh -
cd /path/to/sites || exit
ret=0
for file in */themes/amu_*; do
[ -e "$file" ] || continue
dir=${file%%/*}
theme=${file##*/amu_}
case $dir in
("$theme".*) ;; # OK
(*) printf>&2 '%s\n' "Mismatch: $file"
ret=1;;
esac
done
exit "$ret"
With GNU find, see also:
cd /path/... | Finding on each folder if a subfolder respect the convention name according to the folder name? |
1,326,796,718,000 |
There is Herunterfahren(DE)/Shut Down and Neustarten (DE)/Reboot:
Is it possible to execute these GUI entries from the command line? If so, what exactly are the commands?
I already checked XFCE's docs page for the power manager, but as far as I understood it, these commands aren't listed there.
|
From https://askubuntu.com/a/771187/158442:
I think what you want is xfce4-session-logout (online manpage).
Excerpt from the manpage (reformatted, filtered):
The xfce4-session-logout command allows you to programmatically logout
from your Xfce session. It requests the session manager to display the
logout conf... | Are there commands for execute XFCE's menu entries to reboot or power off/shut down? |
1,326,796,718,000 |
Usually, a double dash separates options from filenames, but xdg-open does not care:
❯ xdg-open -headlinesAfter.epub
xdg-open: unexpected option '-headlinesAfter.epub'
Try 'xdg-open --help' for more information.
❯ xdg-open -- -headlinesAfter.epub
xdg-open: unexpected option '--'
Try 'xdg-open --help' for more informat... |
You can open the file by adding ./:
xdg-open ./-headlinesAfter.epub
| How to open a file starting with dash via xdg-open |
1,326,796,718,000 |
How can I import FreeCAD from the python console?
I'm trying to write a script that can manipulate a given FreeCAD file, but I can't even get FreeCAD imported into the python console on a system where FreeCAD is installed.
user@disp7637:~$ sudo dpkg -l | grep -i freecad
ii freecad ... |
Ah, I think the post you're referring to is overselling things a bit when it says
There is also possibility to import FreeCAD as a Python module but this is more complex.
FreeCAD in itself embeds python to give access to its internal state to scripts running within in the FreeCAD process.
So, things like import orde... | How to `import FreeCAD` in CLI (python) |
1,326,796,718,000 |
I have a text file contains about 50 song titles.
I'm searching for a CLI utility that can take each title from the text file, search for it on YouTube, get the top 4 video links then download the audio of the link.
So far I tried with youtube-dl, there is a search feature there but it only returns metadata and I can'... |
WAV is not modern audio container format; not quite sure why you want a container format that only supports constant-rate and -blocksize audio codecs. But since that is a really awkward thing for a streaming service to deliver, you'll have to download the audio and transcode it to some such codec and put it in a WAV ... | CLI utility to search and download YouTube videos in wav format |
1,326,796,718,000 |
For every program/utility on Unix, I would type the name of the program followed by --version to check its version, like so
program --version
If I understand correctly, the double dash -- is used to specify a single option named version instead of -version, which would mean 7 options v,e,r,s,i,o,n.
Why is it then th... |
The underlying issue is that every application implements its own argument parsing. From there it follows that each person/organisation might standardise on a format, but you can't convince everyone to follow a single standard.
There are several pieces of historical baggage which make the situation worse:
The BSD too... | Confused about java -version [duplicate] |
1,326,796,718,000 |
$ highlight -l -s clarity -S sh -O ansi some_file
No matter what I try, highlight always shows the same theme. And it is supposed to create a file 'highlight.css' but it doesn't. What am I doing wrong?
|
With -O ansi, the output will consist of ANSI escape sequences which would colorize the output in your shell.
The highlight.css file is created for HTML, XHTML, and SVG outputs.
Using -O html should get you your desired results:
$ highlight -l -s clarity -S sh -O html some_file
(Note that you could use the -o flag t... | highlight command refuses to change theme |
1,326,796,718,000 |
When using psql I always have to issue set role ... first.
Could this be executed automatically before accepting interactive commands?
E.g.:
psql -h HOST -U USER -c "set role 'ROLE';" -f -
This almost does what I want except that it reads the input directly (without readline).
I can't use -U ROLE because the role is ... |
Unless it is passed an -X option, psql attempts to read and execute commands from the system-wide startup file (psqlrc) and then the user's personal startup file (~/.psqlrc), after connecting to the database but before accepting normal commands.
and:
ENVIRONMENT PSQLRC Alternative location of the use... | Running psql with a role |
1,326,796,718,000 |
If you apply git clone --help in the command line, your result will include something like the following:
git clone [--template=<template_directory>]
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
[--... |
In --template=<template_directory> the character = is literal. Whatever you substitute for <template_directory> shall be appended to --template= and together they shall form one argument passed to git in the array of arguments. = is not special to the shell, it may be escaped or quoted in a shell. The argument may be ... | Syntax or convention used to describe Linux commands |
1,326,796,718,000 |
Is there some command I can use to monitor changes in /proc/interrupt?
For example, using head -4 I can see that the file is changing, but only if I run head again and again:
> head -4 /proc/interrupts
CPU0 CPU1
0: 451325 0 IO-APIC 2-edge timer
1: 0 3... |
How about watch cat /proc/interrupts That seems to be working on my ubuntu server.
| Output text file contents (/proc/interrupts) as they change [duplicate] |
1,326,796,718,000 |
This question should be asked for a million times, but I colud not find normal answer.
user is member of group adm
I created as root
# touch /tmp/keyboard-backlight.on
# chmod 666 /tmp/keyboard-backlight.on
# chgrp adm /tmp/keyboard-backlight.on
# chgrp adm /tmp/
# echo "text" > /test.txt
# chmod 0666 /test.txt
... |
Deleting and creating files require write permissions for the directory containing the file.
For /, it's owned by root, and it has no "write" permissions for group or others. So only root could delete files there, regardless of the permissions of the file.
$ ls -ld /
drwxr-xr-x 24 root root 4096 Nov 3 19:21 /
Regard... | Linux: Delete file as other and as group |
1,326,796,718,000 |
I have an interactive shell (assume dash) running under a GNU screen session. Is it possible to rename the "current" window via commands issued to the interactive shell? If so, then how?
By contrast, if I wanted to accomplish the same thing via GNU screen keybindings, then I would type CTRL+a followed by A to bring up... |
You can run any screen command (the ones that are or can be bound to keys) with screen -X.
So:
screen -X title 'New title'
Would set the title of the current window, same as Ctrl+a, A or Ctrl+a, : titleEnter followed by the new title.
See info screen title, info screen options, info screen 'Command Index' for details... | GNU screen: How to rename current window via shell commands? |
1,326,796,718,000 |
My logs nohup.out is owned by root user while I m trying to rotate the logs using system which has privileged access using sudo
I have written the below script to rotate logs.
cat rotatelog.sh
cp /var/www/html/nohup.out /var/www/html/nohup.out_$(date "+%Y.%b.%d-%H.%M.%S");
sudo tee /var/www/html/nohup.out;
The issue... |
tee will block waiting for standard input.
If your system provides the truncate command, you can try
sudo truncate -s 0 /var/www/html/nohup.out
Otherwise, you could do something like
: | sudo tee /var/www/html/nohup.out
to supply tee with an empty stdin.
| Trying to rotate logs however tee command fails to return after execution |
1,326,796,718,000 |
I'm looking for a command-line utility that allows me to check what service (eg: http/ftp/ssh) is running on a specific port of a remote machine.
An example of how I imagine a program like this would operate:
kess@KG-PC:~$ portcheck google.com:80
Port 80 of google.com is running a(n) "http" server
|
The simplest way to do such recognition is by establish connection to this port and grab the banner. Banner (usually) can tell you if this is for example Apache httpd, openssh and so on. The list of banners can be quite big. Also you can try some commands like GET / HTTP/1 to check if the service answer to them. For p... | Check what service is running on a specific tcp/udp port |
1,326,796,718,000 |
I would like to edit some preferences of xubuntu-desktop (xfce4), but 100% via Terminal.
In ubuntu-desktop (gnome) I use, for example:
# Prevent suspend and lock the sreen
gsettings set org.gnome.desktop.screensaver lock-enabled false
gsettings set org.gnome.desktop.screensaver ubuntu-lock-on-suspend false
... |
Solution:
The command to perform the changes: xfconf-query.
Listing Available Channels for Change
xfconf-query -l
Listing the Properties per Channel
xfconf-query -c $PROPERTY -l -v
# For example, the property "xfce4-desktop":
xfconf-query -c xfce4-desktop -l -v
-v: displays the value of the propertie... | Edit Xubuntu preferences via Command Line |
1,326,796,718,000 |
I can't understand the purpose of -p option in 'useradd'
Let's create a user
useradd -m -p 'pass1' user1
after running the command above, when trying to log in using su - user1
authentication fails.
another problem is that password is not encrypted in /etc/passwd file, if I run cat /etc/passwd | grep user1 I get u... |
You are supposed to provide the encrypted password to the -p option. From the useradd(8) man page:
-p, --password PASSWORD
The encrypted password, as returned by crypt(3). The
default is to disable the password.
Note: This option is not recommended because the password
... | useradd -p option [duplicate] |
1,654,992,595,000 |
About the less and according with:
Less command
Linux / Unix Colored Man Pages With less Command
indicates the following:
f ^F ^V SPACE * Forward one window (or N lines).
b ^B ESC-v * Backward one window (or N lines).
z * Forward one window (and set window to N).
w * Backward one window (and set window to N).
En... |
I'll try my best to explain with an example.
Open a long text file with less, something with obvious lines.
Now type 4z, and you will see that 4 lines have shifted down.
Type z and another 4 lines have moved.
That 4z has told less that you want the window size to be set to 4.
Once you have set the window size, all opt... | less command: b/f vs w/s |
1,654,992,595,000 |
Say that
https://example.nosuchtld
https://example.net
https://example.org
https://example.willfail
is the content of urls.txt. I want to run <command> <url> for every URL/line of urls.txt —where <command> is, let's say, curl; so,
cat urls.txt | xargs -n1 curl
or
<urls.txt xargs -n1 curl
for instance. I want ever... |
With zsh, you could do:
while IFS= read -ru3 url; do
curl -- $url
print -ru $(( $? ? 4 : 5 )) -- $url
done 3< urls 4> bad 5> good
That way, the bad and good files are opened only once and only if urls itself can be opened for reading.
| What's a clean way to run a specific command C for each line L of a given file F and then move every L where C(L) ran unsuccesfully? |
1,654,992,595,000 |
Some potential duplicates may be the following:
How to ignore specific lines from being redirected
BUT I can't extrapolate from that to solve my problem. So, I am asking here instead.
So, here is what I got so far:
sbcl --noinform --non-interactive --eval "(ql:quickload :lambda-calculus-compiler)" < test.lisp > x.txt
... |
One option is to pipe the command through sed before redirecting to the file:
sbcl --noinform --non-interactive --eval "(ql:quickload :lambda-calculus-compiler)" < test.lisp |
sed '1,/Loading "lambda-calculus-compiler"/ d' > x.txt
This removes the lines starting with 1 through the one after that containing that phr... | How to redirect while ignoring some of the text |
1,654,992,595,000 |
I have a static html site at localhost. When I open Chromium and manually enter localhost into the address bar, the site appears and behaves correctly.
However, when I type the following from the terminal...
chromium-browser localhost
...Chromium opens, localhost appears in the address bar, but the page never loads ... |
I found this post: https://forums.raspberrypi.com/viewtopic.php?t=330711#p1990605
I blindly tried its suggestion, which was to execute the following:
echo 'export CHROMIUM_FLAGS="$CHROMIUM_FLAGS --use-gl=egl"' | sudo tee /etc/chromium.d/egl
(that is, it creates a file /etc/chromium.d/egl which contains the command to... | chromium-browser - can't launch site from command line |
1,654,992,595,000 |
I'm trying to easily move some data with rsync from one server to another without actually connecting manually and doing all that, but only giving the IPs as arguments.
# -- Variables
my_key="my_key"
new_ct="${2}"
old_ct="${1}"
# -- SHH key generation on the localhost
mkdir /tmp/keys/
cd /tmp/keys
ssh-keygen -t ed255... |
You have double quotes inside the double quotes (for instance, "migrating.localdata.to.newCT"). You need to escape the internal double quotes to be treated literally.
ssh -o StrictHostKeyChecking=no root@${old_ct} -p 2222 -i ${HOME}/.ssh/${my_key} \
"
screen -dmLS \"migrating.localdata.to.newCT\" \
bash -c \"rsync -a... | How to initiate rsync transfer from one server to another through ssh? |
1,654,992,595,000 |
I am on a server, whoose network is set statically:
auto eth0
iface eth0 inet static
address 10.1.212.103
netmask 255.255.255.0
gateway 10.1.212.1
How can I, from the commandline, pretend I am DHCP client, and ask DHCP server for network info?
I don't actually want to change the network settings, but I wa... |
For me, dhcping works:
$ sudo dhcping -v -s 192.168.177.1
Got answer from: 192.168.177.1
You can use -V to see the packets exchanged. However, as it's not a real request, I got a NACK, and no nameserver information.
It doesn't work without the server address for me, apparently it doesn't do a broadcast?
As for -g, se... | get DHCP info from commandline |
1,654,992,595,000 |
Currently I am having a bash script in which I accept input from the command line, but the input is with spaces and the bash script is not reading the word after the space. The script is something like this
#!/bin/bash
var1=$1
var2=$2
echo $var1
echo $var2
Suppose I save this file as test.sh. Now my input is somethin... |
That's not possible. The word splitting of the arguments happens before the script is run, so when it starts, the arguments have already been split into words. Read about "word-splitting" in man bash to learn more about the details.
If you know there will be 2 arguments and the first one will never contain spaces, you... | How to accept input with spaces from command line in bash script |
1,654,992,595,000 |
I use incremental backup using
tar --create --file=/home/blueray/Documents/backup/dest/$(date +%Y-%m-%d-%H-%M-%S).tar --listed-incremental=/home/blueray/Documents/backup/dest/usr.snar /home/blueray/Documents/backup/src
But the problem is,
it create too many .tar files as i backup multiple times a day. For example 20... |
It is normal to have a multiple backup version, if you delete the old tar file you can not extract/restore from it anymore.
in order to extract you can issue the below command:
tar --extract --verbose --verbose --listed-incremental=/dev/null --file=2021-11-23-23-34-38.tar
I suppose here you want to restore from the... | How to manage tar files when creating incremental backups |
1,654,992,595,000 |
I have a script that reads a line from a file into variable foo. The line is in fact a long command that I often use as a template. I am trying to edit and re-use this long command. How can I place $foo on the command line ready to edit? I do not want to copy and paste the line, nor do I want to use any new apps that ... |
To reload bash's history file into the current shell (i.e. without logging out and logging in again), run:
history -n
From help history:
-n read all history lines not already read from the history file
| how to place a text in the command line |
1,654,992,595,000 |
Is there a Linux command that can remove the first character on the first line for every file in a folder, and then save it?
Many online resources cover doing this for every line instead of just the first one, for filenames, or they don't save the files. I tried modifying one of these commands to do what I wanted, but... |
If you have GNU sed :
find PATH -type f -exec sed -s -i '1s/.//' \{} +
| Is there a Linux command that removes just the first character of every file? |
1,654,992,595,000 |
I have improper text file which has product name, website location and quantity. Now I just want to prepare product name, number (extract from URL) and quantity.
Input file:
rawfile.txt
Component name Link Quantity
Ba Test Con - Red https://kr.element14.com/multicomp/a-1-126-n-r/banana-plug-16a-4mm-cable-red/dp... |
Something simple like this would do? (can be improved, but you got the idea)
$ cat test.txt
Ba Test Con - Red https://kr.element14.com/multicomp/a-1-126-n-r/banana-plug-16a-4mm-cable-red/dp/1698969 25
Ban Te Con - Black https://kr.element14.com/multicomp/a-1-126-n-b/plug-16a-4mm-cable-black/dp/1698970 25
Ban Te C... | Extract Product, number and quantity from a text file |
1,654,992,595,000 |
I'm attempting to use sed to remove some lines from json files. As you can probably tell, I'm very much an amateur but think I have the regex correct. However sed throws various errors including unterminated address and unterminated 's' command.
The text I'm trying to remove is:
{
"trait_type": "Accessories",
... |
Assuming this is part of a JSON file, the following jq command would find all objects with a trait_type key and a value key and delete all of those objects where the value key has the value None.
jq 'del( .. |
select(
type == "object" and
has("trait_type") and has("value") and
.value == "None"
... | Delete text from files using regex with sed |
1,654,992,595,000 |
I'm using the following command to unzip epub files recursively inside a folder:
find -iname \*.epub -exec unzip {} \;
It works. But the terminal asks me this each time a file is being extracted:
replace mimetype? [y]es, [n]o, [A]ll, [N]one, [r]ename:
Is there a flag that I can add to the command so it automaticall... |
If you want to overwrite existing files without prompting, use unzip’s -o option:
find -iname \*.epub -exec unzip -o {} \;
If you only want to avoid being prompted, a safer option would be -n — it skips files which already exist, instead of overwriting them, again without prompting.
| How to automatically replace mimetype when unzipping? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.