date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,304,454,439,000
I've typically have gnome-terminal open with ~8 tabs, using 2 consecutive tabs for the same task (one has emacs, the other is used to do git checkins and unittest runs and so). When changing tasks, I need to move to a new directory - in both tabs. How can I change the work directory of the second tab to the one of the...
Here is a work-around: on one tab, record the CWD into a temp file, on the other tabs, cd to the just-saved dir. I would put these two aliases to my .bashrc or .bash_profile: alias ds='pwd > /tmp/cwd' alias dr='cd "$(</tmp/cwd)"' the ds (dir save) command marks the CWD, and the dr (dir recall) command cd to it. You c...
Change working directory of 2 terminals at once
1,304,454,439,000
Suppose I have the directories: /foo/ /A/B/C/foo/D/E/ /F/foo/G/H/foo/I/ How can get a result that lists all the directories whose basename exactly matches a given string (for example foo in here)? /foo/ /A/B/C/foo/ /F/foo/ /F/foo/G/H/foo/
You can use find: $ find / -type d -name foo -print
What is the best way to find directories that exactly match a string irrespective of the path?
1,304,454,439,000
As a linux user, I spend a lot of time mucking about in bash. I've always been a bit frustrated by how poor the readability is. Today this annoyed me enough to spur me into action. My immediate problem was solved by this snippet, which changes the directories colour to magenta. (Annoyingly, this caused me to lose all...
Maybe Solarized? http://ethanschoonover.com/solarized There's a bunch of projects that do similar terminal colorization schemes with an eye to usability.
How can I make bash more readable? [closed]
1,304,454,439,000
I'm seeing this in my .bashrc file: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\ [\033[01;34m\]\w\[\033[00m\]\$ ' and I have absolutely no idea what all those escapes codes mean.
There are three kinds of escape codes in there: bash parameter expansion, bash prompt expansion, and terminal escape codes. ${debian_chroot:+($debian_chroot)} means “if $debian_chroot is set and non-empty, then ($debian_chroot), else nothing”. (See /etc/bash.bashrc for how debian_chroot is defined. As the name indica...
Understanding escape codes
1,304,454,439,000
g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something This is from the Apache Thrift website. Also is the -I/usr supposed to be -I /usr?
Here is a breakdown of the command. First the original command, for reference g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something Now, for the breakdown. g++ This is the actual command command, g++. It is the program that is being executed. Here is what it is, from the man page: gcc - GNU project C an...
What does this Linux command do?
1,304,454,439,000
I have a file like this: x = { y = { z = { block = { line1 line2 line3 } } } } x2 = { y2 = { block = { line4 line5 } } } xyz block = { line6 } and so on. I need to revers...
If you are okay with Perl: perl -ne 'if($f && /}/){$f=0; print @blk}; $f ? unshift(@blk, $_) : print; if(/block = {/){$f=1; @blk=()}' ip.txt if(/block = {/){$f=1; @blk=()} initializes @blk array and sets the flag $f if input line contains block = { $f ? unshift(@blk, $_) : print if the flag is ac...
How to reverse lines inside repeated blocks in a text file (using sed/awk?)
1,304,454,439,000
I just learned about brace expansion and hoped I could make use of them to launch the same C++ program with different command line arguments. My code is run like this from the terminal: mpirun -n 1 main.exe 1 10 0.1 1 5 The numbers after main.exe are the input arguments of my program. I would like to do something lik...
No, that won't work. Brace expansions are expanded when you run the command. Only the brace expansion is affected, they don't cause you to run multiple commands. In your case, this: mpirun -n 1 main.exe 1 10 {0.1,0.2} 1 5 Will simply become this: mpirun -n 1 main.exe 1 10 0.1 0.2 1 5 If you want to run it twice, wit...
Brace expansion to run program multiple times with different arguments
1,304,454,439,000
When i update my OS, suddenly the resolution set's 1024 x 768, i do everything to change it back to 1920 x 1080 but nothing helps me, maybe someone know how can i solve this problem? In terminal screenfetch ./+o+- levon@levon-desktop yyyyy- -yyyyyy+ OS: Ubuntu 1...
I had the same issue and ,this was my configuration. so went to nvidia site (https://www.nvidia.in/Download/index.aspx?lang=en-in) and downloaded latest driver and manually installed it and after a reboot my issue seems to be solved.
Suddenly my resolution of screen changed and i can't reset it
1,574,366,215,000
I have a script myscript.sh #!/bin/sh echo $1 $2 which is used something like ... ./myscript.sh foo bar which gives me an output of ... foo bar but how can i make this script include custom command options? for example ... ./myscript.sh -a foo and corespond to $1 and ./myscript.sh -b bar and corespond to $2
Since you are listing bash as the shell used, type: $ help getopts Which will print something like: getopts: getopts optstring name [arg] Parse option arguments. Getopts is used by shell procedures to parse positional param...
How to include custom command options in a bash script with $1 and $2?
1,574,366,215,000
I am documenting some commands for future usage, some of them are too long and I want to document them in multiple lines for visualization, and then just copy and paste them for usage. For example: Raw: openssl pkcs12 -export -in intermediate/certs/lala-lira.cert.pem -inkey intermediate/private/lala-lira.key.pem -out ...
End every line but for the last with a backslash. To use your command as an example: openssl pkcs12 -export \ -in intermediate/certs/lala-lira.cert.pem \ -inkey intermediate/private/lala-lira.key.pem \ -out intermediate/private/lala-lira.pfx What you are doing here is escaping the end-of-line, causing the shell to t...
How to present a command in multiple lines for instant copy/paste usage?
1,574,366,215,000
I checked the od man page, but it does not explain this. What do the numbers on the left column of the od output mean?
This is actually mentioned in the info page for od (available by running info od or by visiting https://www.gnu.org/software/coreutils/manual/html_node/od-invocation.html#od-invocation which is also linked to at the end of the man page) file, albeit not in very much depth: Each line of output consists of the offset i...
What are those numbers on the left of od output?
1,574,366,215,000
In *nix, if I don't have a mouse, nor am I running a GUI, what can I do to copy from what is on the screen? Take this for example: What if I want to copy things from "Entering /mnt/..." to the last "}" Thanks for the answer Read a character from an x-y coordinate on the screen But something unique on Chromebook is th...
In such circumstances, script is very handy: it runs a shell, recording all the output. In your example, before entering the chroot you'd run script temp_file.txt and then sudo enter-chroot etc. On exit from the chroot, you'd exit again to exit script, and you'd find the text you wanted (along with everything else y...
How to copy from CLI without a GUI or a mouse
1,574,366,215,000
Here is my Port.sh file echo 'Give me a maximum of 5 seconds to run please.' lsof -i | grep Xvnc | grep ESTABLISHED | grep $USER lsof -i | grep $USER | grep Xvnc | grep -o -P '(?<=:).*(?=->)' echo 'Brought to you by a cloudy and unlucky day.' echo 'Press enter to exit' I would like to make the terminal wait for the u...
Add at the end of your script: read junk See Bash Manual for more info.
How to Prompt the user to press Enter to Exit in terminal so that the terminal doesn't close automatically?
1,574,366,215,000
When I erroneously type 'ñ' (expecting to type any command) and then remove it and type the correct letter, the output returns the command with a special character attached �, obviously the shell don't recognize the command and I must re-type it being careful not to type again the 'ñ' character. e.g. Wrong typing ...
Due to all help, I could find out how to fix this. The main issue is due to the UTF-8 encoding, the server didn't have it configured as said in comments. Quoting comments: [@Rmano]: In UTF-8, ñ is a two-bytes char [@jimmij]: backspace character for some reason deletes only one of them [@aecolley]: Try setting the env...
BASH: �ls: command not found when typing 'ñ' by mistake
1,574,366,215,000
I have a folder with a lot of files. I want to copy all files which begin with of these names (separated by space): abc abd aer ab-x ate to another folder. How can I do that?
With csh, tcsh, ksh93, bash, fish or zsh -o cshnullglob, you can use brace expansion and globbing to do that (-- is not needed for these filenames, but I assume they are just examples): cp -- {abc,abd,aer,ab-x,ate}* dest/ If you'd rather not use brace expansion, you can use a for loop (here POSIX/Bourne style syntax)...
copying files with particular names to another folder
1,574,366,215,000
Is is possible to run the passwd command with an option to show the newly entered passwords? By default it doesn't show what I type and I don't want this. [dave@hal9000 ~]$ passwd Changing password for user dave. Changing password for dave. (current) UNIX password: New password: bowman Retype new password: bowman pa...
If you really want to go this path and there's no passwd parameter, you can use this Expect script: #!/usr/bin/env expect -f set old_timeout $timeout set timeout -1 stty -echo send_user "Current password: " expect_user -re "(.*)\n" set old_password $expect_out(1,string) stty echo send_user "\nNew password: " expect...
show entered new password in unix "passwd" command
1,574,366,215,000
I have a problem renaming a file that I'm not even sure which special characters I have in the file. I'm using CentOS 6 64bit. When I ls the file: Giko Suzo San?e - Ep1.avi but when view it in FTP: Giko Suzo San’e - Ep1.avi When I try to mv it: [root@server ]# mv 'Giko Suzo San?e - Ep1.avi' 'Giko Suzo Sane - Ep1.av...
You could use \ before the character ? so it is consider as a normal character in the name of the file and not a special character to be interpreted. The command would then be: mv Giko\ Suzo\ San\?e\ -\ Ep1.avi 'Giko Suzo Sane - Ep1.avi' EDIT: following discussion in comments, this line did the trick: mv Giko\ Suzo\ ...
How to rename filename with ' or ? in file name?
1,574,366,215,000
Sometimes the output of some command include other commands. And I'd like to start that command from output without using a mouse. For example, when command is not installed there is a message with line for installing this command: $ htop The program 'htop' is currently not installed. You can install it by typing: sud...
The right thing to do here is to set up bash to prompt for installation, as explained in SamK's answer. I'll answer strictly from a shell usage perspective. First, the text you're trying to grab is on the command's standard error, but a pipe redirects the standard output, so you need to redirect stderr to stdout. htop...
How to start line with command from output of another command
1,574,366,215,000
Let's say I have as follows : Folder A C1 file a A2 Folder B C1 B2 file b B3 What I want is to merge these two folders, which would give me : Folder C C1 A2 B2 B3 Notice I didn't write file a and file b. I only want to merge the architecture. Each repository ...
Well, you could have find exec mkdir. cd /A/ find -type d -exec mkdir -p /C/{} \; Or if the structure is flat as shown in your example, without find cd /A/ for dir in */ do mkdir -p /C/"$dir" done and in both cases the same again for cd /B/.
Merging two directory without copying the files
1,574,366,215,000
I have a directory that has 800 files like this: file1.png [email protected] file2.png [email protected] file3.png [email protected] ... etc I need to create zip files like this file1.zip (containing file1.png and [email protected]) file2.zip (containing file2.png and [email protected]) file3.zip (containing file3...
If always there are two, is simple: for f in file+([0-9]).png; do zip "${f%png}zip" "$f" "${f/./@2x.}"; done Note that the above will work as is from the command line. If you intend to use it in a script, put shopt -s extglob somewhere before that line. (extglob is enabled by default only in interactive shells.) In o...
Zipping files two by two
1,574,366,215,000
I just need to get how much bandwidth is used in 3 or 4 days. Do you have any application in the terminal to do it? I'd prefer if it didn't use SNMP. I found iptraf, wireshark, cacti, but they were not what I am looking for. Of course I need to save my results; for a single computer, not a network. It's very importan...
You know you already have that with ifconfig right? Ifconfig keeps counters about your incomming and outgoing bandwidth on each interface by default. Usually you can't reset counters except rebooting (with a few exceptions) From console you can easily leave a cron running each three days and saving results to a file ...
Bandwidth monitoring in Linux
1,574,366,215,000
Currently, I have a plain text file, A, such as lowest priority very high significance. outstanding very novel In this file, every line contains a sentence. I want to separate this file into multiple files, and each file is composed of a single line of the original file, A. For instance, with respect to the example f...
You can easily do it using split command. E.g.: split -l1 -d -a 3 A A Check man split for details.
Regarding separate a single file into multiple files according to line separation
1,574,366,215,000
How can I align data into pretty columns relative to given word? For example, I have output of the route -n command: default via 172.20.99.254 dev eth0 87.33.17.71 dev tun0 scope link 89.223.15.12 via 172.20.99.254 dev eth0 src 172.20.99.74 172.20.9.0/24 dev eth0 proto kernel scope link src 172.20.99.74 65.46.5.89...
I would use a character that I am sure it doesn't exist into file, as a dummy separator for the column command, like: $ sed 's/dev/@dev/' file | column -ts@ default via 172.20.99.254 dev eth0 87.33.17.71 dev tun0 scope link 89.223.15.12 via 172.20.99.254 dev eth0 src 172.20.99.74 172.2...
align data by word into column
1,574,366,215,000
I would like to create a command which fetches matching previous command, something like this: match-latest "ssh root@150" but which then exits and populates the command prompt with the most recent match, e.g.: owilliams@OWILLIAMS010451 ~/go/ % ssh [email protected] and leaves it for the user to edit (if desired) an...
zsh offers a plethora of ways to retrieve command lines from history. Here’s just a selection of these. Keybindings Press ↑ to step through previous command lines. Press Alt. to step through the last word of each previous command line. Press CtrlR (“reverse”) and start typing to search through previous command lines....
zsh: How to retrieve the previous command line?
1,574,366,215,000
I'm trying to run a script that takes a -t argument. This argument stands for text, and the value -- in theory -- is allowed to be multiline. On the command line, I assume a Here Document would work, but I don't like typing out long things on the command line. In addition, I want this file to persist so I can pass it ...
xargs -d='' (where -d is an extension of the GNU implementation of xargs) is the same as xargs -d= as '' is just quoting syntax in the shell language. That tells xargs to use = as the delimiter. So for instance echo foo=bar | xargs -d= cmd would call cmd with foo and bar<newline> as arguments. With xargs -d '' or xarg...
How do I pass the contents of a multiline file as an argument?
1,574,366,215,000
My man page for 'whatis' does not match others I have found online. Namely, no options are available to use with it. /home/User$ whatis -d ls whatis: -d: unknown option uname -srv Darwin 16.7.0 Darwin Kernel Version 16.7.0: Sun Jun 2 20:26:31 PDT 2019; root:xnu-3789.73.50~1/RELEASE_X86_64 My first thought is that I...
You appear to be on a Mac. Some of the online pages will be for other UNIX-like systems. Many of them will be Linux-centric (more specifically, GNU-centric) without necessarily realising so. The definitive solution for any given command is to use your installed reference documentation. For example, man whatis to see t...
What do I need to do to update my commands?
1,574,366,215,000
PROBLEM: I installed sl but when I type sl on the command line I get this: bash: sl: command not found (root@host)-(03:55:38)-(/home/user) $apt install sl Reading package lists... Done Building dependency tree Reading state information... Done sl is already the newest version (3.03-17+b2). 0 upgraded, 0 newly...
If you're running as root (I'm guessing you might be since you ran apt directly), PATH by default will exclude /usr/local/games and /usr/games due to a conditional in /etc/profile: if [ "`id -u`" -eq 0 ]; then PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" else PATH="/usr/local/bin:/usr/bin:/b...
Locomotive doesn't work on a debian system: sl ls
1,574,366,215,000
How do I efficiently combine multiple text files and remove duplicate lines in the final file in Ubuntu? I have these files: file1.txt contains alpha beta gamma delta file2.txt contains beta gamma delta epsilon file3.txt contains delta epsilon zeta eta I would like the final.txt file to contain: alpha beta gamma de...
If you want to print only the first instance of each line without sorting: $ awk '!seen[$0]++' file1.txt file2.txt file3.txt alpha beta gamma delta epsilon zeta eta
Combine text files and delete duplicate lines
1,574,366,215,000
When using find, how can I drop the original filename extension (i.e. .pdf) from the second pair of -exec braces ({})? For example: find ~/Documents -regex 'LOGIC.*\.pdf' -exec pdf2svg {} {}.svg \; Input filename: ~/Documents/LOGIC-P_OR_Q.pdf Output filename: ~/Documents/LOGIC-P_OR_Q.pdf.svg Desired filename: ~/Docu...
You can use an "in-line" shell script, and parameter expansion: -exec sh -c 'pdf2svg "$1" "${1%.pdf}.svg"' sh {} \; or (more efficiently, if your find supports it) -exec sh -c 'for f; do pdf2svg "$f" "${f%.pdf}.svg"; done' sh {} +
Dropping filename extensions with find -exec
1,574,366,215,000
I need to be able to do this via command line in one step: lab-1:/etc/scripts# sqlite3 test.db SQLite version 3.8.10.2 2015-05-20 18:17:19 Enter ".help" for usage hints. sqlite> .mode csv ; sqlite> .import /tmp/test.csv users sqlite> select * from users; John,Doe,au,0,"",1,5555,91647fs59222,audio sqlite> .quit I've t...
SQLite meta commands are not terminated by ; but by newline. Therefore, you will have to provide the commands in some other way so that newlines are inserted in the correct places. Here's a few examples, of which I would probably use the first one (because it's readable). Use a here-document: sqlite3 testdb <<'END_C...
sqlite3 command line - how to set mode and import in one step
1,574,366,215,000
I am looking for one or possibly more commands, or a combination of commands, to get my PC to use as much resources as possible. I want to check how my computer behaves when subject to the maximum amount of data it can handle. I've tried by running multiple programs such as browsers, graphic and system tools one by on...
You could probably use stress: stress: tool to impose load on and stress test systems If you wnat to stress memory you could use : stress --vm 2 --vm-bytes 512M --timeout 10s to use 2 vm using both 512MB of ram for 10 seconds. If you want to stress CPU add: stress --cpu ## -t 10s with ## equal to your number...
Is there a command or a serie of commands to make the computer use as much resources as possible?
1,574,366,215,000
How can I execute each command pre-appended with another one? Example when I run: nmap -p 80 host I want it to run proxychains nmap -p 80 host even when I do not add proxychains intentionally. In other words: can I alias all commands at once with proxychains pre-appended? Bonus if this is something I can switch on/...
Would it work to just run a full shell under proxychains? Assuming it can deal with processes started by the shell properly. You could do with just $ proxychains bash and exit the shell at will. But if you really want to, you can abuse the DEBUG trap (with extdebug set) to mangle the commands the shell runs. This wo...
add a command to each command (e.g. proxychains each command by default)
1,574,366,215,000
I'm writing a wrapper Bash script for ARSS to make it easier to use. The program converts images to sounds and vice-versa but it only accepts 24-bit BMP images, which I was only able to produce using GIMP so far. I'm looking for a way to convert any given image to a suitable BMP file so ARSS can process it. I tried Im...
According to an ImageMagick forum post, using -type truecolor may be the correct way to force the image to 24 bit: convert "$1" -type truecolor "$1.bmp"
How to convert an image to a 24-bit BMP in commandline?
1,574,366,215,000
I want to delete all the text after the second underscore (including the underscore itself), but not on every line. Every of the target lines begin with a pattern (>gi_). EXAMPLE. Input >gi_12_pork_cat ACGT >gi_34_pink_blue CGTA Output >gi_12 ACGT >gi_34 CGTA
$ awk -F_ 'BEGIN {OFS="_"} /^>gi/ {print $1,$2} ! /^>gi/ {print}' input >gi_12 ACGT >gi_34 CGTA
Delete everything after second underscore
1,574,366,215,000
I've got a command foo that outputs a list of filenames: $ foo file1.a file2.b file3.a And a command bar that accepts the names of .a files as arguments and does some processing: $ bar file1.a file3.a Great success! $ bar file2.b FAILURE I'd like to combine the two with a pipe like foo | xargs bar, but I need to fil...
You can use grep to grab all files within foo that end with .a. foo | grep "\.a$" | xargs -d'\n' -r bar
How to filter lines passed through a pipe?
1,574,366,215,000
Trying to command mv foo&foo.jpg images/ but get command not found, then if try and rename the file it won't let me.
Use single quotes. For example: mv 'foo&foo.jpg' images/ Unless you quote or escape the & symbol, it's interpreted as a special token by the shell.
cannot move file because of & in name
1,574,366,215,000
It would certainly be possible to whip together something in Python to query a URL to see when it was last modified, using the HTTP headers, but I wondered if there is an existing tool that can do that for me? I'd imagine something like: % checkurl http://unix.stackexchange.com/questions/247445/ Fri Dec 4 16:59:28 ES...
This seems to fit your requirements (updated to use '\r\n' as record separator for response data): #!/bin/sh get_url_date() { curl --silent --head "${1:?URL ARG REQUIRED}" | awk -v RS='\r\n' ' /Last-Modified:/ { gsub("^[^ ]*: *", "") print exit } ' } u...
Command line tool to check when a URL was updated?
1,574,366,215,000
I'm trying to create some files that has different names and with different extensions. Let say I want to create for example 3 files with following name and extension: File001.000 File002.001 File003.002 Or with alphabetical extension: File001.A File002.B File003.C Also it would be better if I could create files wit...
The simplest way I could find is: touch $(paste -d '.' <(printf "%s\n" File{001..005}) \ <(printf "%s\n" {000..004})) This will create File001.000 File002.001 File003.002 File004.003 File005.004 To understand how this works, have a look at what each command prints: $ printf "%s\n" File{001..0...
How to create multiple files/directories with randomized names?
1,574,366,215,000
Given a shell script file that begins as #!/bin/bash # (bash script here), and has been chmod +xed, is there any difference in running ./script and bash script from the command-line?
It depends on your $PATH. ./script will run /bin/bash script. bash script will use whatever bash comes first in your path, which isn't necessarily /bin/bash, and could be a different version of Bash.
Is there a difference between ./script and bash script? [duplicate]
1,574,366,215,000
I have numerous HTML files all nested inside different folders contained in a single overall folder. In each of these HTML files I need to replace /contact/index.html With /contact/index.php Is there an easy way of doing this from the command line?
Yup, if you have GNU find and GNU sed, try this in the parent folder: find . -type f \( -iname "*.htm" -o -iname "*.html" \) -exec sed -i.bak 's#/contact/index\.html#/contact/index.php#' '{}' + This will find all files whose name ends in .html or .HTML or .htm or .HTM (or .HtM...) and run this sed command on them: se...
Quickest way to find and replace a string in numerous HTML files
1,574,366,215,000
Is there something like a logical for the cli? I want to achieve this mv -t newfolder *.(png|jpg) so that alls jpg and png files are moved into newfolder. I know it could be done with mv -t newfolder *.png && mv -t newfolder *.jpg But there is somewhere sytactic sugar, isn't it?
In Bash: mv -t newfolder *.@(png|jpg) ?(pattern) Matches zero or one occurrence of the given patterns *(pattern) Matches zero or more occurrences of the given patterns +(pattern) Matches one or more occurrences of the given patterns @(pattern) Matches one of the given patterns !(pattern) Matches anything except one ...
Regex match in CLI
1,574,366,215,000
I do not hold a deep understanding of computer science concepts but would like to learn more about how the utility encfs works. I have a few question regarding the concept of filesystem in regards to encfs. It is said that encfs is a cryptographic filesystem wiki link. 1)To encrypt the files encfs is moving around bl...
I think that behind your description, there is a misconception. The unencrypted data is not stored on the disk at any point. When you write to a file in the encfs filesystem, the write instruction goes to the encfs process; the encfs process encrypts the data (in memory) and writes the ciphertext to a file. The file n...
How to understand the filesystem concepts used by encfs?
1,574,366,215,000
I am writing a script to check whether all the servers in my organization are functioning properly. One of those is Zimbra mail server. I am trying to send a mail through sendmail provided by zimbra package using the following command ssh Jarvice@someip echo "Hello" | /opt/zimbra/postfix-2.7.4.2z/sbin/sendmail [email ...
Your local shell is dividing your command into ssh ... and /opt/zimbra ..., and then piping the two. You have to quote the argument to ssh, so your local shell won't try to interpret it and it will be sent to the remote computer in its entirety: ssh Jarvice@someip "echo \"Hello\" | /opt/zimbra/postfix-2.7.4.2z/sbin/se...
Execute command through SSH
1,574,366,215,000
I am logged into a linux server via ssh. From the bash shell, is there any standard way of bringing up some kind of text editing environment so I can create and edit a text file? I am aware that there exist apps like emacs and vi, but I don't know if they are appropriate for basic text file editing or if I should use ...
It's well-known fact, that vi has only two modes: it beeps and spoils text (: So, if you're newbie and know nothing about vi and emacs, the best choice for you will be something simple like nano. It has hint in footer and it's easy to edit and save your edits. But in case you want to be a good administrator, you shoul...
How to create and edit a text file from the bash shell
1,302,063,784,000
I need to be able to determine the size of a block special file. For example, given /dev/sda, I need a command that will provide the size of the device. (By size I mean capacity, since this is a storage device.) Rationale: I can store information in the device with: echo "12345" >/dev/sda # needs to be run as root...
I don't think there's a general, cross-platform answer. On Linux, the information is in /proc/partitions (in spite of the name, this contains all (most?) block devices, not just PC-style partitions). awk '$4 == "sda" {print $3}' /proc/partitions
How to get size of a block special file? [duplicate]
1,302,063,784,000
I want to grant root access temporarily from ip 1.2.3.4, just for the current session (until next sshd or server restart) I could add this to sshd_config, and then remember to remove it: AllowUsers [email protected] but is there better way? Can I change the current settings of the currently running sshd daemon, witho...
In FreeBSD, therc system provides a mechanism for passing flags to the sshd daemon, namely to set the sshd_flags variable prior to starting/restarting sshd. The rc system will look for files names /etc/rc.conf.d/sshd/* and source all such files on any 'service sshd' invocation. That makes it fairly trivial to create...
sshd: add AllowUsers for current session, without editing sshd_config
1,302,063,784,000
I have a very similar problem to this question, but have no idea how to adapt the answer to my own issue. I have a tab-sep file with 2nd column containing comma-sep list, such as: TRINITY_DN1_c0_g1 DN1_c0_g1 GO:0000166,GO:0003674,GO:0005488,GO:0005515,GO:0005524,GO:0005575 TRINITY_DN1_c0_g3 DN1_c0_g3 GO:000582...
This awk command is quite readable: awk ' BEGIN {FS = "[,\t]"; OFS = "\t"} {for (i=3; i<=NF; i++) print $1, $2, $i} ' file In perl, this is perl -F'[,\t]' -lane 'print join "\t", @F[0,1], $F[$_] for 2..$#F' file # or perl -F'[,\t]' -slane 'print @F[0,1], $F[$_] for 2..$#F' -- -,=$'\t' file If you're not sure y...
Expanding comma separated list in a tab-delimited file into separate lines
1,302,063,784,000
Apologies for this newbie question but I can't find the answer anywhere. If I run the command systemctl in a SSH terminal accessing an Ubuntu VM in Azure, then it ends with lines 159-187/187 (END), it doesn't return the control and I don't know what key to press to let it continue and finish. I can press Ctrl-C to can...
This isn't a general thing, it is specific to the systemctl command. Some commands, like systemctl, automatically open a pager (programs like less or more) for their output. That's why you can press space to load the next page of output. To exit the pager, just press q. You can also use Ctrl+C though, it doesn't reall...
Return control after command ends in Ubuntu
1,302,063,784,000
I have custom script that takes: optional arguments in the short/long format one required command line argument the short/long command line options are for example: -r, --readonly -m, --mount for the one required arguments, these are actually specified in the script as case statements, ie foo and bar in this exampl...
Let's suppose the function for which you want to define completions is called myfunc. First, let's set up the actual function: Put your function in a file called myfunc. Note: This does not end in .zsh or .sh. When you put a function in its own file, you do not need to add funcname() {…} boilerplate. Make sure tha...
zsh completion for custom script: complete options from "case" statement
1,302,063,784,000
When I run the info command I get bash: info: command not found How can I solve this?
You should install the info package: sudo apt install info
Install "info" in Debian
1,302,063,784,000
I use this dd command for checking disk speed: dd if=/dev/zero of=/path/file bs=1G count=1 oflag=direct which gives back something like this: 1 oflag=direct 1+0 records in 1+0 records out 1073741824 bytes (1,1 GB, 1,0 GiB) copied, 8,52315 s, 126 MB/s Now I would like to pipe this output, not the file dd is writing, ...
To be able to insert dd in a pipeline before or after another command, its informational messages are written to standard error rather than to standard output. The OpenBSD manual for dd explicitly mentions this (but the Ubuntu manual seems to omit this fact, but mentions it in the more complete info page): When finis...
How to write dd status/result message to a file?
1,302,063,784,000
The below nmcli command to connect to WiFi doesn't connect if it has more than one word as ssid name? nmcli device wifi connect my homewifi password mypass NOTE: SSID name: my homewifi (bad since is has 2 words) SSID name: my (good since only has 1 word) Connecting with one word ssid name...
If there are spaces in the command line, you should use quotes: nmcli device wifi connect "my homewifi" password mypass This will let the shell and nmcli know that this is to be considered as one word.
nmcli command takes only first string of ssid? [closed]
1,302,063,784,000
I just ran a job that takes several hours, and I forgot to pipe that text into a text file. pseudocode: echo [previous text output] > OutputHistory.txt Additionally, I can't just "copy and paste" what was in my terminal because 1) the display omits important formatting characters like "\t", and 2, I may have closed ...
This is impossible in general. Once an application has emitted some output, the only place where this output is stored is in the memory of the terminal. To give an extreme example, if this is the 1970s the terminal is a hardcopy printer, the output isn't getting back into the computer without somebody typing it in. If...
How would I get my terminal to regurgitate the previous output text from past commands? Is this even possible?
1,302,063,784,000
How do I double each line of input piped in? Example: echo "foobar" | MYSTERY_COMMAND foobar foobar
Just use sed p. echo foobar | sed p You don't need cat, either: sed p input.txt # or sed p input.txt > output.txt Explanation p is the sed command for "print." Print is also sed's default action. So when you tell sed explicitly to print, the result is that it prints every line twice. Let's say you wanted to only p...
How do I double each line of piped output? [duplicate]
1,302,063,784,000
Is that possible to get an alternative to the command dd to burn an iso image including some options: Detect the burning device , Burn an iso image and eject the CD from the command line?
In KDE the reference CD burning software is K3b, which is packaged in Debian as k3b. On the command-line you'd probably use cdrkit (the main package is called wodim).
How to burn an iso image from the command line
1,302,063,784,000
I want to create a file of fixed size (1G, 10G, 100G etc) with a single random word of length within the specified limit on every line. I basically want this to run a benchmark which will sort the entire file. So if I want a file of 1G and the word length limit is suppose 4, the sample of file would look like this: a ...
My understanding of the question is that, you need to create a large file, each line of this file is a random word within specified length. If you don't need the word to be a real word, but some random characters: < /dev/urandom tr -d -c '[:alpha:]'|head -c 1M|fold -w10 >result.txt This will create a file of size...
Create a file of fixed size with specific contents
1,302,063,784,000
Attempt 1 xargs -I '{}' -0 -n 1 myprogram --arg '{}' --other-options But that does not preserve zero bytes. Also the program may run multiple times. But instead of failing in case of zero byte creeping into stdin, it runs program multiple times. Attempt 2 myprogram --arg "`cat`" --other-options But that does not pre...
It is impossible to have NUL bytes in command line arguments, so the question is what do you want to happen in case there are NUL bytes in the standard input. As you've noted, your candidate solution #1 runs the command multiple times in this case. That's not ideal. But there is no ideal solution that lets you handle ...
How do I turn entire stdin into a command line argument verbatim?
1,302,063,784,000
I have a text file which contains around 9999999 lines. Here I'm pasting the few lines: 1874641047 Gazipur 1874646347 Jessore 1845105653 Chittagong 1845146123 Narayanganj 1845164162 Gazipur 1843908007 Jessore Here 1st column contains cell phone numbers & 2nd column contains regions. I wanted to write those data...
You can use awk: awk '{print > $2".txt"}' input-file It redirects the output to a filename made from the second field.
How can I write data separately in many text files which contain the same fields?
1,302,063,784,000
How can I list the current directory or any directory path contents without using ls command? Can we do it using echo command?
printf '%s\n' * as a shell command will list the non-hidden files in the current directory, one per line. If there's no non-hidden file, it will display * alone except in those shells where that issue has been fixed (csh, tcsh, fish, zsh, bash -O failglob). echo * Will list the non-hidden files separated by space ch...
What is the alternative for ls command in linux? [duplicate]
1,302,063,784,000
When I use the code below in a terminal on Ubuntu, it works fine: rm !(*.sh) -rf But if I place the same line code in a shell script (clean.sh) and run shell script from terminal, it throws error as this clean.sh script: #!/bin/bash rm !(*.sh) -rf Error I get: ./clean.sh: line 2: syntax error near unexpected token `...
Shell Script Approach By default, globs don't work in a BASH script (although you can turn them on with shopt). If the shell script ever gets run by a non-BASH interpreter, globs might not work at all. You can get the same effect using the find command, which is how I'd recommend doing it (because of how much more con...
!(*.sh) works on the command line but not in a script
1,302,063,784,000
I know some methods for stopping process. When I type: echo {1..999999} > filename.txt I can't stop it from running. I can stop other processes with Ctrl+C | Ctrl+D | Ctrl+\ and etc. But none of them seem to be working with this command. Some guys told me to simply close this terminal. Other than that, open new ter...
The reason why cannot interrupt that with Ctrl-c etc... is that the shell isn't running any command at that point. It's busy expanding {1..999999} to compute what the command line arguments will eventually be once it gets to the point of running the command. While external commands respond to termination signals like ...
How do you stop a bash shell expansion?
1,302,063,784,000
Comparing grep '.*[s]' file with grep .*[s] file Why do you need quotation marks to let this work properly? In the second case, grep seems trying to inspect every file with a period.
Quotes (either single or double) around an argument inhibit glob expansion. Your first example passes a Regular Expression as an argument to grep. Your second example contains a glob pattern which the shell itself expands, passing filenames that fit that pattern as arguments to grep.
Why does "grep '.*[s]' file" work and "grep .*[s] file" doesn't?
1,302,063,784,000
I'm tarring up /home, and piping it through bzip2. However, I've got lots of already-compressed files out there (.jpg, .mp4, .mkv, .webm, etc) which bzip2 shouldn't try to compress. Are there any CLI compressors out there that are smart enough (either via libmagic or the user enumerating extensions) not to try to bac...
The way you are doing this, with compressing a .tar file the answer is for sure no. Whatever you use for compressing the .tar file, it doesn't know about the contents of the file, it just sees a binary stream, and whether parts of that stream are uncompressable, or minimally compressible, there is no way this is know...
Tell gzip/bzip2/7z/etc not to compress already-compressed files?
1,302,063,784,000
I have in a directory /home/files/ some files that all have the same extension .txt. For example 1.txt 2.txt 3.txt 4.txt 5.txt test.txt These files are all the same in data format but the data are different. All these files have at least the following line inside frames=[number here] This line appears multiple times...
With find + grep: find . -name '*.txt' -exec sh -c 'grep -HPo "frames=\K.*" "$0" | tail -n1' {} \; And with shell for loop + grep in similar fashion: for file in *.txt; do grep -HPo 'frames=\K.*' "$file" | tail -n1; done
Fastest way to read last line within pattern of multiple files with the same extension
1,302,063,784,000
I have a nice PS1 line in my .bash_profile, and I want to copy it to another machine. So I want to view it AND copy it to my clipboard. I can't figure out how to string the commands to do this together. I imagine what I need to do is grep for my PS1 line, pipe that to tee, then tee goes to stdout and also to pbcopy ...
... | tee /dev/tty | ... /dev/tty is the "file" that refers to your terminal.
Redirect output to stdout and pipe to a binary
1,302,063,784,000
I want to display the number of lines, words and characters, in a file, in separate lines? I don't know anymore than using wc filename for this.
You can use tr: wc filename | tr ' ' '\n' , or if you just want the numbers: wc filename | tr ' ' '\n' | head -3
How to display the number of lines, words and characters in separate lines?
1,302,063,784,000
I want to rename my file with its substring.Because unfortunately renamed all the files in my server. Now I want to remove suffix( .gz) of all the files including files in subdirectories also. Below is avaliable files with extra .gz. # pwd /usr/apache-tomcat-6.0.36/webapps/rdnqa/WEB-INF/classes # ls META-INF ...
You can use rename (it's designed for that). Just execute this command in the folder where the *.gz file are: rename -n 's/\.gz$//' *.gz This removed the .gz extension from all files that have a .gz extension. Output should look like this: hibernate.queries.hbm.xml.gz renamed as hibernate.queries.hbm.xml jbpm.busines...
How to rename file using substring of the same file name [duplicate]
1,302,063,784,000
I want to download the source files for a webpage which is a database search engine. Using curl I'm only able to download the main html page. I would also like to download all the javascript files, css files, and php files that are linked to the webpage and mentioned in the main html page. Is this possible to do using...
First of all, you should check with the website operator that this an acceptable use of their service. After that, you can do something like this: wget -pk example.com -p gets the requisites to view the page (the Javascript, CSS, etc). -k converts the links on the page to those that can be used for local viewing. Fro...
Download all source files for a webpage
1,302,063,784,000
I have a directory in linux which has a list of log files where log files get auto generated if some job runs. Each log file gets appended with the timestamp like "JobName_TimeStamp" UPDATED: job_2014-05-28_15:05:26.log job_2014-05-28_15:06:58.log job_2014-05-28_15:07:02.log job_2014-05-28_15:07:57.log job_2014-05-28_...
The below code worked: for i in myjob*; do if [[ "myjob_2014-05-28_15:08:00.log" < "$i" ]]; then echo $i fi done
Listing files greater than particular timestamp in file name?
1,302,063,784,000
I am trying to use cpulimit for testing an app I'm developing under low resource conditions, and I need the process to start under the influence of cpulimit. It is not sufficient to start the program and later apply cpulimit. The example on the cpulimit page does not work for me. The example is this: cpulimit --lim...
This is unrelated to cpulimit. Running a.out directly on the command line wouldn't have worked either. When you execute a program without specifying any directory component, the program is looked up in the PATH. The current directory is normally not in the PATH, so you need to give an explicit directory indication. cp...
How can I start a process using cpulimit?
1,302,063,784,000
I'm currently writing a shell script that separate values from their identifiers (retrieved from grep). For example, if I grep a certain file I will retrieve the following information: value1 = 1 value2 = 74 value3 = 27 I'm wondering what UNIX command I can use to take in the information and convert it to this format...
You can use awk like this : grep "pattern" file.txt | awk '{printf "%s ", $3}' Depending of what you do with grep, but you should consider using awk for greping itself : awk '/pattern/{printf "%s ", $3}' file.txt Another way by taking advantage of bash word-spliting : echo $(awk '/pattern/{print $3}' file.txt) Edi...
How to separate numerical values from identifiers
1,302,063,784,000
I have a large log file that contains numerous lines of the same entry, lets call it "repeat-info". As an example here is what a portion of the log might look like: [Timestamp] repeat-info [Timestamp] repeat-info [Timestamp] Log information 1 [Timestamp] Log information 2 [Timestamp] repeat-info [Timestamp] Log inform...
There are a few ways to do this. Best would be grep: grep -v 'repeat-info' file.log Other ways: sed '/repeat-info/d' file.log sed -n '/repeat-info/!p' file.log awk '!/repeat-info/' file.log
Searching a file & excluding lines with a specified string
1,302,063,784,000
I saw this usage of redirection somewhere, and thought it was a typo: grep root < /etc/passwd But after I run it, I saw that it gives the same output with grep root /etc/passwd: $ grep root < /etc/passwd root:x:0:0:root:/root:/bin/bash $ grep root /etc/passwd root:x:0:0:root:/root:/bin/bash The same thing happens...
Many utilities which work with files will accept stdin (standard input) as streamed input, or accept the file-name as a parameter.. Your < file examples are redirecting the output of the file to the utility. The file was opened by the shell and passed on to your utility via stdin .. On the other hand, with cat file,...
Removing redirection operator does not change output. Why?
1,302,063,784,000
Example: When I run echo -e "\[\033[;33m\][\t \u (\#th) | \w]$\[\033[0m\]" the printed response is \[\][ \u (\#th) | \w]$\[\] where everything after the first \[ and before the last \] is an orangey-brown. However when I set the command prompt to \[\033[;33m\][\t \u (\#th) | \w]$\[\033[0m\] the command prompt ...
In Bash 4.4+, you can use ${var@P}, similarly to how ${var@Q} produces the contents of var quoted, see 3.5.3 Shell Parameter Expansion in the manual, bottom of page. $ printf "%s\n" "${var}" \[\033[00;32m\]\w\[\033[00m\]\$ $ printf "%s\n" "${var@P}" |od -tx1z 0000000 01 1b 5b 30 30 3b 33 32 6d 02 2f 74 6d 70 01 1b ...
Is it possible to use the escape codes used in shell prompts elsewhere, such as with echo?
1,302,063,784,000
I am trying to empty my syslog.1 file which was flooded with some messages and has the size of 77 GB. I did sudo truncate -s 0 /var/log/syslog.1 but the command is taking more than 2 hours to return. Is it safe to stop it by Ctrl-C or by the kill command? I am afraid that these methods may cause inconsistency in the ...
Interrupting a process will never cause the filesystem itself to become corrupted¹. The kernel ensures this. The worst that can happen is that the files are in an inconsistent state with respect to application invariants. For example, killing a file editor while it's saving the file may leave a half-written file, but ...
How to stop truncate command safely
1,302,063,784,000
I am using Linux Mint 19.3 I want to run two instances of youtube-dl. All traffic of terminal 1 instance should go through regular network. All traffic of terminal 2 instance should go through VPN. Is there any command that will enable terminal 2 to use VPN connection for all future commands? In other words, Is there ...
You cannot "instruct terminal 2 to use a VPN connection for all future commands". However, you can make a new network namespace, run your VPN in that namespace or move the VPN network interface into that namespace (possibly after connecting it up in a suitable way to the main network namespace and/or your physical net...
Command that will Enable VPN Only in my current Terminal
1,302,063,784,000
I often find myself in a long command-line, where it can be a pain to navigate to a specific location in the middle by means of Left-Arrow, Right-Arrow, Alt+B, Alt+F etc. I know that using tmux, I can move to a particular <keyword> by means of a search. Since this is a very common operation, is something similar impl...
Bash (and any other terminal application that uses the readline library) has search functionality. Command line edition is done by the shell, not by the terminal. (See What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?). The main search commands are Ctrl+S and Ctrl+R, which search f...
Move the cursor directly to `<keyword>` in a long command line
1,302,063,784,000
When I run date on my Ubuntu under WSL, it prints: Wed May 15 19:33:37 STD 2019 Why does this have the string STD in it? I can't find a timezone online with the abbreviation STD (for example here) and googling 'date std' gave me unexpected results.
Thanks to Jesse_b for finding this Stack Overflow Q/A: TL;DR WSL Dynamically generates a fake timezone info file at /usr/share/zoneinfo/Msft/localtime that in hard linked to /etc/localtime. The Msft file uses the made up names DST or STD, and they stand for no specific timezone. What is actually going on is WSL atte...
Why does my date output have "STD" as the time zone?
1,302,063,784,000
I'm interested in wrapping a command such that it only runs at most once every X duration; essentially, the same functionality as the lodash throttle function. I'd basically like to be able to run this: throttle 60 -- check-something another-command throttle 60 -- check-something another-command throttle 60 -- check-s...
I'm not aware of anything off-the-shelf, but a wrapper function could do the job. I've implemented one in bash using an associative array: declare -A _throttled=() throttle() { if [ "$#" -lt 2 ] then printf '%s\n' "Usage: throttle timeout command [arg ... ]" >&2 return 1 fi local t=$1 shift if [...
How to wrap a command such that its execution is throttled (that is, it executes at most once every X minutes)
1,302,063,784,000
I want to change the password for my wifi network foo. I've got a raspberry pi connected to foo. I only use SSH to talk with it. The pi is headless, and it isn't convenient to attach a monitor+keyboard or hardline. /etc/wpa_supplicant/wpa_supplicant.conf on the pi has lines like this: network={ ssid="foo" psk=...
Yes This works. The network manager will try connecting to each one.
changing wifi password over SSH on wifi-only headless server
1,302,063,784,000
I frequently end up grepping files with very long lines resulting in pages worth of output for one matching word. What's a good way to limit the output to only enough characters as the width of my terminal? I realize this means the matching word may not be present in the line. But I still want context, so filename o...
Consider this wrapping function, which passes any parameters to grep, then cuts the output to $COLUMNS (or 80, if COLUMNS isn't set): function grepcut() { grep "$@" | cut -c1-${COLUMNS:-80} } Use it like: $ grepcut sometext somefiles or $ set | grepcut LS_COLORS
How to make grep output fit screen's width of characters
1,302,063,784,000
I use the following code as part of a much larger script: mysql -u root -p << MYSQL create user '${DOMAIN}'@'localhost' identified by '${DOMAIN}'; create database ${DOMAIN}; GRANT ALL PRIVILEGES ON ${DOMAIN}.* TO ${domain}@localhost; MYSQL As you can see it creates an authorized, allprivileged DB user, an...
Just have the user store the variable beforehand with read: echo "Please enter password for user ${domain}: "; read -s psw mysql -u root -p << MYSQL create user '${domain}'@'localhost' identified by '${psw}'; create database ${domain}; GRANT ALL PRIVILEGES ON ${domain}.* TO ${domain}@localhost; MYSQL Here, the...
Making mysql CLI ask me for a password interactively
1,302,063,784,000
There are some commands like cd or ll that if I run them as sudo, their execution just "breaks". What is a rule of thumb to know which commands will "break" this way when a sudo command precedes them? This data can help me and other newcomers to code stabler scripts.
Only external commands can be run by sudo. Sudo The sudo program forks (start) a new process to launch an external command with the effective privileges of the superuser (or another user if the -u option is used). That means that no commands that are internal to the shell can be specified; this includes shell keywords...
A rule of thumb to know which commands break in sudo?
1,473,661,284,000
I wish to compile the results of a find command where the find command returns the relative filepath of a java file located in subdirectories. E.G., I am in ./ and I want to run javac on a file, someFile.java, but I don't know at "command-type-time" what the relative path is. Running find . -name someFile.java retu...
You want to use the $() syntax. eg javac $(find ./someDir/anotherDir/ -name someFile.java)
Forward results of Find command to javac
1,473,661,284,000
For example, when using ack to search code in source files, the output is high lighted. But if you pipe the output into a local file, you lose the code high light. Do we have a command line tool to reserve it? To understand what I mean: $ git clone https://github.com/koehlma/jaspy $ cd jaspy/ $ ack func ./* # you see ...
ack does something smiliar to grep. When it puts it text to a terminal, it will spit the results out in color. If the output is redirected to a file, the matches do not get colorized. You can override these heuristics with the options --color and --nocolor. Check man 1 ack for more details.
command line tool to reserve code high light in output file?
1,473,661,284,000
I want to cd to the directory of go's bin file: $ type go go is /c/tools/go/bin/go How can I quickly cd to this directory in bash ?
cd $(dirname $(which go)) which go will show the path of the executable. Then get the dirname of that path and cd to that.
How to quickly cd to a command's directory after used the 'which' or 'type' [duplicate]
1,473,661,284,000
We have a policy on our cluster that any files not modified or accessed within 30 days will be deleted. I have a project running and I want to keep all files until I finish it, would it be possible to trick the system by doing something like: find ./ -type f -exec touch {} + I have tried this and it seems that the ti...
Sure this should work. But you make sure by check with 'stat' command. sh-4.3$ stat test.csv File: 'test.csv' Size: 871 Blocks: 8 IO Block: 4096 regular file ...
How to modify files on Unix to avoid file purging policy?
1,473,661,284,000
I am writing a script that requires me to provide a list of files in my directory, whose filenames contain spaces,*,?,$,%,etc. How can I do this, I have seen multiple posts but couldn't find anything that works for me. Is it possible to achieve this using grep?
grep -E should do what you need. Note that some characters need to be escaped with a backslash, so if you add more and the results aren't what you expected, escape it and try again. Note the | is an or... $ ls | grep -E '\s|\*|\?|\$|%' all this.txt all?this.txt all*this.txt all%this.txt all th*s.txt all$.txt
How to list filenames that contain spaces and special characters without using find
1,473,661,284,000
I am using rlwrap to colorize prompt in asterisk CLI: rlwrap -s 99999 -a -pRED /usr/sbin/asterisk -r I read in man rlwrap that I can also use rlwrap -z pipeto to pipe output through a colorizer. I have grc colorizer which works like this: cat foo | grcat <conf_file> The above examples colorizes foo using the rules...
pipeto Unfortunately, rlwrap's built-in filter pipeto does not filter output in the way you desire. I find the documentation rather misleading, but what it does is if you run rlwrap -z pipeto some-shell, then, within the interaction: if you type commands without any pipe sign (|), those are passed verbatim to some-sh...
rlwrap -z pipeto: piping output through pagers
1,473,661,284,000
Regarding the question Simple command line HTTP server I would like to know, what is the simplest method for creating a http server listening on a specified port that will always cause timeout (it just eats the request and never responds). I am looking for a dead simple oneliner. It would be useful for the purpose of ...
You can use NetCat to just listen on a port and do nothing: nc -l $PORT
Simple http server from the command line that will always cause a timeout
1,473,661,284,000
What's the shortest command I could use to find out my WAN IP?
I found: $ curl ifconfig.me 73.4.164.110 So of course I made an alias $ alias myip='curl ifconfig.me' $ $ myip 73.4.164.110
What's the shortest way to find my WAN IP address at the command line? [duplicate]
1,473,661,284,000
I'm new to Linux and so far,I have come to understand that if we open a new process through a gnome-terminal eg: gedit & "& for running it in background", then if we close the terminal, gedit exits as well. So, to avoid this ,we disown the process from the parent terminal by giving the process id of gedit. But, I've c...
When you close a GNOME Terminal window, the shell process (or the process of whatever command you instructed Terminal to run) is sent the SIGHUP signal. A process can catch SIGHUP, which means a specified function gets called, and most shells do catch it. Bash will react to a SIGHUP by sending SIGHUP to each of its ba...
closing parent process(terminal) doesn't close a specific child process
1,473,661,284,000
For example if I did a curl -F '[email protected]' https://clbin.com. How do I man curl easily?
In both bash and zsh (and (t)csh where that feature comes from), provided that history expansion is enabled: man !!:0 (admittedly, it's not really shorter than man curl).
How to see manpage of previous command?
1,473,661,284,000
I've got an Excel file, shown in the picture below, and available for download here. What I need is to extract the variables under Item (Column B) and the values in column G. As a start, I tried saving the Excel file as a comma-delimited .csv file, but when I check the number of rows in the Mac OS X Terminal, it tells...
After seeing your CSV output, the problem is clear: you told Excel to use CR line endings, probably because it informed you that they are "Macintosh" style. That is badly outdated information, not true for over a decade now. There are three main line ending styles: LF: The style used by Unix and all its primary deriv...
How can I convert this excel file so that it is not only one row?
1,473,661,284,000
When writing a command on the bash command line, I can use CTRL+w to delete a word backwards, or ALT+d to delete word forwards. The problem is, that these two shortcuts are not exactly complementary: CTRL+w deletes everything up to a space, whereas ALT+d deletes only up to any non-alphabetic character (i.e. stops at /...
bind -p gives you the current bindings. You'll find that Ctrl+W is bound to unix-word-rubout and Alt+D to kill-word: "\C-w": unix-word-rubout "\ed": kill-word If you do a bind -p | grep kill-word, you'll find: "\e\C-h": backward-kill-word "\e\C-?": backward-kill-word Some terminals send ^H upon Backspace and some ot...
bash command line editing (Emacs shortcuts)
1,473,661,284,000
I have analog camera and I give a film to the lab where they scan it, I wanted to upload it to flickr but want to change info about camera. Right now it's NORITSU KOKI QSS-32_33 and I wanted it to be pentax k1000 (I don't want to clear exif data). How can I do this from command line.
The tool you're looking for is called exiftool. You can use it to read & write exif meta data that's attached to a single image or a whole directories worth of files using its recursive switch (-r). To change the camera model you can use the -model=".." switch. Example Here's an image before the change. $ exiftool ff4...
How to change camera info in Exif using command line
1,473,661,284,000
I want to set an alias to start nedit together with command line option -noautosave (due to text files up to 500MB). What seemed to be easy: alias nn="nedit -noautosave $1 &" just raises some error "Permission denied" of a different file and another error about unexpected EOF while looking for matching "'" and "unexp...
If you only want to run nedit with -noautosave when one of the files to be opened is larger than a given size, try this (I am using 100M but you can set your own size limit): function nn() { big=0; let big+=$(find "$@" -size +100M|wc -l) if [ $big -gt 0 ]; then nedit -noautosave -- "$@" & else ...
Bash aliases/functions and command line options
1,473,661,284,000
I am working in Linux and C-shell. Often times I would require to change some portion of what is there already in the prompt that I obtain from reverse searching through the history command by use of CTRL+R. I do not want to use the Backspace for doing this. I have looked at this question on superuser.com which was sp...
In tcsh (which I suppose is what you're calling "C-Shell" if you're not totally masochist) in emacs mode (usually the default), you can use Ctrl-W. That's the kill-region widget which deletes between the mark (set with Ctrl-Space but defaults to the beginning of the line) and the cursor. In that regard, its behaviour ...
How can I clear portion of what is typed into the prompt while working on Linux and using C-shell?
1,473,661,284,000
I have my current PS1 as follows. The $? output is really useful (second line). export PS1="\ ${PSOn_Blue}${PSBWhite}\t\ ${PSColor_Off} \$?\ ${PSColor_Off}${PSBGreen} \u\ ${PSColor_Off}${PSWhite}@\ ${PSColor_Off}${hostcolor}\h\ ${PSColor_Off}:\ ${PSBGreen}\w\ ${PSColor_Off}\$\ " It would be even nicer if the return...
I use this: BOLD_FORMAT="${BOLD_FORMAT-$(color_enabled && tput bold)}" ERROR_FORMAT="${ERROR_FORMAT-$(color_enabled && tput setaf 1)}" RESET_FORMAT="${RESET_FORMAT-$(color_enabled && tput sgr0)}" PS1='$(exit_code=$?; [ $exit_code -eq 0 ] || printf %s $BOLD_FORMAT $ERROR_FORMAT $exit_code $RESET_FORMAT " ")' Concaten...
Color PS1 based on previous command output [duplicate]
1,473,661,284,000
In the book I am reading, the output of df command is shown like this: Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 15115452 5012392 9949716 34% / /dev/sda5 59631908 26545424 30008432 47% /home /dev/sda1 147764 17370 122765 13% /boot tmpfs 256856 0 256856 0...
df shows you the utilization and free space on filesystems. Obviously, on your machine, /home is not a filesystem but a mere directory.
'df' command doesn't list /home directory