date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,373,893,866,000 |
I'm running CentOS 7.2 on my Cloud Account and following some tutorials to install Grafana.
I've almost finished install but got stuck when they asked me to execute this command which used to start the service on boot.
update-rc.d grafana-server defaults 95 10
Of course, i did it and error came out: update-rc.d comma... |
update-rc.d doesn't exist on Red Hat distros such as Fedora/CentOS/etc. The equivalent would be to use chkconfig, eg.
chkconfig grafana-server on
By default, chkconfig assumes levels 2345. Any runlevels not specified as on, will be marked as off; levels 016 by default. So you can specify runlevels:
chkconfig --level ... | convert update-rc.d command into chkconfig |
1,373,893,866,000 |
I have the following code:
#!/bin/bash
task=$1
xml=$(curl -sL "http://login:[email protected]/issues/$task.xml")
id=$(xmllint --xpath '//issue/id/text()' --format - <<<"$xml")
name=$(xmllint --xpath '//issue/subject/text()' --encode utf8 - <<<"$xml")
echo "task #$id - $name"
But when I run it I get encoded cyrillic ... |
After a few minutes of fighting with xmllint, I usually give up and end up using xmlstarlet instead which is usually more inclined to doing what you expect it to do. Here:
xmlstarlet sel -t -v '//issue/subject' <<< "$xml"
(or <rant>give up altogether on XML and use a more sensible format</rant>).
| Problem with encoding in shell script |
1,373,893,866,000 |
I know how to play a tone for a specific amount of time using SOX.
play -n synth 5 sin 347
I know how to save a tone using SOX.
sox -n note.mp3 synth 5 sin 347
Question is : How can I save a longer tone (hours) without the sound actually playing and not actually having to wait hours for the file to generate?
|
Answer: @derobert pointed out the "sox" and "play" command are part of the same package but does different thing. The 3600 below is the time interval in seconds.
sox -n note.mp3 synth 3600 sin 347
The above code will generate an hour long tone without playing it.
play -n note.mp3 synth 3600 sin 347
The above code w... | Generating a long sound file with SOX without actually playing the tone |
1,373,893,866,000 |
I have set a simple udev rule for my Raspberry Pi (Debian) to automatically mount an USB HDD. It just runs a script which mounts all devices in /etc/fstab since it's the only one I have and I'm going to have there.
I just need that but I saw that there were some environment variables that got passed to the script and ... |
When you are printing straight to the terminal, your shell doesn't know about it, so it doesn't know to print its prompt again. You would get similar behavior running e.g. (sleep 1; echo foo) &.
I would suggest either not printing from your udev rule (that seems like the more usual thing to do: be quiet unless somethi... | Need to press enter to get prompt after executing udev script |
1,373,893,866,000 |
I am writing a bash script to perform some analysis using the program ROOT. I want to run some initial command to load the result of the analysis, then continue using ROOT interactively.
The analysis part goes along well but the problem is that after root is executes my initial command, it closes immediately. So far I... |
You could do:
expect -c 'spawn -noecho root -l SummerStd_140PU_NM1_his.root
send "TBrowser a;\r"
interact'
| Pass a command to ROOT from a shell script and having it stay open |
1,373,893,866,000 |
Possible Duplicate:
Recursive rename files and directories
I have a large directory of music files that is often changing as files and directories come and go. My preference is to make sure that file and directory names don't have spaces in them, so I replace them all with underscores.
I go into the main directory... |
Here's what happens:
find finds the matching directory ./Test 02.
find executes the rename command on that directory.
rename renames Test 02 to Test_02.
find tries to descend into the directory Test 02. But it no longer exists.
The easiest way of solving this problem is to tell find to work the other way round: firs... | How do I get this find and rename command to work with subdirectories? [duplicate] |
1,373,893,866,000 |
I have to find a free, gratis command line solution to convert primary Microsoft PowerPoint presentations into HTML files (1 HTML file per foil) on Linux (Debian, OpenSuse). It would be nice if the solution supports OpenOffice Impress presentations as well but this is not necessary.
What is/are solution/s for this mat... |
You want to use pptHTML:
http://www.ma.utexas.edu/restricted-resources/utma-doc/xlHtml/pptHtml.txt
For debian based distros:
http://packages.debian.org/unstable/utils/ppthtml
The C Source for the xlhtml package:
http://prdownloads.sf.net/chicago/xlhtml-0.4.9.3.tgz
ppthtml is an executable installed through the same pa... | How to convert a PowerPoint ppt file into HTML files? |
1,373,893,866,000 |
I got a bunch of URLs (more than 1,000) and I am wondering if there is any CLI script to validate URL for http schema?
|
You can use Perl's Regexp::Common::URI::http. From the CPAN documentation:
use Regexp::Common qw /URI/;
while (<>) {
/$RE{URI}{HTTP}/ and print "Contains an HTTP URI.\n";
}
| Any CLI to validate URL? [closed] |
1,373,893,866,000 |
I have this line that I execute from php
sudo -u db2inst1 -s -- "/opt/ibm/db2/current/bin/db2 connect to PLC; /opt/ibm/db2/current/bin/db2 \"update EDU.contact set MOBILE_PHONE = '123'\""
it works fine on Sudo version 1.7.2.
Now I got new server with SUSE Linux Enterprise Server 11 (x86_64). There was no sudo so I ins... |
I'm really not quite sure why you're getting this error. I have a system with sudo 1.8.3 on it, and the documentation clearly says something like sudo -s "echo hi" should work, but it doesn't.
The way I've always done this is to do the same thing -s [command] does, but manually.
sudo sh -c 'echo hi'
or in your case
s... | How to run this in sudo? |
1,373,893,866,000 |
I don't mind the idea of quotes when I load the Mint console, however the OEM text leaves much to be desired. I'd like to update the quote text with inspirational or otherwise useful quotes.
How would I go about doing that?
|
Editing Linux Mint fortunes! (Mint 13) has some good information for how to tweak what "fortunes" are displayed.
In specific, it appears they are stored in /usr/share/cowsay/cows (as plain text, preformatted) with .cow extension.
There's more information in the link.
| Change (not remove) "fortunes" in Linux Mint console |
1,373,893,866,000 |
I recently changed my MacBook's UI to show Hebrew, and at around the same time, I began using the Terminal more often. The combination of the two has lead me to wonder - are there Hebrew language commands, or any other non-english language command sets available for the terminal either on Unix, Linux, or Mac OS?
(This... |
This is a cool idea, but I don't think it exists. Alternatively, you could write your own wrappers (in Hebrew in your case) either as executable code or as an alias in your ~/.bashrc.
Something like:
alias [hebrew_for_add_a_user]='useradd'
I would personally opt for the alias implementation.
| Are there foreign language Terminal command sets? |
1,373,893,866,000 |
I know the commands to restart/stop/start, but when I try to pass options it doesn't seem to work!
CENTOS 6, MySQL 5.14
service mysql restart
service httpd restart
Then I tried this:
/etc/init.d/mysql --general_log /my/log/path.log
That doesn't work either (the error message says it doesn't have access) =/
Update: A... |
To change options permanently and in the sanctioned manner, edit the files in /etc/sysconfig that have the same name as the service.
For example, consider httpd. On one system I have, there are several things you can set:
# Processing model
HTTPD=/usr/sbin/httpd.worker
# Additional options
OPTIONS=
# Set locale
HTTP... | If I'm logged in as root, how do I restart mysql or apache with options? |
1,373,893,866,000 |
I'm something called iscan to use my scanner. However to use it, I need to go through a GUI to get my scanned pdf. When I run iscan --help (because just iscan launches the GUI), it tells me that it is a GIMP plugin and requires to have GIMP launched:
iscan is a GIMP plug-in and must be run by GIMP to be used
Is there... |
Use scanimage from sane-backends.
| Using iscan (GIMP plugin) from the command line |
1,373,893,866,000 |
I actually found following one-liner on commandfu.com:
cmdfu(){ curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; }
I have not come across a similar use of the () in bash before.
It seems that it creates the command cmdfu temporarily within the bash environment. Am I... |
This is a shell function. If you create it at the command line, it will exist only for the current shell invocation. You can add the definition to a shell startup file (.bashrc, .bash_profile, etc) and it will make it "permanent".
If you search the bash(1) manpage for "Shell Function Definitions" you can see the synta... | What is this construct in bash? mycommand(){dosomething;} |
1,373,893,866,000 |
Is there any tool to count the number of system-calls issued for example in one-second in the entire system (like a global strace) ? ( Something like what vmstat does for number of interrupts or context switches per second )
|
One possibility is to count system calls with perf. If you only want a global count, updated every second, run
perf stat -e raw_syscalls:sys_enter -a -I 1000 sleep 5
This will show the global count of system calls, every second, for five seconds. The sleep 5 command determines how long the trace will last; the -I par... | Counting the number of issued syscalls |
1,373,893,866,000 |
TL;DR:
Q: How to keep a counter in find -exec loop ?
My use-case:
I need to move a lot of directories which are scattered around the place, so I do
find . -type d -name "prefix_*" \
-exec sh -c '
new_path="/new/path/$(basedir "$1")";
[ -d "$new_path" ] || mv "$1" "$new_path";
' find_sh {} \;
... |
Instead of using a pure find command you could combine find with a while read loop or GNU parallel. Both are likely to be faster than find's -exec since you don't start a new shell for every path found by find.
Solution Using GNU Parallel
GNU parallel has the following benefits compared to while read:
Easier to get r... | find -exec and increment counter / progress |
1,373,893,866,000 |
I want to extract frames as images from video
and I want each image to be named
as InputFileName_number.bmp.
How can I do this?
I tried the following command:
ffmpeg -i clip.mp4 fr1/$filename%d.jpg -hide_banner
but it is not working as I want.
I want to get, for example, clip_1.bmp, but what I get is 1.bmp.
I am tr... |
$filename is handled as a shell variable.
What about
ffmpeg -i clip.mp4 fr1/clip_%d.jpg -hide_banner
or
$mp4filename=clip
ffmpeg -i ${mp4filename}.mp4 fr1/${mp4filename}_%d.jpg -hide_banner
?
Update: For use with gnu parallel, you can use parallel's -i option:
-i
Normally the command is passed the argument at the... | How to include input file name in output file name in ffmpeg |
1,373,893,866,000 |
I need the number of the previous week of the month.
In the 2nd week of March, the previous week would be 1. In the 1st week of April, the previous week would be 5.
My week starts with Monday.
WEEK=$(( 1 + $(date +%V) - $(date -d "$(date -d "-$(($(date +%d)-1)) days")" +%V) ))
How may I subtract one from this so tha... |
If I'm not mistaken, your expression (reorganized here a bit), finds the week number corresponding to the first day of the current month, the week number corresponding to today, and calculates the difference as week-of-month?
first=$(date -d "-$(($(date +%d)-1)) days")
weekofmon=$(( 1 + $(date +%V) - $(date -d "$first... | Get previous week's number in bash |
1,373,893,866,000 |
As you can see I'm trying to run a Java program but I need the command which I can write in terminal to run the code.
|
I imagine the easiest way would be to press the blue arrow at the top.
If it has to be command line though, try
Javac Main.java
To compile the source to byte code which will give you a Main.class file, then
Java Main
To run it. The oracle website has a quick guide here
| How to run a simple Java program using terminal command? |
1,373,893,866,000 |
I am working in a big project using SVN and many times I have to go see things in other people's branches and play with them. But I want to keep those changes local, never commit them.
By mistake, though, its very easy to type svn ci -m"blabla" and commit my changes in someone else's branch.
The branches have some ide... |
I would use a shell function:
svn () {
if [[ $1 == "ci" || $1 == "commit" ]] && [[ $PWD != *"-bb"* ]]; then
echo "don't commit to someone else's branch" >&2
return 1
fi
# now, do the actual svn command
command svn "$@" # quotes are crucial here
}
| Confirm "svn ci" command depending on my current location |
1,373,893,866,000 |
The company just gave us all a new virtual machine for development porpoises.
It runs Arch Linux, which nobody here has experience of.
The VM has no internet access, but we can side load files by dowloading them on the Windows host PC and placing them in a directory which is shared with the VM.
How can I serach for su... |
What a sad thing having a VM without internet access :( I think that you should talk to your boss and tell him that without internet access you can't properly update your linux distro, and this can lead to potential security issues.
Anyway, you can browse the Arch Linux official package list from here: https://www.arc... | How to install from the command line in Arch Linux? |
1,455,402,031,000 |
On page change, redraw, or Reload command, xpdf will reload the file it is currently displaying. Is it possible to cause xpdf to reload the file by sending a signal? Which signal?
(I am basically looking for the functionality offered by xpdf -remote ServerName -reload, except I want to apply it to an xpdf that was n... |
I don't think you can use a signal. But Xpdf accepts synthetic events, so it's easy to programmatically type r into the window using xdotool(1). Unfortunately the xpdf window does not identify itself by its PID, but the following seems to work:
xdotool search --onlyvisible --class Xpdf key r
If you know the name of... | Is it possible to send an xpdf process a signal that causes it to reload the file being displayed? |
1,455,402,031,000 |
Part of my software issues various commands to open and view different file types. For instance I use atril for PDFs and eom for PNGs.
However I have a slight problem with CSV files. I can open them with soffice –calc <filepath> but each time it goes through the Import stage.
Is there a way I can avoid this, to avoid ... |
A method to skip importing would be to convert the file to a format that can be read without importing - so for instance:
soffice --headless --convert-to ods --outdir /tmp tblIssues.csv
soffice --view /tmp/tblIssues.ods
rm /tmp/tblIssues.ods
This converts the file tblIssues.csv to a ODS spreadsheet, saves it to /tmp ... | Open CSV File And Go Straight To Spreadsheet |
1,455,402,031,000 |
Creating a git repository for testing.
~ $ mkdir somefolder
~ $ cd somefolder/
~/somefolder $ git init
Initialized empty Git repository in /home/user/somefolder/.git/
~/somefolder $ echo test > xyz
~/somefolder $ mkdir somefolder2
~/somefolder $ echo test2 > ./somefolder2/zzz
~/somefolder $ git add *
~/somef... |
When you do a simple export with HEAD, an internal timestamp is initialized based on the commit's timestamp. When you use more advanced filtering options, the timestamp is set to the current time. To change the behavior, you need to fork/patch git and change the second scenario, eg proof of concept:
diff --git a/archi... | How to create a deterministic tar.gz using git-archive? |
1,455,402,031,000 |
I want the output of:
diskutil list; diskutil info [multiple devices]
Without having to do:
diskutil info disk0; diskutil info disk0s1; diskutil info disk1 ...etc
For example, with many builtin commands like touch rm mkdir, etc. I can use bracket expansion to perform commands on multiple versions of a file:
mkdir njb... |
The brace expansion you're asking about will only expand for files/directories that match on disk to the pattern you use. The other issue you'll run into is diskutil may not be able to handle more than 1 argument at a time. To expand these you'd need to do a while or for loop, and pass the results to diskutil as you i... | How can I list the info for an array of /dev/disks using bash expansion or substitution? |
1,455,402,031,000 |
What is the most portable or standard way to send an email from the console or a script on Linux, and possibly Unix?
|
To do this, you can use the mailx command. Below is an usage example:
mailx -v -s "Subject" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://<server_name>:25 -S from="[email protected]" -S smtp-auth-user=<username> \
-S smtp-auth-password=<password> [email protected]
This example is using S... | Standard and portable way to send email from console? |
1,455,402,031,000 |
When writing in command line I have this aversion to scrolling my eyes down to the bottom of the page as I write commands.
How do I keep the cursor/line at the top and allow the output to be displayed below it every time I write and execute a command? Has anyone ever tried to accomplish this?
|
You can do something like that by adding
\[\e[f\e[K\]
at the beginning of your prompt variable (PS1). But it doesn't take scrolling into account.
\[ start non-printing sequence
\e[f ANSI escape sequence to move cursor to position 1;1
\e[K ANSI escape sequence to erase from cursor to end of line
\] end... | How to keep the terminal cursor fixed at the top? |
1,455,402,031,000 |
I'm trying to write a script that switches focus to Emacs. This is what I have:
#!/bin/bash
wmctrl -a 'emacs@pat-ubuntu-desktop'
It works fine when there is only one Emacs window (or "frame," in Emacs parlance) open, but it doesn't do anything when multiple Emacs windows are open. The problem seems to be that the win... |
Matching on the window title isn't very reliable. For example, if you're viewing this question in your browser, then wmctrl -a 'emacs' might activate your browser.
You can customize the frame title format with frame-title-format. I use (multiple-frames "%b" ("" invocation-name "@" system-name)). But I don't recommend ... | Getting wmctrl to work with multiple Emacs windows |
1,455,402,031,000 |
Say I want to modify the latter of some concatenated command line options, is it possible without killing the first command?
Specifically I have compile and run scripts executed thusly:
> compile ; run
The compile is in progress (half way through two hour duration), but new information tells me I don't really want th... |
Something like
compile && { test -f /path/to/dont_run || run; }
should solve your problem. touch /path/to/dont_run would prevent run from being executed. You can make this more complicated (and more convenient) by e.g. defining a shell function cond_run_cmd which does some check like that, limited to its tty (so that... | Suspend and edit previous single line commands |
1,455,402,031,000 |
Question: Is there an easy way how I can teach zsh to check the command line before executing it? I know that I can completely wrap a specific program with an extra script, but this is not what I want to do.
Example:
Using tab completion, it could happen to me easily, that I overwrite my input file by calling gcc wron... |
You could redefine the accept-line zle widget to do all the checks you want like:
accept-line() {
if [[ $BUFFER =~ '^gcc.*-o\s*\S*\.c\b' ]]; then
zle -M 'I will not do that!'
else
zle .$WIDGET "$@"
fi
}
zle -N accept-line
| zsh - check arguments of a command before executing it |
1,455,402,031,000 |
I'm trying to figure out if there is a way to get the UNIX command tree to display only directories that match a specific pattern.
% tree -d tstdir -P '*qm*' -L 1
tstdir
|-- d1
|-- d2
|-- qm1
|-- qm2
`-- qm3
5 directories
The man page shows this bit about the switch.
-P pattern
List only those file... |
Someone mentioned on stackoverflow in the trees man page that this is why the -P switch doesn't exclude things that don't match the pattern.
BUGS
Tree does not prune "empty" directories when the -P and -I options are
used. Tree prints directories as it comes to them, so cannot accumu‐
late information o... | Can the UNIX command tree display only directories matching a pattern? |
1,455,402,031,000 |
I'm using the following script to copy multiple files into one folder:
{ echo $BASE1; echo $BASE2; echo $BASE3; } | parallel cp -a {} $DEST
Is there any way to use only one echo $BASE with brace expansion?
I mean something like this:
{ echo $BASE{1..3} } | parallel cp -a {} $DEST
|
You could use an array:
BASES[0]=...
BASES[1]=...
BASES[2]=...
# or BASES+=(...)
# or BASES=(foo bar baz)
echo "${BASES[@]}" | parallel cp -a {} $DEST
To make it safer (spaces and newlines in the variable in particular), something like this should work more reliably:
printf "%s\0" "${BASES[@]}" | parallel -0 cp -a {}... | Copy multiple files to one dir with parallel |
1,455,402,031,000 |
I am contemplating using mpg123 as an audiobook player. I can't find any other good audiobook players for Linux, and I think mpg123 may be my best option.
My audiobooks are organized by directories and the track names are numbered (e.g., Track-01.mp3, Track-02.mp3, etc.).
What I am seeking is a way to save the last l... |
Thomas Orgis, a mpg123 developer and maintainer, just implemented this functionality in mpg123 (as a script called 'conplay') at my request.
His description is:
This little wrapper runs mpg123 on a given directory (hand in '.' for the current one), playing all *.mp[123] files therein in terminal control mode. The ext... | command line audio with mpg123 - how to save position in audio and begin from that location next time? |
1,455,402,031,000 |
I have an interactive terminal program, that accepts stdin (telnet for example).
I want to send it some input before interacting with it, like this:
echo "Hello" | telnet somewhere 123
But that only sends in Hello and kills telnet afterwards. How can I keep telnet alive and route input to it?
|
You can't change what STDIN of telnet is bound to after you start, but you can replace the simple echo with something that will perform more than one action - and let the second action be "copy user input to the target":
{ echo "hello"; cat; } | telnet somewhere 123
You can, naturally, replace cat with anything that ... | Sending some input into a process, then resuming input from command line |
1,455,402,031,000 |
We use the `exceed tool to connect to our UNIX servers, but sometimes the command-line behaves erratically. When I am typing some command on the command-line, nothing happens -- nothing is displayed on the screen and I need to close the terminal and open a new one. Why does that happen?
Is it related to stty sane? I h... |
I'm not sure if it is what is happening in your case, but pressing Ctrl+S will freeze the tty, causing no updates to happen, though your commands are still going through. To unfreeze the tty, you need to hit Ctrl+Q.
Again, I'm not totally sure this is what is happening in your case, but I do this by accident often en... | Keyboard input not displayed on the screen? |
1,455,402,031,000 |
I have some HTTP requests in raw format such as
GET /docs/index.html HTTP/1.1
Host: www.nowhere123.com
Accept: image/gif, image/jpeg, */*
Accept-Language: en-us
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
(blank line)
I have to test and debug them for this reason I ne... |
I suggest telnet: telnet www.nowhere123.com 80 and you are talking raw to the server.
Example:
telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET /index.htm
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1... | How to make an HTTP request from raw data? |
1,455,402,031,000 |
What kinds of files are okay to delete in /usr directory without blowing up the server?? Is it possible to increase the size of /usr directory without blowing up server?
|
The /usr directory usually contains the /usr/share/doc directory tree which contains just documentation files. That should be fairly safe to move elsewhere or outright delete in case of emergency.
But you should use something like du -kx /usr | sort -rn | less to list the directories in the /usr filesystem in order o... | My /usr directory is 100% full. Unable to download packages |
1,455,402,031,000 |
I was skimming over the documentation of find to better utilize the command usage.
I was reading the part that says
GNU find will handle symbolic links in one of two ways; firstly, it
can dereference the links for you - this means that if it comes across
a symbolic link, it examines the file that the link points ... |
Gnu find documentation is not as strict in terminology as the POSIX one. The latter sheds light and I will refer to it. It doesn't define -iname so I will concentrate on -name. I assume -iname is designed to be like -name, only case-insensitive. Therefore I expect all properties of -name that have nothing to do with c... | find and symbolic link |
1,455,402,031,000 |
The following error occurs while using the below commands.Guide me to overcome this issue.
rpasa-vd1-363: cd /home/rpasa/DDEMO
No more processes.
|
You have hit our per-user process limit and you will have to talk to your system administrator to find out how many process you have running under your user account or you can try and run the ps command to see what processes you are running.
| Why the following error occurs in the terminal while using linux commands? |
1,455,402,031,000 |
I'm looking at the mail command which fires off Heirloom Mail.
My procmail failed and it has 55 messages in the queue.
I need to forward them out to another email and then process them manually.
I'm not sure how to get them from the Linux server out to my email though.
|
I discovered that I had to "set forward-as-attachment" then I could forward out the mail...
| Is there any way to forward mail from the command line in Linux |
1,455,402,031,000 |
The following command takes about 10 minutes to output the result
find . -name "muc*_*_20160920_*.unl*" | xargs zcat |
awk -F "|" '{if($14=="20160920100643" && $22=="567094398953") print $0}'| head
How can I improve its performance?
|
As noted in comments zgrep is better choice for such kind of tasks with globstar option which allows to use ** as all path inside the directory except hidden
shopt -s globstar
zgrep -m 10 '^\([^|]*|\)\{13\}20160920100643|\([^|]*|\)\{7\}567094398953' ./**muc*_*_20160920_*.unl*
shopt -u globstar
| How can I optimize this Unix command? |
1,455,402,031,000 |
I have a file with spelling mistakes in it. It has a lot of mistakes I need to find all mistakes and correct them.
I used :
spell [filename]
it shows me spelling mistakes
thiis
iz
wurse
...
and many others.
How can I correct all mistakes in one command?
|
I couldn't find a man entry for spell, or ispell, but I did find a ComputerHope entry, which I'll quote:
spell is essentially a wrapper for the much more complex ispell
utility. However, unlike ispell (or the very similar GNU program,
aspell), spell does not make any spelling suggestions. It only reports
which ... | Spelling mistakes in the file? |
1,455,402,031,000 |
Objective: I am trying to set up a 3G connection using NetworkManager 0.9.4 via command line. I have previously succeeded (see this question) by setting up the connection through the nm-applet (GUI in X) but now I need to replicate this on many machines and therefore want to do it via command line as part of an instal... |
The NetworkManager.conf man page notes of the base config file plugin:
For security, it will ignore files
that are readable or writeable by any user or group other than root.
In this case the result is "Unknown connection". chown your connection to root and chmod it 0600 to match those created by NetworkManager.
M... | Manual creation of NetworkManager connection file fails (Error: Unknown connection) |
1,455,402,031,000 |
Knowing that "How to convert from text to .pdf" is already well answered here link and here link, I am looking for something more specific:
Using Claws-Mail [website] and a Plug-In [RSSyl] to read RSS feeds I collected a lot of text files. These I want to convert into .pdf files.
Problem: The files inside the folders ... |
If you have a relatively simple file tree where you have only one level of directories, and where each directory contains a list of files but there are no sub directories, you should be able to do something like this (you can paste this directly into your terminal and hit Enter):
for dir in *; do ## For each direct... | convert bulk of text files to pdf with naming based upon header file |
1,455,402,031,000 |
I have a Debian Squeeze variant (MintPPC 9) installed on an old Mac Powerbook G4 (PowerPC CPU). I wish to boot it into a multiuser CLI login shell instead of automatically booting into the login screen for LXDE. I do, however, wish to keep GDM or whatever DM is used by LXDE since I also use it to switch between LXDE a... |
The extra options in grub on the kernel line are in fact kernel boot options passed across to the kernel when loaded.
So if you are referring to appending text to the grub line in Ubuntu, then the same config should be able to be used for mint and passed to the kernel by Yaboot.
It looks like Yaboot supports an appen... | Configuring Yaboot and Debian to Boot into a Command Line Login Shell? |
1,455,402,031,000 |
With this plugin we can fuzzy search through candidates of apt packages.
the output of running it as below:
# apt zzuf zziplib-bin zytrax
The code in the link (I put if [[ "${BASH_<...> fi to a function my-fuzzy-test):
#!/usr/bin/env bash
function insert_stdin {
# if this wouldn't be an external script
# we ... |
That Ctrl-R widget uses zle vi-fetch-history to insert history matches, which is not applicable to what you're doing here.
What you need to do is insert the matches you've generated into the editing buffer, as is done by another widget in the same code over here: https://github.com/junegunn/fzf/blob/master/shell/key-b... | Populate selected candidates to terminal after fuzzy search with fzf via keybinding? |
1,455,402,031,000 |
I'm currently trying to make a tar backup to a tape with mbuffer acting as a buffer between e.g:
tar --acls -c /var/test | mbuffer -m 8G -P 100% -R 100M | dd of=/dev/nst0 bs=256k
But the buffer is still empty about 10-20 times. So I wanted to use a file based buffer with the following command:
tar --acls -c /var/test... |
no file is created
mbuffer -m 60G -T /srv/testbuffer creates a file, opens it and unlinks it right after. If you check the file descriptors in /proc/<PID of mbuffer>/fd you will find one that points to
/srv/testbuffer (deleted)
This is quite a standard trick when it comes to temporary files. If mbuffer terminates f... | How does `mbuffer -T` work? |
1,455,402,031,000 |
I've followed the instructions provided on the wp-cli.org site but I can't seem to get the wp command to run for all users.
I copied the file to /usr/local/bin and renamed it to wp per the instructions. And when I'm logged in as root I can run wp from anywhere and it works (although it gives me the "are you sure you w... |
I determined that the issue was related to cageFS.
Solution
If the server environment is using CloudLinux with cageFS enabled, cageFS definitions must be updated to allow the wp command to be accessible to non-root users
I found these instructions here to do this: https://docs.redy.host/knowledge-base/install-wp-cli-c... | How do I install WP-CLI for all users on centOS 7 |
1,461,781,712,000 |
I have Okular configured that when it's already running and I open a pdf from the command line, it should open the new file as a new tab in Okular.
However, if this new file is in another directory than the other one, Okular fails to open the document and only displays an empty tab with the file name and the error mes... |
Workaround: Open additional pdf files either using the absolute path names or relative path names to the initial pdf file.
So for example
okular foo.pdf &
okular ../foobar.pdf
and
okular foo.pdf &
okular /the/complete/absolute/path/to/foobar.pdf
both work.
//Update:
To automate the workaround, this function can be a... | Open multiple pdfs in Okular from command line |
1,461,781,712,000 |
Given a list of file names, how can I sort it by file modification time?
The resulting output needs to look exactly like the input with the exception that the data has been sorted accordingly.
Here is a sample of the input.
/jobs/crm/import/done/20140227-1359-0009.txt
/jobs/bridge/open-workitem/done/20140227-1359-0009... |
Assuming your input is small, and the file names don't contain spaces or other weird characters, you can just use ls.
ls -dt $(cat files)
$(cat files) puts the contents of files on the command line, and splits them on whitespace to get a list of arguments. ls -t takes a list of files as its arguments, sorts them by ... | How to sort a list of files by time, given only the filenames |
1,461,781,712,000 |
I am planning to analyze audio via linux command line.
There are a lot of analyzers out there which have a graphical interface, but since I want to make an automated input/output of this information I can't use a GUI.
The optimal case would be to send an audiostream from an embedded device to powerful machine, which a... |
Command-line batch audio processing tools are sox(http://sox.sourceforge.net/) and ecasound(http://www.eca.cx/ecasound/). You may want to check man soxformat for the list of supported formats (i.e. streaming and file formats). It may be also beneficial to consider including ffmpeg(see http://ffmpeg.org/ffmpeg-all.html... | Is there a command line tool for analyzing audio frequency |
1,461,781,712,000 |
I like the command line because it preserves the context of what I'm doing. But if I use a "rogue" mode program like vi or less, the whole screen gets taken over.
Is a middle way possible, where the console mode program takes over only half the screen (above or below the shell part)?
I'm borrowing the term "rogue" fro... |
I guess you could run your full-screen program in tmux or Screen pane directly, without additional shell session (shell is just another program).
Another way, which I prefer, is to use tiling/stacking window manager like i3 and terminal program urxvt. The latter has very fast daemon/client structure, which allows open... | Is there any way to have console (rogue) mode programs take over only part of the terminal screen? |
1,461,781,712,000 |
I need to count the number of files under a folder and use the following command.
cd testfolder
bash-4.1$ ls | wc -l
6
In fact, there are only five files under this folder,
bash-4.1$ ls
total 44
-rw-r--r-- 1 comp 11595 Sep 4 22:51 30.xls.txt
-rw-r--r-- 1 comp 14492 Sep 4 22:51 A.pdf.txt
-rw-r--r-- 1 comp 8160 Sep... |
wc is a char, word, and line counter, not a file counter.
You, the programmer/script writer, are responsible for making it count what you want and to adjust the calculation accordingly.
In your case, you could do something like:
echo $((`ls|wc -l`-1))
Finally note that your ls is probably an alias as it gives a long ... | The result of "ls | wc -l" does not match the real number of files [duplicate] |
1,461,781,712,000 |
In the following code, I have to poll $tmp_input to continue executing the code because wezterm cli send-text is asynchronous. This makes sure that $tmp_input is ready.
tmp_input=$(mktemp ./tmp_input.XXXXXX)
echo "read input; echo \$input > $tmp_input" | wezterm cli send-text --pane-id $bottom_pane_id --no-paste
whi... |
You could create a named pipe with mkfifo instead, and read that. Reads will block until something has written to the pipe, no manual polling required. Something like:
tmp_input=$(mktemp -d ./tmp_input.XXXXXX)
mkfifo "$tmp_input/fifo"
echo "read input; echo \$input > $tmp_input/fifo" | wezterm cli send-text --pane-id... | Alternatives to file polling? |
1,461,781,712,000 |
A coworker recently asked "What is man"? After being informed that not all things accessible from the Bash CLI are commands, I was wary to call man a command.
man man just calls it an interface:
NAME
man - an interface to the on-line reference manuals
man has an executable:
$ which man
/usr/bin/man
$ file /usr... |
I have a small shellscript, that can help me identify a command: what kind of command it is and if installed via a program package, which package. Maybe use the name what-about,
#!/bin/bash
LANG=C
inversvid="\0033[7m"
resetvid="\0033[0m"
if [ $# -ne 1 ]
then
echo "Usage: ${0##*/} <program-name>"
echo "Will try to ... | How to know what are commands, system calls, bash built-ins, etc? |
1,461,781,712,000 |
I recently installed Debian for CLI purposes.
I am looking to install CLI packages, I want to know how to search for packages (CLI packages such as nano)?
|
To find CLI packages in Debian, you can look for packages tagged as interface::command-line, either using the tag search engine, or on your system by installing debtags and running
debtags search interface::command-line
Both approaches have options to refine the search. See the Debtags wiki page for more details.
Thi... | How to search for Debian CLI packages? |
1,461,781,712,000 |
I want to use grep to determine how many characters should be displayed before and after what is being searched.
For example I want to filter 'example' from the 'this is an example' line.
By using grep example the result would be all the line containing the string, when what I hope to obtain is just "an example", two ... |
there are grep options
grep -Eo '...example' test.txt
where
-E use extended regular expression
-o ouput only matched string
... means any 3 character
both option can be merge as -Eo
' ' enclose patern to avoid shell subsitution
As sugested, alternative for 3 or less caracter
grep -Eo '.{,3}example' test.txt
where... | How to find word with part of surrounding context using grep? |
1,461,781,712,000 |
I have a bunch of text files in the following format:
Lorem ipsum dolor sit amet,
consetetur sadipscing elitr,
sed diam nonumy eirmod tempor
invidunt ut labore et dolore
magna aliquyam erat, sed diam
voluptua. - At vero eos et accu-
sam et justo duo dolores et ea
rebum. - Stet clita kasd guber-
gren, no sea takimata s... |
Using awk:
awk -F'-$' '{ printf "%s", sep $1; sep=/-$/?"":OFS } END{ print "" }' infile
with the -F'-$', we defined the Field Separator to single hyphen at the end of line, so with this and by taking the first field $1, we will always have the line without that hyphen for those line having this hyphen or still entire... | Bash - remove dashes and new-lines before replacing new-lines with spaces |
1,461,781,712,000 |
Is there a pkill-like tool which does this:
send signal to all matching processes
wait N seconds until the processes have terminated
if all processes have terminated, nice: exit
if some processes have not terminated send SIGKILL
For me it is important that the tool waits until the processes have really terminated.
I... |
There is no “standard” command which provides the behaviour you’re after. However, on Debian and derivatives, you can use start-stop-daemon’s --stop action with the --retry option:
start-stop-daemon --stop --oknodo --retry 15 -n daemontokill
will send SIGTERM to all processes named daemontokill, wait up to 15s for th... | pkill which waits |
1,461,781,712,000 |
I am trying to copy a file to 10 files. Say for example I have a E-mail message named test1.eml. I want 10 copies of the same file.
When I searched in internet, I came across this stackoverflow thread https://stackoverflow.com/questions/9550540/linux-commands-to-copy-one-file-to-many-files and followed the eval comma... |
I would do something like for i in {2..10}; do cp test1.eml test$i.eml; done
Yet is more or less the same thing.
| Alternate solution for making multiple copies of a single file using command line? |
1,461,781,712,000 |
I want to grep for a word in a file in the last n lines without using the pipe.
grep <string> filename
enables to search the filename for a string. But, I want to search for a string in the last N lines of the file. Any command to search for that without using the pipe?
|
If your shell supports it (zsh, bash, some implementations of ksh), you could utilise process substitution
grep <pattern> <(tail -n5 yourfile.txt)
Where -n5 means get the five last lines.
Similarly,
grep <pattern> <(head -n5 yourfile.txt)
would search through the 5 first lines of yourfile.txt.
Explanation
Simply s... | Grep for a string in file without using pipe |
1,461,781,712,000 |
when I do ls the output is in columns, however I need the output to be in only one column, line by line, one entry per line.
So the only way I could come up with is:
echo * | xargs -n1 echo
Is this the standard way to achieve it or is this bad style?
|
That's bad, for all the reasons plain xargs is bad, namely it breaks with filenames containing whitespace or backslashes:
$ touch "foo bar"
$ echo * | xargs -n1 echo
foo
bar
Besides, it runs a copy of (the external) echo command for every file.
In most shells you could use printf "%s\n" * to get the listing. Or ls -1... | echo * | xargs -n1 echo , Is there a shorter, more elegant way of a line by line listing? |
1,461,781,712,000 |
When I write the code the way below, I am able to run several commands after the else statement:
if [ "$?" -eq 0 ]
then
echo "OK"
else
echo "NOK"
exit 1
fi
However, when I use another syntax I am unable to union 2 commands after the OR:
[ "$?" -eq 0 ] && echo "OK" || (ec... |
The pair of ( ) spawns a subshell, defeating the goal of exiting the whole script with the exit command inside.
Just replace the ( ) with { } (and adjusted syntax because { } are not automatical delimiters but more treated like commands: a space after { and last command inside must end with some terminator:; fits): t... | Union commands after the || (OR) operator |
1,461,781,712,000 |
I was wondering, is there any way to kill a process that is running on a specific IP and port on Ubuntu 14.04 on a local IP and port? Preferably, this would be in one command, but if not, a bash script would be perfectly fine as well.
|
There are likely cleaner ways, but something along the lines of:
netstat -lnp | grep 'tcp .*127.0.0.1:9984' | sed -e 's/.*LISTEN *//' -e 's#/.*##' | xargs kill
| How can I kill a process running on a specific IP and port? [closed] |
1,461,781,712,000 |
Resolution: the files were saved with CR rather than LF line breaks.
Mosvy pointed this out, but only posted as a comment, rather than an answer, so I am unable to officially thank him for helping me to find the cause and solve the problem.
Thanks mosvy, if you come back please post as an answer so I can give you a th... |
The OP's problem was caused by file file using CR (\r / ascii 13) instead of LF (\n / ascii 10) as line terminators as expected by sed. Using CR was the convention used in classic MacOS; as a non Mac user, the only use of it I've met with in the wild in the last two decades was in PDF files, where it greatly complicat... | Does AWK have similar ability as SED to find line ranges based on text in line rather than line number? |
1,461,781,712,000 |
I've extracted strings I'm interested in from another file and now have a list like this:
StringA
StringB
StringA
StringA
StringB
StringC
StringB
How can I extract the number of occurrences each string has using common command-line tools?
I would like to end up with a list like this:
StringA 3
StringB 3
StringC 1
|
Use:
sort file | uniq -c
Looks simple?
| Count number of string occurrences [duplicate] |
1,461,781,712,000 |
For example, from this file:
CREATE SYNONYM I801XS07 FOR I8010.I801XT07
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
CREATE SYNONYM I801XS07 FOR I8010.I801XT07
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
Table altered.
Table ... |
Supposing you're on an elderly system, like HP-UX, that doesn't have GNU utilities, just the old, original BSD or AT&T "grep". You could do something like this:
#!/bin/sh
awk '/ORA-/ { print line1; print line2; print line3; print line4; print $0 }\
// {line1 = line2; line2 = line3; line3 = line4; line4 = $0}' $1
Ye... | Show lines matching a pattern and the 4 lines before each |
1,461,781,712,000 |
I'm trying to remove a file and I keep getting a message similar to:
[1] 12345
and nothing happens, I run a directory search (dir) and the file remains and I get a stopped message
|
You are removing a file with an & character in the name, and the rm command is being put in the background. (For the record, the 1 is the job number, and the 12345 is the process ID)
It is important to quote or escape any filenames that contain special characters. A good rule of thumb is: if you think something might ... | rm command returns a message [1] 12345 What does this mean? |
1,461,781,712,000 |
I want to separate a long path to multiple lines, like this:
cd foo1/foo2/foo3/foo4/bar
to
cd foo1\
foo2\
foo3\
foo4\
bar
|
You could do this with an array but the cd command looks a bit complicated:
path=(
foo1
foo2
foo3
foo4
bar
)
cd "$(IFS=/; echo "${path[*]}")"
Array literals allow for arbitrary whitespace.
| How can I separate a long path into multiple lines? |
1,461,781,712,000 |
I want to set a variable if my condition is true on my Ubuntu system.
This proves that my if-statement is correct:
$ (if [ 1 == 1 ]; then echo "hi there"; fi);
hi there
This proves that I can set variables:
$ a=1
$ echo $a
1
This shows that setting a variable in the if-statement DOES NOT work:
$ (if [ 1 == 1 ]; the... |
The (...) part of your command is your problem. The parentheses create a separate subshell. The subshell will inherit the environment from its parent shell, but variables set inside it will not retain their new values once the subshell exits. This also goes for any other changes to the environment inside the subshel... | Set variable conditionally on command line [duplicate] |
1,461,781,712,000 |
I've gotten used to using grep for my command line searches and wanted to know how to successfully do a search using the result of another search.
Here's my attempt, where I am looking for 'tool' within my result:
grep tool | grep -rl embed=
This returns some results and then the console hangs. Are there any simple/e... |
Pipelines run from left to right. More precisely, the processes run in parallel, but the data flows from left to right: the output of the command on the left becomes the input of the command on the right.
Here the command on the left is grep tool. Since you're passing a single argument to grep, it's searching in its s... | Search within a search |
1,461,781,712,000 |
# ldd /usr/bin/ffmpeg
linux-vdso.so.1 => (0x00007ffffc1fe000)
libavfilter.so.0 => not found
libpostproc.so.51 => not found
libswscale.so.0 => not found
libavdevice.so.52 => not found
libavformat.so.52 => not found
libavcodec.so.52 => not found
libavutil.so.49 => not found
libm.so.6... |
The best solution for this is to use awk:
$ ldd /usr/bin/ppdhtml | awk '/ => / { print $1 }' | head -n1
libcupsppdc.so.1
To do this using grep, you will need to use the lookahead and lookbehind features of PCRE:
$ ldd /usr/bin/ppdhtml | grep -Po '(?<=\t).+(?= => )' | head -n1
libcupsppdc.so.1
The lookahead and lookb... | How to perform grep onto the output of ldd properly ? |
1,304,454,439,000 |
I watched a video lecture today that introduced C and things like how to make a C program that will run in Linux. I followed the steps given and now I'm stuck with a bit of a problem.
I created my C file (HelloWorld.c) and used the command gcc -o HelloWorld HelloWorld.c to compile the file, both of these steps were su... |
You don't have the value of the PATH environment variable set to include whatever directory the HelloWorld executable file lives in.
Supposing you have used cd to get to the directory, you can run HelloWorld with this command: ./HelloWorld
Unix shells have a variable called PATH, which is a :-delimited list of directo... | Running C Programs on Linux |
1,304,454,439,000 |
I have a while loop in my script which waits for the connection get online and then continues.
#!/bin/sh
while ! ping -c1 $1 &>/dev/null
do echo "Ping Fail - `date`"
done
echo "Host Found - `date`"
It takes 25 to 45 seconds for the connection to reconnect. I cannot let it wait for any longer than 50 seconds.... |
Without a while loop:
# -W 50 = timeout after 50 seconds
# -c 1 = 1 packet to be sent
response="$(ping -W 50 -c 1 "$1" | grep '1
packets transmitted, 1 received')"
if [ "$response" == '' ] ; then
echo no response after 50 seconds
else
echo connected
fi
| Bash: Timer in while loop |
1,304,454,439,000 |
On Linux, is there a way to sort ls output by users? What I try to achieve is something like this:
user_a file1
user_a file2
user_b another_file
user_c this_file
user_c that_file
user_d file3
I am aware that a listing like this would also contain file size, permissions etc. – my main concern is the sortin... |
Determining which column the owner name is in from a single ls -l output without knowing which is which is not possible. You could try to match the entries in each column with the passwd file, but there is no guarantee that you would not be matching the group column or the filename column both which could only contain... | sort ls output by users |
1,304,454,439,000 |
If I want to open all mp4 files in a directory, I can simply do something like totem *.mp4. But how can I open all mp4 and all flv files in that directory with one command. I.e. I want to do something like this totem (*.mp4 OR *.flv). What's the easiest way to do this? Perhaps it helps that I am using zsh.
|
Simply call
totem *.mp4 *.flv
Too easy, isn't it ;-)
| Fastest way to open all files in a directory with multiple file extensions on commandline |
1,304,454,439,000 |
I'm working with graphic design. I've downloaded many files (EPS files, PSD files, etc) from various websites.
Because it come from various websites, after downloaded from more than 10 different websites, I got many same files with same size, and same everything but different file name (2 to 4 copies for same file). T... |
This command will rename all files to the md5sum of their content. That means files with the same content will get the same name.
for f in *; do mv $f $(md5sum $f | cut -d " " -f 1); done
You can replace md5sum with sha1sum in the command.
For this demonstration I added -v to mv so we can see what is being renamed.
$... | remove duplicates by renaming identical fles to same name |
1,304,454,439,000 |
This is my current prompt definition:
PS1=$'%F{063}%1~%f %(1v.%F{099}%1v %f.)%F{063}%%%f '
RPROMPT='$VIMODE %m'
and I'm working on integrating this. Basically I'm starting to find it very unreadable.
Is there any way that I can make it multiline in a way perhaps similar to what Perl can do with regex's (e.g., what /x... |
With Zsh 4.3.11, you can use the Z parameter expansion flag to split a string value according to the normal shell parsing rules while discarding comments (C option to Z) and treating newlines as normal whitespace instead of replacing them with semicolons (n option to Z). You can then stitch the results back together (... | Is there a way to make the prompt definition multiline? |
1,304,454,439,000 |
I need to run a command that looks like this
mycli --file test.zip --file another_test.zip
How could I run that dynamically with all zip files in a directory? I'm sure I could pipe the files from a find command, but I don't know how to actually append them as arguments to another command and my bash-fu is not great
|
Using an array:
unset -v args
declare -a args
for file in *.zip
do
args+=( --file "$file" )
done
mycli "${args[@]}"
Or, POSIXly:
set --
for file in *.zip
do
set -- "$@" --file "$file"
done
mycli "$@"
Or, assuming GNU tools:
find . -maxdepth 1 -name '*.zip' -printf '--file\0%f\0' |
xargs -0 -- mycli
A relevant... | Append all files in a directory as cli arguments |
1,304,454,439,000 |
I have multiple files(100-1000) in foo dir. I want to append each filename to its own content. I think the for loop should resolve appending a random string to for each file,
for f in *; do printf "%10s \n" $(shuf -i 50-100 -n 50 -r) >> $f; done
How can I append filename to all this shuffled numbers, directly concata... |
Ok, if I get it right, you want to prefix a fixed string to all numbers printed by shuf. If so, just add that string to the start of the printf format string:
$ printf "x%10s\n" $(shuf -i 50-100 -n 3 -r)
x 71
x 70
x 92
Change the %10s to %s get them back to back without the whitespace. Similarly,... | How to print filename into itself |
1,304,454,439,000 |
After installing microk8s (Micro Kubernetes) on my local machine, one of the commands I encountered was microk8s.enable dns which can also be run as microk8s enable dns. This doesn't seem to be a universal thing. git status is a valid command but git.status is not. How do Linux systems support such type of command str... |
You'll sometimes see programs (and scripts) inspect the name of the file that was used to invoke the program and condition behavior off of that.
Consider for example this file and symbol link:
$ ls -l
-rwxr-xr-x ... foo
lrwxr-xr-x ... foo.bar -> foo
And the content of the script foo:
#!/bin/bash
readonly command="... | Does Bash support command.subcommand structure in addition to command subcommand structure? If yes, how to incorporate this in bash scripts? |
1,304,454,439,000 |
Given a bash variable with the value 2019-08-15, is there some utility that can convert that date to the format August 15, 2019?
|
On Linux, or any system that uses GNU date:
$ thedate=2019-08-15
$ date -d "$thedate" +'%B %e, %Y'
August 15, 2019
On macOS, OpenBSD and FreeBSD, where GNU date is not available by default:
$ thedate=2019-08-15
$ date -j -f '%Y-%m-%d' "$thedate" +'%B %e, %Y'
August 15, 2019
The -j option disables setting the system ... | How to convert 2019-08-15 date format to August 15, 2019 in the command line? |
1,304,454,439,000 |
I see people running shell scripts by typing ./scriptname. Now this seems to be the default way, since I have seen it so often, however occasionally, but not rare, I see them type sh scriptname. Is it just a matter of preference or is there a more significant difference between ./ and sh ?
|
There are a few differences.
./scriptname
requires that the file called scriptname be executable, and it uses the shell specified as its first line (in the “shebang”, e.g. #!/bin/sh), if any.
sh scriptname
works as long as the file called scriptname is readable, and it uses sh (whatever that is) regardless of what t... | What is the difference between sh and ./ when invoking a shell script? [duplicate] |
1,304,454,439,000 |
I have text-files containing many lines, of which some starts with ">" (it's a so-called *.fasta file, and the ">"s marks the beginning of a new information container):
>header_name1
sequence_info
>header_name2
sequence_info
I want to add the name of the file these lines are located in to the header. For example, if ... |
This should do the trick. I break the filename at the underscore to get the numerical prefix, and then use a printf to zero-pad it out to a three digit string.
for file in *.fasta; do
prefix="$(printf "%03d" "${file%%_*}")"
sed "s/^>/>$prefix-/" "$file" > "${prefix}_tagged.fasta"
done
| Wrapping a loop around a 'sed'-command processing many files in a single directory |
1,304,454,439,000 |
I use the following command to convert my input file contents to lowercase
tr A-Z a-z < input > output
This command works fine.
But when I try to store the output in input file itself, it is not working.
The input file is empty after executing the command. Why?
tr A-Z a-z < input > input
|
But when I try to store the output in input file itself, it is not working. The input file is empty after executing the command. Why?
Because the > input causes the shell to truncate the file before the tr command is run. Incidentially, you can get around this with more advanced descriptor handling in Bash:
exec 8<>... | Convert file contents to lowercase and store result in same file [duplicate] |
1,304,454,439,000 |
I'd like to schedule 8 curl commands over the next 12 hours. I was wondering if there's a way to do with with 8 single-line calls to at. Sorta like:
$ at now + 1 min "curl -X POST 'http://localhost:5566/export/778'"
or
$ at now + 1 min -- curl -X POST 'http://localhost:5566/export/778'
But neither of those work.... |
A portable way is:
$ echo "curl -X POST 'http://localhost:5566/export/778'" | at now + 1 min
| Is it possible to specify an at command on a single line? |
1,304,454,439,000 |
For example, a file file1.txt contains
Hi how are you
hello
today is monday
hello
I am fine
Hi how are you
After the processing of file1.txt it should write to file2.txt and contents should be like this without repeating the same lines.
Hi how are you
hello
today is monday
I am fine
What comm... |
This is an easy job for sort, use the unique (-u) option of sort:
% sort -u file1.txt
hello
Hi how are you
I am fine
today is monday
To save it in file2.txt:
sort -u file1.txt >file2.txt
If you want to preserve the initial order:
% nl file1.txt | sort -uk2,2 | sort -k1,1n | cut -f2
Hi how are you
hello
today is mon... | How to write contents of a file to new file removing repeated lines [duplicate] |
1,304,454,439,000 |
I'm going to config my network interfaces and run this command:
auto eth0
but it returns -bash: auto: command not found. It seems I've missed something which I don't know. Any idea? What should I install?
|
auto eth0 is interfaces(5) syntax. It's a line you would add to /etc/network/interfaces, not a command to be run in a shell. Once you correctly configure the interface in /etc/network/interfaces, you can run the ifup/ifdown commands to apply them.
| -bash: auto: command not found |
1,304,454,439,000 |
I've script which is connecting to remote host via SSH, creates temporary file and executing the following command:
Calling system(mysql --database=information_schema --host=localhost < /tmp/drush_1JAjtt)
Each time it's creating different file (pattern: drush_xxxxxx).
I've tried couple of times manually running on t... |
If the file is created for enough short amount of time, you can run the following command on separate terminal before running the script:
while true; do cat /tmp/drush_* 2>/dev/null && break; done
Where /tmp/drush_* is your pattern. The advantage is that it's quick and you don't have to install any external tools (if... | How to access temporary file straight after creation? |
1,304,454,439,000 |
I often mistype a command. So I will type this
sublimetext myfile.txt
instead of
git add myfile.txt
When I do this, I hit up to restore the last command. But after doing so, my cursor is at the end of the previously typed line. Is there a keyboard short cut to jump back to the prompt?
|
On bash command line, I use ctrl+a to go to the beginning of command and ctrl+e to go to the end of command.
| keyboard shortcut to jump cursor to prompt? |
1,304,454,439,000 |
Where can I find more information about the command(?) print since I don't receive a result when I input man print? For example, in the zsh I can do the following:
$ print "Hello, world\!"
Hello, world!
I've seen print -P foo and print -n bar used among other flags and have no idea what they mean nor do I know where ... |
In zsh, at the prompt, type print, and then Alt-H.
If it gives you the man page for the print system command instead of the print builtin, you may want to follow the instructions given under Accessing On-Line Help at:
info zsh Utilities
For zsh documentation, I prefer to use info in general. The zsh documentation is ... | How can I `man print`? |
1,304,454,439,000 |
I am running a program fls (from the Sleuth Kit) with option -v for verbose mode. However it takes too long, and the program is still running since yesterday. I guess it will run faster without verbose mode, but I am not sure how long it takes to finish running and whether it is worth to stop and rerun it without ve... |
As lynxlynxlynx points out, unless the program author makes provisions for it, you cannot change the verbosity while the program is running, but you can keep it from printing to a terminal in case that is a bottle neck.
To do this, close the terminal after telling the shell not to send a SIGHUP. Most shells will send ... | Is it possible to disable verbose in the middle of running? |
1,304,454,439,000 |
I installed VLC through terminal but it shows:
bash: /snap/bin/vlc: No such file or directory
I also tried:
which vlc
and it showed:
/usr/bin/vlc
When I try to run it through sudo su, it shows this error:
VLC is not supposed to be run as root. Sorry.
If you need to use real-time priorities and/or privileged TCP por... |
You should run
$ /usr/bin/vlc
As for why executing vlc looks for /snap/bin/vlc, I wouldn't know.
If you had a snap for vlc installed, I guess it should have worked as well.
Perhaps you have an alias set in your ~/.bashrc or elsewhere.
If you find such an alias, and remove it, you could probably start running vlc with... | VLC doesn't open through terminal or GUI |
1,304,454,439,000 |
I use grep to get the output of mysqladmin as
sudo mysqladmin ext -i10 | grep 'buffer_pool_pages_flushed'
and the output is continuous (every 10 seconds) as
| Innodb_buffer_pool_pages_flushed | 265708726 |
| Innodb_buffer_pool_pages_flushed ... |
Append:
| awk '{if(NR>1){print $4-last,"("$4"-"last")"} last=$4}'
Output:
26939 (265735665-265708726)
16047 (265751712-265735665)
2864 (265754576-265751712)
19804 (265774380-265754576)
| How to subtract number in previous line from current line's using grep? |
1,304,454,439,000 |
I have a directory structure as follows:
dir
|___sub_dir1
|_____files_1
|___sub_dir2
|_____files_2
|___sub_dirN
|_____files_N
Each sub_directory may or may not have a file called xyz.json. I want to find the total count of xyz.json files in the directory dir.
How can... |
You can use :
find path_to_dir -name xyz.json | wc -l
| get count of a specific file in several directories |
1,304,454,439,000 |
I'm writing a script to configure new debian installs while finding the best solution to confirming that a user exists in the script, the best way I found gives me wierd output.
PROBLEM:
id -u $var and id -u $varsome give the same output even though
var has a value (the username) and varsome has no value
[19:49:24]... |
Since the variable expansion wasn't quoted, the empty word that results from $varsome being expanded is removed completely.
Let's make a function that prints the number of arguments it gets and compare the quoted and non-quoted case:
$ args() { echo "got $# arguments"; }
$ var=""
$ args $var
got 0 arguments
$ args... | id -u $var gives the same output if $var has a value or not |
1,304,454,439,000 |
I'm trying to do simple grep and grep -v so I will get the lines from a.txt that exists in b.txt and not in c.txt.
Example of 3 files
a.txt:
a
b
c
d
e
up.txt:
a.up
b.up
c.up
dw.txt:
a.dw
b.dw
Desired output:
c
I wrote the below code but the grep looks on the $(sed...) as one single line at a time and not as a who... |
Assuming the files are all sorted and that we're using a shell that understands process substitutions (like bash):
$ join -t . -v 1 -o 0 <( join -t . a.txt b.txt ) c.txt
c
or, for other shells,
$ join -t . a.txt b.txt | join -t . -v 1 -o 0 - c.txt
c
This uses join twice to perform relational joins between the files.... | grep lines that exists on one file but not in the other |
1,304,454,439,000 |
This has long puzzled me and this seemed like the best venue to solicit the perspective of those with far more POSIX time-in-grade than I have. I consider the parsing of ls output in this manner to be crucial and creating aliases to modify the ls command to default to it is always one of the first customizations I mak... |
This was discussed when the option was added to ls; Jim Meyering said
Just one little question about this patch: are you sure not to add a
short option for --group-directories-first ?
For now, yes. It would take a strong argument to go against the
“no new short option names” policy for ls, especially conside... | Why has the --group-directories-first switch for the ls command never evolved to have a short form as well? |
1,304,454,439,000 |
I want to delete all hidden directoris from a directory and its sub-directory.
I also use rm -rf .directory_name this command is iterative command I want to a recursive command.
Please anybody help me??
|
It sounds like you want something like this (although it's not clear what you mean when distinguishing "iterative command" from "recursive command", since rm -rf is both recursive and iterative):
LC_ALL=C find . -name '.?*' -type d -exec echo rm -rf {} +
Once you're happy, remove echo from the option arguments to -ex... | Recursively delete hidden directory & its files? |
1,304,454,439,000 |
I find myself doing this often enough that I wonder if there's a standard Unix way to do it:
% mkdir -p /TARGETDIR/relative/path/to
% cp ./relative/path/to/somefile /TARGETDIR/relative/path/to
In other words, I don't want to just copy somefile to /TARGETDIR, but actually I want to copy its entire relative path.
Is th... |
With GNU coreutils (non-embedded Linux, Cygwin):
cp -p --parents path/to/somefile /TARGETDIR
With the POSIX tool pax (which many default installations of Linux unfortunately lack):
pax -rw -pp relative/path/to/somefile /TARGETDIR
With its traditional counterpart cpio:
find relative/path/to/somefile | cpio -p -dm /TA... | Can one copy a relpath in one command? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.