date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,421,059,115,000
I'm trying to recursively copy a folder of files containing .csv extensions and rename them while copying them into a single folder. I'm close except for the file renaming which eludes me. Can anyone assist? find "/IMPORTS/EFHG2" -iname '*.csv*' -exec cp {} /temp/Template \; As for the rename I'm looking for somethin...
Having below structure: ├── destdir └── srcdir ├── dir1 │   └── with space.csv ├── dir2 │   └── infile.csv └── dir3    └── otherfile.Csv running the command: find "/path/to/srcdir" -type f -iname '*.csv' -exec sh -c ' path="${1%/*}"; filename="${1##*/}"; echo cp -nv "${1}" "/path/to/d...
Copy and rename files recursively using part of folder name for new name
1,600,274,121,000
I've downloaded this program construct2d and compiled it using GNU Fortran gfortran 9.3.0. You can compile the program using gnu make: make (compilation time: 10 seconds on my PC running Ubuntu 20.04 with GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu) ). This program doesn't work with arguments, instead I ...
From contributors to comp.lang.fortran: One problem seems to be where the main loop: done = .false. do while (.not. done) call main_menu(command) call run_command(command, surf, options, done, ioerror) end do calls 'run_command': subroutine run_command(command, surf, options, done, ioerror) ... lo...
Feeding a command using file redirection or pipe doesn't always work
1,600,274,121,000
I'd like to make a hot-key for this task I sometimes need to perform: %> cp file.txt.1 file.txt.1.bak Where I've repeated the file name but with a .bak on the end. I'd like to instead just type: %> cp file.txt.1 Hit the quick key and have it add the file name with a .bak extension. Which would turn the second code...
For this case, in either bash or zsh, you can enter the command as cp file.txt.1{,.bak} This is brace expansion. For cases where brace expansion isn't convenient because you want to do more editing on the second argument, in zsh, there's a command copy-prev-word which is bound to Ctrl+Alt+ out of the box. It inserts ...
How can I add a hot-key to readline for zsh or bash that takes fills in the 2nd parameter to copy but with .bak?
1,600,274,121,000
How do I download and install packages from the command line in OpenBSD? As an example, in Fedora, to download the php pecl-memcached package from the command line, I just do this: dnf install php php-pecl-memcached I have searched through the net but found no answer relating to it ...
Install a package by- # pkg_add packageName For downloading PHP packages- # pkg_add php # pkg_add php-fpm # pkg_add php-mysql Discover more information at the openbsd faq
OpenBSD: downloading and installing php packages
1,600,274,121,000
I need to go through folders and count files in TARs with same name. I tried this: find -name example.tar -exec tar -tf {} + | wc -l But it fails: tar: ./rajce/rajce/example.tar: Not found in archive tar: Exiting with failure status due to previous errors 0 It works when there is only one example.tar. I need separa...
You need tar -tf {} \; instead of tar -tf {} + to run tar with each tarball individually. In GNU man find it says: -exec command {} + This variant of the -exec action runs the specified command on the selected files, but the command line is built by appending each selected file name ...
Loop through folders and count files in TARs
1,600,274,121,000
I tried the command setxkbmap cn but nothing happened. I'd like to write characters in pinyin, so that it would automatically write chinese characters and then have the possibility to turn in back to english with setxkbmap us I'd like to do it from command line, because I'm using i3 window manager.
Normally, you will need an IME(Input Method Editor) to enter languages that make use of Chinese characters (e.g. Mandarin, Japanese, etc.). Some of the more popular IMEs (in no particular order) include Fcitx, IBus and SouGou PinYin. Installing an IME is generally straightforward on the mainstream distros, you just in...
Set chinese in xkb
1,600,274,121,000
How can an original command issued at the command line be acquired without using proc or any other non standard tool? When printing a process list using ps, the arguments passed in to initiate the command are shown without quotes, which is not how the original command was issued. It also appears that no combination of...
There is no portable way to get an unambiguous representation of the command line of another process. You didn't find the answer you're looking for because it's impossible. You either need to cope with an ambiguous representation, or to use a different method depending on which OS your code is running on, or to find s...
process list with quoted arguments, portably
1,600,274,121,000
There are many times I get single page PDFs that I want to convert to JPEGs and crop the excess whitespace off of. Here is the current set of commands I have which accomplishes what I want: gm convert -density 300 -trim INPUT.PDF TMP.PNG gm convert -bordercolor white -border 10 TMP.PNG OUTPUT.JPG rm TMP.PNG I am tryi...
One of the few things I've learned the hard way about ImageMagick is that the order of arguments can be vital. In particular, you are providing an input pdf file, then suggesting a density to use when converting it to an image, whereas you need to set the density before reading the pdf. Simply invert those 2 items an...
Consolidate several GraphicsMagick (ImageMagick) commands into one
1,600,274,121,000
When I run 'ls -laGp' command in macOS some of the folders are highlighted with this color. What does that mean? I researched but couldn't find any documentation or anything. If you let me know which sources I should check first in these situations it would be awesome.
From the BSD ls man page: LSCOLORS The value of this variable describes what color to use for which attribute when colors are enabled with CLICOLOR. This string is a concatena- tion of pairs of the format fb, where f is the foreground color and b is the background color. The...
What does 'mustard color' highlighted directories mean?
1,600,274,121,000
I have a set of lines (item + description) which I want to run through fzf -m. For example: item1: Some description item1: Another description item2: Yet another description After selection I would like fzf to return the line numbers (e.g. 1 3) instead of the lines themselves because: 1) I don't want to include the d...
fzf can already do this with --with-nth to change the presented (and searched-for) line to only some fields of the original line. So we start with: 1: item1: Some description 2: item1: Another description 3: item2: Yet another description then use: fzf -d: --with-nth 2.. which means to skip showing the first field (...
fzf: How to return "ID" / line numbers?
1,600,274,121,000
I'd like to save the output from running a specific command on the command line. However, after running the command, I am prompted to type in the name of my account to confirm that I would indeed like to run this command. If I simply use command > file.txt, the prompt itself is saved to the file and I can't type the c...
You can use tee, which writes both to stdout and a file. command | tee file.txt
Redirect output to file when there is additional prompt
1,600,274,121,000
System: Red Hat Enterprise Linux Server release 7.6 (Maipo), 3.10.0-957.el7.x86_64 GOAL: Collect configurations for data from multiple servers to validate they are the same. What Works: ssh $SERVERNAME 'yum list installed | grep -E "krb|java|libkadm|realmd|oddjob|sssd|adcli"' >> $FILENAME What Doesn't Work: ssh $SERV...
GracefulRestart is almost certainly correct. No verify, compare the output of $PATH between on-server exec and ssh to server exec: [server2.com]# echo $PATH [jumpbox]# ssh server2.com 'echo $PATH' If the path to 'adcli' & 'realm' are missing on the ssh $PATH env variable, then the simplest way to fix is to simply use...
Commands Not Found when Passed through SSH
1,600,274,121,000
how can I use printf to print a row of minus symbols? when I try: printf "-----------\\n" I get: bash: printf: - : invalid option printf: usage: printf [-v var] format [arguments] when I try: printf "\-\-\-\-\-\-\-\-\-\-\-\\n" I get: \-\-\-\-\-\-\-\-\-\-\-
It is an extremely in-efficient way to use printf() without using format specifiers. You generally define them to let know what type of output is being formatted. It should have been written as printf '%s\n' "-----------" Such that the printf matches the ----------- as a string type with the format specifier that tak...
Printf - print repeating minus symbols [duplicate]
1,600,274,121,000
I've read this thread https://unix.stackexchange.com/a/7718/256195, that only if var doesn't contain any tab/spaces but in my case it does contain spaces, like below example: "this is a test" this_is_a_solid_line_that_doesnot_contain_tab_or_spaces command column will separate this is ..etc also, but I'd want so...
Assuming the input doesn't contain | characters, you could convert those sequences of whitespace that are not inside quotes to | (or any other character that doesn't occur in the input) and then pipe to column -ts'|': <input.txt perl -lpe 's/(".*?")|\s+/$1||"|"/ge' | column -ts'|'
Layout tab/spaces [closed]
1,600,274,121,000
I have a list of names and I have a binary file. I want to copy that binary file so that there is one copy for each member of the list. The list is a text file with one name in each row. I keep coming back to for i in $(cat ../dir/file); do cp binaryfile.docx "$i_binaryfile.docx"; done There is no error. Only one...
It should be: for i in $(cat file); do cp binaryfile.docx "${i}_binaryfile.docx"; done EDIT: You can reproduce it with this example: $ i=1 $ echo $i 1 $ echo $i_7 $ echo ${i}_7 1_7 The point is that _ (underscore) character is allowed in variable name. You can read about it in man bash but keep in mind that it's wr...
Copy a file a number of times with names that come from a list
1,600,274,121,000
I need to do simple financial calculations on Linux and had been using wcalc for this until I stumbled upon a wrong result caused by floating-point number issues. Is there a calculator (I really would prefer the command-line) that one can rely on for this task? One that doesn't use floats internally?
As pointed out in the comments to my question, bc doesn't have this problem. Another solution is the the more powerful command line of Qalculate! which seems to fulfill my needs.
Financial calculations without floating point numbers in console?
1,600,274,121,000
If you put this link in a browser: https://unix.stackexchange.com/q/453740#453743 it returns this: https://unix.stackexchange.com/questions/453740/installing-busybox-for-ubuntu#453743 However cURL drops the Hash: $ curl -I https://unix.stackexchange.com/q/453740#453743 HTTP/2 302 cache-control: no-cache, no-store, m...
Curl download whole pages. A # points to a fragment. Both are not compatible. hash The symbol # is used at the end of a web page link to mark a position inside a whole web page. Fragment URLs ...convention called "fragment URLs" to refer to anchors within an HTML document. What is it when a link has a pound "#" s...
cURL url_effective with Hash
1,600,274,121,000
I used netstat -anlptu to check for open ports. This command is now somewhat deprecated so I start using ss -anptu but each entry takes 2 lines. The result is not practical. I use Debian.   netstat -anlptu: tcp 0 0 0.0.0.0:6001 0.0.0.0:* LISTEN - tcp 0 ...
Use column. For example: ss -anpt | column -t -x | less I get output like: State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 100 127.0.0.1:143 0.0.0.0:* LISTEN 0 100 0.0....
ss command take 2 lines for each result
1,600,274,121,000
I want to link the ssh command to autossh command, so for example when I type ssh [email protected] it will execute autossh [email protected]. I was tried ln -s autossh ssh but it doesn't work.
The command you are looking for is alias. The general syntax for the alias command varies somewhat according to the shell. In the case of the bash shell (or any sh-like shell) it is alias [-p] [name="value"] So it seems you want: alias ssh="autossh"
Link command to another command
1,600,274,121,000
I'm using a piped command to migrate a big production DB from one host to another using this command: mysqldump <someparams> | pv | mysql <someparams> And I need to extract the line 23 (or let's say the first X lines) (saved as file or simply in bash output) from the SQL passing from one server to another. What I've t...
With zsh mysqldump <someparams> | pv > >(sed '22,24!d' > saved-lines-22-to-24.txt) | mysql <someparams> With bash (or zsh): mysqldump <someparams> | pv | tee >(sed '22,24!d' > saved-lines-22-to-24.txt) | mysql <someparams> (though beware that as bash doesn't wait for that sed process, it's not guaranteed t...
Get first N lines of output from a pipe operation
1,600,274,121,000
I'm looking to create a script that when executed it will look at a directory and search for all files and then automatically discover the filename patterns to then move them based on additional logic stated below. Say I have the following files in a folder: aaa.txt temp-203981.log temp-098723.log temp-123197.log tem...
Check, does it work and I will add explanation, how it works. I tested it in the dash. Note: file names should not contain spaces, newlines. #!/bin/dash limit=1 printf "%s\n" * | sed 's/[-0-9]*\..*$//' | uniq -c | awk -v lim=${limit} '$1 >= lim {print $2}' | sort -r | while read -r i; do for j in "${i}"*; do ...
How to move all files matching a certain name to a new folder if the number of matching files is greater than 10?
1,600,274,121,000
I accidentally executed man ls > info.txt and now I don't know how to recover the contents of the file.
you've wrote the output of "man ls" command in a file that you called it "info.txt". If your info.txt file was empty, now easily you can delete your file and create new one by using these commands: #rm -f info.txt #vi info.txt (thenCtrl + X and press yes to save it.) Or: you can open info.txt file, and delete content...
How do I recover the contents of a file? [duplicate]
1,600,274,121,000
I'm using this command, which searches pacman.log for packages updated today and converts them into a conky string: tail -500 /var/log/pacman.log | grep -e "\[$(date +"%Y-%m-%d") [0-5][0-9]:[0-9][0-9]\] \[ALPM\] upgraded" | sed 's/^.*\([0-2][0-9]:[0-5][0-9]\).*upgraded \([^ ]*\).*/${color2}\2${goto 250}${color1}\1/' ...
You can do (with a shell with support for zsh's {x..y} form of brace expansion like zsh, bash, ksh93 or yash -o braceexpand): { printf '%.0s\n' {1..18} your-command } | tail -n 18 Note that it prepends newline as opposed to appending them. To append, you could do: your-command | tail -n 18 | awk '{print};END{whil...
Append new lines to stream, until certain number is reached
1,600,274,121,000
I have three commands in one shell script: wget, 7z, and rm. Inside list.txt URL1 archive_01.zip URL2 archive_02.zip URL2 archive_03.zip Download archives: while read -r url filename; do wget -O "$filename" "$url"; done < list.txt $ ls archive_01.zip archive_02.zip archive_03.zip Extract archives...
Something like this? #! /bin/bash - while read -r url filename; do wget -O "$filename" "$url" 7z x "$filename" rm -- "$filename" done < list.txt
How to combine multiple commands into a nested loops?
1,600,274,121,000
I'm working in the same directory of the files. I have files with three different extensions. I want to perform each one of the five commands on a file with the specific extension by passing them as arguments to the for loop. example: I want when I run the code like: $my_code.sh *.zap *.F *.T I want the script to pe...
It makes no sense put all commands into the single for loop, in your case. You don't have common actions for all files - each extension has own commands and them doesn't intersects. Thus, you will need use if or switch for distinguishing one extension from another. Why do so? It will be easier to create a custom loop ...
how to pass many arguments to for loop?
1,600,274,121,000
I have a large list of IP addresses (most are IPv4, but a few are IPv6), followed by a space and then a domain name, followed by another space and the same domain name with "www." in front of it. Each instance is on it's own line. The list looks like this (but is much larger): 23.212.109.137 at.ask.com www.at.ask.com ...
With single awk command: awk '{ print $2 > "domains.txt"; print "http://"$3 > "domains_http.txt" }' file Results: > cat domains_http.txt http://www.at.ask.com http://www.maps.googleapis.com http://www.litscape.com http://www.loc.gov http://www.mbu.edu > cat domains.txt at.ask.com maps.googleapis.com litscape.com...
Find and Replace Everything Before a String of Text
1,600,274,121,000
Lets say I was told to do sudoers file changes with the following... What does that mean, and how do I actually do it? www-data ALL = NOPASSWD: /bin/rm /etc/vsftpd/vusers/[a-zA-Z0-9]* I believe that it's setting the premissions for those folders, and I think I use the visudo command to do it... but I'm not sur...
The first word in the line indicates who this line applys to. www-data is a user, you can find it in /etc/passwd. NOPASSWD means members of this user doesn't have to authenticate when calling sudo. Mostly used when a process will be calling sudo instead of a human. The next part is the what your www-data has acces...
How to interpret line in sudoers
1,600,274,121,000
This is what I get üê∑ echo $((5/2)) 2 How to make $((5/2)) giving me 2.5 ?
You can't. Bash will only work with integers. For more precision, use something like bc.
How to make $((5/2)) deliver a floating point number? [duplicate]
1,600,274,121,000
When you browse in a webpage with a browser, after the code of the page is downloaded, the browser downloads all the assets (CSSs, JSs and images). Is there a way I can list all the URL of the assets of a page (internal and external assets)? The idea is to monitor changes on the external and internal assets.
I wrote a Python script that might do what you want: #!/usr/bin/env python2 # -*- coding: ascii -*- """list_assets.py""" from bs4 import BeautifulSoup import urllib import sys import jsbeautifier import copy # Define a function to format script and style elements def formatted_element(element): # Copy the eleme...
Listing webpage assets via CLI
1,600,274,121,000
I have two large files ~9GB. CSV File 1 has columns A, B, C, D, E and CSV File 2 has columns B, C, F, G. The desired output is A, B, C, D, E, F, G. All I have been able to find is joining on similar columns and concatenating with the same columns, however here some match, and some do not. A sample output would look so...
This works based on the following facts: (a) All fields are strictly tab separated (b) Common columns in both files (B and C) have the same value $ join --nocheck-order -eNaN -13 -22 -t$'\t' -o 1.1 1.2 1.3 1.4 1.5 2.3 2.4 b.txt c.txt A B C D E F G 1 2 3 4 5 6 7 NaN 1 2 NaN 1 2 1 Files ...
Concatenate CSV with some shared columns
1,600,274,121,000
I used the below command to list down all the daemons that are in a machine /sbin/initctl list | awk '{ if ($1 == "tty") print $1" "$2; else print $1; }' Now my next requirement is to get the daemons running path i.e command line. For instance vmsd /usr/sbin/vmsd So gave couple of tries using the ps aux command foll...
As DopeGhoti answered in the comments: If you can find the PID, use cat /proc/$pid/cmdline
Need to get the command line of all the daemons that are running
1,600,274,121,000
In all the different Linux desktop environments there is usually a list of all the (xorg) programs that can be run. For example in my most recent Linux install (Arch running the Deepin Desktop Environment) if you press the Windows/Mac key it brings up a list of all the applications that use xorg, and shows what ones w...
Desktop entries for applications, or .desktop files, are generally a combination of meta information resources and a shortcut of an application. These files usually reside in /usr/share/applications or /usr/local/share/applications for applications installed system-wide, or ~/.local/share/applications for user-specifi...
Get list of all installed X applications
1,600,274,121,000
I'm creating an animated gif using mogrify's convert. However, at the moment I run in on a folder with dozens of images in it, and I just instruct it to use all of the images it finds. However, I'd like it to only use files that were created on a particular date. Can I do such a thing? Current command used: convert -...
This small shell script will loop through every file in the current directory and compare it's last-modified timestamp to the range that is built by the start and end timestamps (here, October 10th). Matching files are added into the files array, and if there are any files in the array, it calls convert on them. Adjus...
How do I use mogrify convert only on files with a certain creation date?
1,600,274,121,000
If I start a terminal (any terminal, for example urxvt) like urxvt -e sleep 5, then a new terminal is launched but after 5 seconds the terminal closes, because the sleep program has ended. How can I start a terminal with a program on the command line, but have the terminal stay alive after that process has ended? In ...
The terminal (tmux) closes when it's executed the command you told it to execute. If you want to execute top and then an interactive shell, you need to tell it to do that. Combining commands is the job of the shell, so run an intermediate shell (which isn't interactive) and tell it to run the two commands in successio...
How to prevent the terminal from closing when the program it was started with ends? [duplicate]
1,600,274,121,000
Why does this work when I type it direct on the commandline: oldversion=12345 newversion=67890 sed -i "s/${oldversion}/${newversion}/g" "/home/user/MyDir_${newversion}/MyDir_${newversion}.reg" But when I put it in a script it doesn't: #!/bin/bash oldversion=12345 newversion=67890 sed -i "s/${oldversion}/${newversion...
Character 16 in the sed script does not exist. This is the " character that sed is complaining about, and that means that your editor or input method replaced it with some non-ASCII rendition of ". My guess would be either “ or ” or ¨. Use file on your file in order to get some guess on the encoding. It should be "...
sed works on commandline but not in script [closed]
1,468,321,036,000
Copy and pasting from a website to the terminal is very harmful , there are an example here You past the following line :ls /some/thing/much/too/long/to/type/ , by pressing Enter the following command will be executed without confirmation: ls /dev/null; clear; echo -n "Hello ";whoami|tr -d '\n';echo -e '!\nGotcha!!!\n...
The easiest and most portable way to see "hidden commands" is probably using cat -v For instance, I might run "cat -v" and paste into that terminal to see the nonprinting characters. Further reading: How can I see what my keyboard sends? (ncurses FAQ)
Is there an additional option to display hidden command on the terminal?
1,468,321,036,000
For example , there are two files a.ppt and b.jpg . And I can call a magic method to open them appropriately just like : magic_method a.ppt magic_method b.jpg And it open libreoffice writer and image viewer or something that fit the file type . Is there any command or script for that?
You might be thinking of xdg-open: xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and...
Is there any way to detect file type and open it with GUI in terminal in Fedora? [duplicate]
1,468,321,036,000
I'm looking for something like Zenity or Yad, except I want something that behaves like a menu, namely: it opens right next to the cursor; it takes one click to select things; it's possible to have multiple levels. The closest thing I've found is actually Autokey's folders, but Autokey needs to always be running (even...
Sawfish manages its menus with a companion program sawfish-menu. You can use that program even if you aren't running Sawfish as your window manager. The protocol between sawfish and sawfish-menu doesn't seem to be documented anywhere; it's inspired from the menu specification format in Sawfish itself. echo '(popup-men...
Is there a program that will launch a configurable context menu
1,468,321,036,000
How might I more easily use a filename found by grep as an argument to vim: $ grep -r foo * lib/beatles/john.c lib/pantera/phil.c lib/pinkfloyd/roger.c lib/pinkfloyd/richard.c lib/whitestripes/elephant/jack.c $ vim lib/pinkfloyd/roger.c To autocomplete with Bash, I need to type " l \t p \t i \t r \t o \t " because m...
I've made a script to grep recursively for a pattern, and then I can select one of the matches so vim will open that file in that line. I call it vgrep (vim grep, although it uses also awk in it). The following is its code: #!/bin/bash my_grep() { grep -Rn -I --color=auto --exclude-dir={.svn,.git} --exclude={t...
Autocomplete from grep output
1,468,321,036,000
I get Python. I don't get shell script. I could learn shell script, but I would rather not if I can use Python in its place. A good place for me to start would be the .profile script. Currently, for me it is: # ~/.profile: executed by the command interpreter for login shells. # This file is not read by bash(1), if ~/....
Not really. The .profile and .bashrc (and .bash_logout and .bash_profile) are specific to the shell. That is, the shell programs and only the shell programs read these files. It (the shell) does not execute these as a separate process, but rather source them, in a way similar to how Python does an import, but far less...
.profile is written in shell script — can I instead make my system understand that I want it to execute a Python script instead?
1,468,321,036,000
Background If think most of us agree that filters and pipes are the very foundation of Unix systems. Pipes and filters are very powerful tools. Almost all Unix utilities use the standard input and output streams by default to make it possible to use them within pipelines. It is a convention for utilities within Unix ...
Pipelines don't work for source code because you can't process input as it comes in. You need the entire file loaded before processing begins. It gets even worse when you need multiple files for compilation (.h files for example). If you were reading from stdin you would need to stream in all of the needed files wi...
Why doesn't cc (the C compiler) and similar utilities use standard streams by default? [closed]
1,468,321,036,000
When I run my favorite app, why the arguments look different when viewed by ps? $ redshift -l 12.94:43.75 2>/dev/null 1>&2 & [1] 8637 $ ps -o cmd= -C redshift redshift -l 12.94 43.75 Notice the missing colon.
Though the details are operating-system specific, most systems allow you to alter the command-line arguments as they are reported by ps (or in the /proc file system). For example, on some systems you can directly edit argv. Many systems ship with a library function called setproctitle that allows you to do this. So ...
Why are arguments of a command altered when viewed by ps?
1,468,321,036,000
I am fairly new to Linux and have been trying to move some files around with terminal on my external hard drive but I can't seem to get it to work. I am using a generic external hard drive with a ext4 format but not matter what I try I can't do anything with it through my terminal. The Drive's name does have spaces in...
Welcome to Linux! A trick that will get you started here (and will save you from getting carpal tunnel in the future) is "tab completion": $ ls /med then press Tab to see $ ls /media/ If you press Tab again, you might see a list of possible options to continue the path, $ ls /media/ MyBigExternalDrive/ My Exampl...
Can not access my external hard drive.
1,468,321,036,000
I have: $ find 1 2 -printf '%i %p\n' 40011805 1 40011450 1/t 40011923 1/a 40014006 1/a/e 40011217 1/a/q 40011806 2 40011458 2/y 40011924 2/a 40013989 2/a/e 40013945 2/a/w I want: <inode> <path> any 2 40011450 2/t 40011458 2/y any 2/a 40014006 2/a/e 40011217 2/a/q 40013945 2/a/w How do do it?
Already answered. Here is version adapted to this task: D=$(readlink -f "2"); (cd "1" && find . -type f -print0 | cpio --pass-through --null --link --make-directories "$D") && rm -Rf 1 After this command I have exactly what I wanted: $ find 1 2 -printf '%i %p\n' find: `1': No such file or directory 40011806 2 4001145...
How do I merge (without copying) two directories? [duplicate]
1,468,321,036,000
Need to remove default gateway. For example, there is an IP 192.168.4.15 with default gateway 192.168.4.14. I connect to WLAN with gw 10.0.0.1 and after that I would like do remove previous gw. IFS='.' read -ra IPARR <<< "$IP" Gateway="${IPARR[0]}.${IPARR[1]}.${IPARR[2]}.14" ssh blah@$IP '/sbin/route -v del defa...
So, the answer is to use double quotes when ssh'ing into machine: ssh blah@$IP "/sbin/route -v del default gw $Gateway;"
Concatenate and pass as parameter, bash
1,468,321,036,000
Is there any way I can save a list in a output.txt, but without using the text editor to make so that: before each output there should be the command used that made the list ( list -l, for example or if I use two ls with different arguments, two separated groups of list with each of their own command used on to make...
Well, you can always create function like f () { echo "$@" >> output.txt; $@ >> output.txt; echo >> output.txt;} and then write f ls / f ls /tmp f do_something_that_produces_list
Saving a list in a specific format
1,468,321,036,000
I'm looking for a way to view the timestamp of a job in CUPS. I've searched the man pages and can't seem to find it. The long term goal is to have a script that parses the time from the jobID and will automatically delete any job that is over a certain age - to avoid overloading the server. My CUPS server has over 20...
I found the following 2 questions within the U&L site that would seem to give hints as a possible way to do this. These 2 questions: View all user's printing jobs from the command line How to show the CUPS printer jobs history? Would seem to imply that you could use lpstat to get what you want. I noticed that I coul...
View timestamp for CUPS print jobs
1,468,321,036,000
So today I encountered one of my PHP files was outdated so I've got to overwrite the phpthumb directory on the entire server. Multiple websites use this folder on multiple unknown locations, so how can I overwrite all these directories from 1 source path? (ie: /home/test/testuser/phpthumb/ to /home/*/*/phpthumb/)
This should work: echo /home/*/*/phpthumb | xargs -t -n 1 cp -r /home/test/testuser/phpthumb/* You have to work with xargs. Unfortunately cp cannot copy to multiple target. cp can handle multiple sources. Explanation: echo /home/*/*/phpthumb: lists all phpthumb directories xargs -t -n 1: xargs should call cp for eve...
How-to overwrite directory on multiple places with 1 source directory
1,468,321,036,000
Typing in xdotool getwindowfocus windowkill currently terminates the active window and bypasses any safeguards like "would you like to save your work?". Is there a weaker command than windowkill I can here use that won't make such bypasses?
The soft way to request an X11 application to close its window and possibly then exit is to send it a WM_DELETE_WINDOW message. Xdotool doesn't appear to have a way to do this. You can do it in Perl with X11::Protocol::WM. Untested: perl -MX11::Protocol -MX11::Protocol::WM -e '$X = X11::Protocol::new(); X11::Protocol:...
A quit command weaker than windowkill?
1,468,321,036,000
I'm running a command on command line which infinitely generates a certain data and I'm looking for a particular bit of data, so I used grep to find it. As soon as I get the data, I want the command to kill itself. How do I achieve this? NOTE1: AND'ing kill $$ with grep is not terminating the command. NOTE2: I saw thi...
Try this loud_program | grep --max-count=NUM then, according to my limited knowledge, loud_program receives SIGPIPE because it is writing to a disconnected end, which in turn could terminate loud_program. Try it with your program, not sure if this works for all programs.
How to make an infinitely executing command kill itself when certain conditions are met?
1,468,321,036,000
I've downloaded list of videos via youtube-dl and each file has corresponding .json file containing certain properties. So I would like to sort the files based on the selected json property which is inside of corresponding .json file (e.g. by number of views count, property: view_count). What tools I need and how this...
You would need to use some command-line JSON parser, extract the specific value for each file by printing it and sort it by the printed value. Here is the example of the script which you can use: ls -1 *.json | tr \\n \\0 | xargs -0 -L1 -I% sh -c "cat '%' | jshon -e view_count | awk '{print \$1\" %\"}'" | sort -k 1 -n...
How to sort files based on the json property value inside the file?
1,468,321,036,000
I want to convert a particular amount of seconds to a date. In my case the it's the number of seconds elapsed since 1st of January 0001. If it were for seconds elapsed from epoch it would be easy: $ date -r nr_of_seconds. It would be awesome if there was a way of telling date to start at a particular date. Is there s...
date -r almost does the job. All you need to do is shift the origin, which is an addition. date -r $((number_of_seconds - epoch)) where epoch is the number of seconds between 1 January 1 and 1 January 1970. The value of epoch depends on your calendar. In the Gregorian calendar, there are 477 leap years between 1 and ...
Convert a number of seconds elapsed to date from arbitrary start date
1,468,321,036,000
I have 11 files with spaces in its name in a folder and I want to copy the newest 10. I used ls -t | head -n 10 to get only the newest 10 files. When I want to use the expression in a cp statement I get an error that the files could not be found because of the space in the name. E.g.: cp: cannot stat ‘10’: No such fil...
If you're using Bash and you want a 100% safe method (which, I guess, you want, now that you've learned the hard way that you must handle filenames seriously), here you go: shopt -s nullglob while IFS= read -r file; do file=${file#* } eval "file=$file" cp "$file" Destination done < <( for f in *; do ...
Use output from head to copy files with spaces
1,468,321,036,000
When I run, say, cp, I get output like the following: # cp -v Foo Bar âFooâ -> âBarâ What's up with the weird â characters? Why is the shell doing this? It looks like some kind of strange encoding issue. When I use PuTTY, I get â. When I log into the actual machine locally, I get ? in inverse-video. If I redirect std...
It's an encoding issue. Set your Putty character set translation to "UTF-8": Window -> Translation -> Remote character set
Incorrect output from cp, rm, and so on
1,468,321,036,000
Sometimes I wonder how Linux programs achieve certain results knowing that they internally use system calls (system() or exec() in C programs). Given a working binary I wonder if it is possible to know easily which commands where executed. In a concrete example I use the genealogy tool gramps to build a family tree. I...
strace -o dumpfile.strace -f -e trace=process $your $app $with $parameters You find the result in the file dumpfile.strace.
Retrieve system commands without reading sources
1,468,321,036,000
I am running Ubuntu 13.10 on a Thnkpad X1 Carbon. My Wifi card is Centrino Advanced-N 6205 [Taylor Peak] I normally connect to open WiFi networks using the commands sudo iw dev wlan0 connect <ESSID> <Frequency> <BSSID> dhclient wlan0 This method works for me everywhere except in one room on my campus, where the sign...
You can use wpa_supplicant to connect to open AP. Add following section to the /etc/wpa_supplicant.conf: ap_scan=1 # no encryption network={ ssid="TEST" key_mgmt=NONE } You'll find more details in the sample /etc/wpa_supplicant.conf
Tips for debugging WiFi on the command line?
1,468,321,036,000
I am using a macBook Pro I enter: new-host-2:~ Justin$ hostname And it returns: new-host-2.home Why is this when it says in setting/sharing my computers name is "Justin's macbook pro" and computers on my local network can access my computer at "Justins-MacBook-Pro.local" The tutorial I am reading says that the command...
MAC OS X maintains at least three different names for different usages (ComputerName, HostName and LocalHostName). You can set the command line hostname to a different value with this command: scutil --set HostName "justins"
Why when I enter the command "hostname" it returns something other than my computers name?
1,468,321,036,000
I've experienced an issue where some of my scripts run perfectly fine when I call them manually, but these same scripts when called as cron jobs via cron don't seem to work at all. So my question: I'd like to know if there are restrictions that apply with the use of commands and/or scripts (and the privilege of execu...
The most common reason why commands that work fine from the command line would fail under cron is the fact they run under a stripped down environment with only a handful of variables defined. In particular PATH is set to its default value. Any customization done in dot files (.profile /etc/profile and the likes) is no...
Does cron impose some limitations to types of commands and privilege of execution? [duplicate]
1,468,321,036,000
I'm trying to remove a file I made by mistake using --exclude with tar. I ended up making a tar file named --exclude=*.tar Now I want to delete it but I'd like to rename it first. How do I escape it correctly?
There are two straightforward ways to do this using just rm: rm -- --exclude=*.tar or rm ./--exclude=*.tar
Proper escape sequence for a non-standard file name [duplicate]
1,468,321,036,000
I want to send, maybe using escape sequences such as $$$, fragments of an article through various commands, possibly with modifiers. The stdin would be replaced by the corresponding stdout. (Deleting the very special modifier should be simple enough with sed, if necessary.) I believe I can do it with python... but I w...
With awk & bash (for here-string <<< feature ): awk ' /^\$\$\$/{ sub(/\$\$\$/, "") cmd=$0 next } { arr[cmd]=arr[cmd] $0";"} END{ for (a in arr) { if (a ~ ".") { exe=sprintf("%s", a " <<< \042" arr[a] "\042" ) system(exe) ...
Piping fragments of a document through various commands
1,468,321,036,000
I have about 40 files in my folder. I selected all the files and pressed command+I. Instead of opening one Get Info window, my Mac shows up 40 windows! Is there a terminal command to hide the file extension from being shown when I open this folder in Finder the next time?
I found the answer in the other stack exchange forum "Super User". It looks like this is not possible in Terminal, unless we have Xcode installed or via AppleScript. Show/hide extension of a file through OS X command line
Hide a file extension using Terminal
1,468,321,036,000
I have 2 files: d and t. I would like to be able to combine these files so that the first line of file t is followed by a tab and then the first line of d. For shorter lines, paste t d seems to work fine. $ cat d t Highly reactive metals in group 1A of the periodic table. Fairly reactive metals in group 2A of the per...
The file which was the source for t was created using notepad on Windows 8 and copied by Ubuntu 13.04 into my home directory. The source for d was created on Ubuntu in gedit. Thus, the carriage returns were in the file all along. It seems that moving files back and forth between different operating systems results in ...
Why does the paste command add line breaks? [duplicate]
1,468,321,036,000
For example, the following works fine: /usr/bin/program It produces some output, and gets to result. But if I invoke it like this: echo -n | /usr/bin/program or this echo -n | bash -c "/usr/bin/program" or even this: echo -n | bash -c "wc -c; /usr/bin/program" It produces some lines of output, then fails. I have n...
Here's a Perl one-liner that will do what you want: perl -e '$SIG{CHLD} = sub{exit 0}; open $fh, "|-", @ARGV or die; sleep 20 while 1;' /usr/bin/program It's essentially the same as a mythical* sleep forever | /usr/bin/program, except it also watches for the program to finish, and will quit immediately when it does. ...
How can I work around the program failing if there is *any* stdin?
1,468,321,036,000
I was just introduced to xxd today. See link. I am very familiar with the QNX hd and odcommands, both of which will take input and create a hex dump (or octal dump if you like). See hd and od. What I am looking for is the xxd -r capability to go backwards from a hexdump to a binary file, but apparently QNX doesn't hav...
I would try to compile xxd for QNX instead of trying to find an alternative: ftp://ftp.uni-erlangen.de/pub/utilities/etc/xxd-1.10.tar.gz The source is small (less than 1000 lines) and it has defines for windows and amiga so I expect it's fairly portable.
Alternative to xxd for QNX
1,468,321,036,000
I want to know that if i install a daemon service in Arch Linux, then what will be the path of the files that will get install. also which files will be install where.
Have you read pacman(8)? To list all the files being installed by a particular package, run: $ pacman -Ql <package_name> Daemons are usually systemd services in Arch Linux, hence you could run: $ pacman -Ql <package_name> | grep service to see a list of service files installed by that package.
How to get the Installation path of binary and logic file in Daemon in Arch Linux
1,468,321,036,000
I am able to use ImageMagick to create a thumbnail of the first page of a PDF using: convert -thumbnail x80 95.pdf[0] thumb_95.png This works fine and generates a thumb_95.png file. I have tried several permutations of "find" using xargs but I can't get a combo working that will create the thumbnails in the folders a...
Try this: find /source/directory -name "*.pdf" -exec \ sh -c 'convert -thumbnail x80 {} $(dirname {})/thumb_$(basename {})' \; I had to modify it slightly to: find /source/directory -name "*.pdf" -exec \ sh -c 'convert -thumbnail x80 {} $(dirname {})/thumb_$(basename {} .pdf)'.png \; To have basename strip the fil...
Howto recursively create PDF thumnbails on Linux command line
1,356,894,572,000
I have one system that I would like to do a little clean up, so I would like to get all user accounts and last date they accessed they mail. It is a Debian system. So far I got to this: cut -d: -f1 /etc/passwd | xargs -n1 finger | grep "Mail last read" But I don't know how to write that username in front of Mail l...
You can try something like: for USER in $(cut -d: -f1 /etc/passwd); do MAILINFO=$(finger $USER | grep "Mail last read"); echo "$USER - $MAILINFO"; done I think you should get the gist ... you need to manipulate the return from the grep "Mail last read" a bit.
List all users and last time they read mail, pipeing to multiple output
1,356,894,572,000
Currently I'm repeatedly doing a 'find' that's too slow. I'm searching for non-hidden executable files within "$root", excluding "$root/bin": find "$root" -type f -perm -o+x -not -path "$root/bin/*" \( ! -regex '.*/\..*' \) I'd like to restrict find to only look in directories with mtimes older than a certain time. I...
Try this one: find "$root" -type d -mtime -1 ! -path "$root/bin*" -exec find "{}" -maxdepth 1 -type f -executable \; It's not just one find run, however maxdepth should accelerate the result.
How to have find only search for files in changed directories?
1,356,894,572,000
From what I know, parameters you pass to a command, goes to it's STDIN stream. so this: cut -d. -f2 'some.text' should be perfectly identical to this: echo 'some.text' | cut -d. -f2 as we send some.text to STDIN. In first case through a paramter, in second case via pipe. Where do parameter some.text from the first sam...
STDIN and the program command ( including arguments ) are completely different things. STDIN is a file that the program can read from. It may be connected to a terminal, a disk file, a device, a socket, etc. The program command is simply a set of strings, the first of which is the name of the program. They are pas...
Where are command line arguments (e.g. 'some.text') actually passed to?
1,356,894,572,000
I have used oh_my_zsh (and tinkered with bash_it) on multiple systems and have generally been happy with it, though I hate it's auto-correction feature and generally turn it off. My usual shell is zsh and I really want just three things from my prompt: Current directory/or pwd. Git status and branch. Color output fr...
To have colored output from ls, use the alias ls='ls --color=always'. You can enable this with alias ls='ls --color=always' As for having your current directory in your prompt: PROMPT='%~' To add git status to you prompt, take a look at this.
Shell Prompt Customization? [closed]
1,356,894,572,000
Is the ide interface also a bus? Is there a command like lspci or lsusb, to find out what devices are on the ide bus? Sources seem to contradict eachother. I'm asking this question here because of the need to know how to explore the bus in linux, but I would also like to make sure I understand what it is to begin with...
According to wikipedia, IDE is a bus: http://en.wikipedia.org/wiki/Parallel_ATA As far as I know there's no tool to scan the IDE bus apart from letting the kernel do it. I think it might interfere with regular I/O.
ide and pci bus commands
1,356,894,572,000
Is there a command-line utility which would allow me to extract pitch information from an audio file and store it in a numerical form (i.e. as a list of comma-separated values)?
You could have a look at pitchtrack but it only supports two output formats, its own (.pt) and PostScript if you use the included "pt2ps" tool.
Extract pitch information from audio file
1,356,894,572,000
I've managed to get flvstreamer to read a radio station's RTMP stream with the options --live -r [url], and it outputs what I guess is the raw audio data + stream info to stdout. Can I make it play the stream through my speakers, from the command-line? Possibly by sending sending the raw audio data to mplayer or somet...
I think I've made it work with 1.81 now :) ./flvstreamer_x86 --live --quiet --buffer 3000 -r [url] | mplayer -vo null -idle - I added the -idle to stop it from exiting, I guess the problem was that flvstreamer needed to buffer and mplayer didn't receive more data, so it quit.
Play RTMP stream from command-line
1,356,894,572,000
Is there a command like mv --preserve-structure src src/1 src/2/3 dst which creates dst/1 and dst/2/3? It should work similar to mv src/* dst, but move only the subtrees listed.
Under Linux, using rename from the Linux utilities (rename.ul under Debian and Ubuntu): rename src dst src/1 src/2/3 # dst/2 must exist With the rename Perl script that Debian and Ubuntu install as prename or rename: rename 's!^src!dst!' src/1 src/2/3 # dst/2 must exist rename 'use File::Basename; use File::Pa...
Selective recursive move?
1,356,894,572,000
I wanted to know what should I do to restore the configuration files if I've modified or accidentally deleted a file. In my case, I'm talking about /etc/snmp/snmpd.conf, what command should I use to reinstall it?
For restoring the configuration files you can use: sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall packagename So in this case the command (for snmpd) would be: sudo apt-get -o Dpkg::Options::="--force-confmiss" install --reinstall snmpd Credits to this site
How to restore configurations files ? (SNMP)
1,356,894,572,000
I'm using Pandoc to convert my mardown files to html files, html pages which are Github styled using Github.html5 from the Pandoc-goodies repo which is based on this other repo. I'm extremely pleased to see that ![](./file.pdf) inserts the complete inline pdf in the html file output, however it's more or less at the m...
Pandoc allows to add attributes to images, which will also work for <embed> elements. The attributes must be given in curly braces. E.g. ![](./file.pdf){width=100% height=80%} The advantage is that this syntax, contrary to raw HTML, will work in many output formats supported by pandoc.
How to change the size of inline pdf in Pandoc generated html files?
1,356,894,572,000
I have a tar.gz called "first.tar.gz". Inside it I have only one folder called "first" (no other folders or files). I want to decompress the tar.gz, so the folder "first" renames to "second". I tried this: tar -zxf first.tar.gz --transform s/first/second/ but it didn't work for me. I didn't get any errors / response, ...
When you use --transform with GNU tar and ask for verbose output with -v, the pathnames you see outputted are the un-transformed pathnames. GNU tar will transform the pathnames according to your --transform expression but will not report these in the output unless you use the option --show-transformed-names. Example: ...
How to change name of a folder inside tar.gz before decompressing?
1,356,894,572,000
When using tab completion for mkdir I found a binary existing called mkdict. But I can't find a man page or other details. A Google search only yields info on a python library with this name, but I don't think this command can be that. What is it? I am running Oracle Linux 8 in a VM, without GUI (just cli). Here is so...
Googling for /usr/sbin/mkdict (because it's really interesting that it's in sbin and not bin) finds this bugreport No man pages found for /usr/sbin/mkdict & /usr/sbin/packer. These binaries are part of the cracklib-dicts RPM package, but no man pages are included in RPM package. from Red Hat, which fits Oracle Linux...
What is the mkdict command and what does it do? (It came in distro but has no man page or help)
1,356,894,572,000
I've several files containg POST body requests. I'd like to send those requests in parallel. Related curl command is like: curl -s -X POST $FHIR_SERVER/ -H "Content-Type: application/fhir+json" --data "@patient-bundle-01.json" Request bodies are files like patient-bundle-xx, where xx is a number. Currently, I'd like ...
With GNU Parallel: doit() { bundle="$1" curl -s -X POST $FHIR_SERVER/ -H "Content-Type: application/fhir+json" --data "@patient-bundle-$bundle.json" } export -f doit export FHIR_SERVER seq -w 99 | parallel -j77 doit Adjust -j77 if you do not want 77 jobs in parallel.
Make parallel http requests using raw data files
1,356,894,572,000
I read on a stackoveflow post that on Linux, when we delete a file, it is not actually deleted, only the link from the inode table is removed to that file. If that is the case, then why isn't delete a constant time operation? I also tried an experiment: I created a folder with 1500 images and created a tar object of t...
Because it's not a simple "mark a single inode deleted" operation: https://www.slashroot.in/how-does-file-deletion-work-linux At least on ext4 file deletion is a whole lot faster than on ext2/ext3 partitions due to the use of extents. In case of SSDs file deletion could be slower than necessary due to the use of the "...
Why is deleting files in Ubuntu slow?
1,356,894,572,000
I'm studying the env command and trying to understand how it works. Here's the command synopsis: env [-iv] [-P altpath] [-S string] [-u name] [name=value ...] [utility [argument ...]] I decided to play around with it and tried: env cd /home/username I get: env: ‘cd’: No such file or directory The result is the same w...
Because cd is not a "utility", it's a shell "bultin", handled by env's parent shell. Read man $SHELL.
Why do I get an error when using cd as env's utility argument? [duplicate]
1,356,894,572,000
I'm trying to perform docker save -o on all images in a docker-compose.yaml file in one command. what I've managed to do is: cat docker-compose.yaml | grep image and this will give: image: hub.myproject.com/dev/frontend:prod_v_1_2 image: hub.myproject.com/dev/backend:prod_v_1_2 image: hub.myproject.com/dev/abd:v...
Your pipeline approach could convoluted as you add more and more commands. Just use the prowess of your native shell, in this case bash for operations like this. Pipe the output of grep image docker-compose.yml into a while..read loop and perform substitutions with it. In a proper shell script this could be done as #!...
How to use xargs to set and change variables on the fly?
1,356,894,572,000
set complete = enhance is put in .cshrc, and we have two files, test_ab_dd.c and test_abc_dd.c. If I type test_ab_<TAB> in the command line, csh DOES NOT autocomplete to test_ab_dd.c. It suggests both test_ab_dd.c and test_abc_dd.c. I have to type all the way to the end. Shouldn't this no longer be ambiguous? It compl...
When you set complete to enhance it considers periods, hyphens and underscores as word separators and not as the characters like you expected. So basically the answer is no since this is a "feature" of setting complete to enhance.
csh/tcsh Tab Completion with "complete = enhance" Strange Behavior
1,356,894,572,000
I can login to the server terminal with username and password. But I can't run the screen command. It says Must be connected to a terminal while I ran this screen -R newNodeServer. I found an answer at Ask Ubuntu: What does the script /dev/null do?, but if I run the command script /dev/null according to that answer,...
My best guess here is: @testteam is trying to run screen command and getting screen complaining about not being able to open terminal. In the answer linked, solution mentioned is to use script /dev/null and that should resolve the issue. @testteam is wondering if that's going to affect any servers running on the mach...
Will the command `script /dev/null` stop or affect the running applications and server? [duplicate]
1,356,894,572,000
is there a nice way to combine: ls -R | grep "^[.]/" | sed -e "s/:$//" -e "s/[^\/]*\//--/g" -e "s/^/ |/" (displays directory as tree) with du -h ... (for each listed dir) Without installing any extra package, like tree, dutree ?
I think, you should revert the order of du -h with tac and then put some formatting with sed. This one should work for "normal" directory names (without control characters): du -h | tac | sed 's_[^/[:cntrl:]]*/_--_g;s/-/|/' Or use find -exec: find . -type d -exec du -sm {} \; | sed 's_[^/[:cntrl:]]*/_--_g;s/-/|/'
du + tree command (without tree installation)
1,356,894,572,000
I know this is a Very Bad Idea™️ with regards to security, I'm ok with that. (Everything is over SSL, so meh.) I have a small wandering Raspberry Pi powered bot, that I'd like to keep in touch with. Which means the bot should try its darnedest to connect to my server. It has Wifi, but no cell chip. I live in a tech...
I do not know of any ready-made tool that can be used for your purpose, but you could build one yourself. The necessary tools and programs are available on Raspbian. Luckily, wpa-supplicant allows for interactive control of scanning for networks and manually connecting to networks. To be specific you can either use ...
Connect to fastest open WiFi (that can reach the Internet) and keep looking if cut off?
1,356,894,572,000
I have a bunch of directory, sub-directory, and filenames that were created in Linux with the following pattern: YYYY - MM - DD T HH : MM : SS (I added spaces for clarity but no spaces are in the directory/sub/file names; YYYY, MM, DD... are integers and '-', 'T', ':' are constants of the expression). These directorie...
Assuming \357\200\242 are octal numbers. Try: rename -n 's/\o{357}\o{200}\o{242}/:/g' 2018-* The command rename works with a Perl regular expression replace. Here it replaces three characters given as octal byte values with a colon. Because of -n this just prints what it would do. So you are able to test without dest...
Replacing bad file, directory and subdirectory names using a regex pattern
1,356,894,572,000
I couldn't find an example online but I'm sure I've seen shell coders use ${1:--} to accept user input. Here's an example: #!/bin/bash var="${1:--}" echo "$var" Then, run it: $ ./test.sh "this is a test" My question is: how is using "${1:--}" to accept user input different from "$1"?
${1:--} will expand to the string "-" if there is no parameter one or if the parameter is empty. So ./test.sh "" will return the string "-" as will the command ./test.sh This is considered to be a useful default in many circumstances where an argument of "-" can mean stdin or stdout. Also it makes sure scripts don't ...
Bash: how to properly accept user input?
1,356,894,572,000
I'm not sure if this would be the right place to ask this question. I've created a sample website using metaexploitable OS, and since this is a terminal-based OS I've been having trouble coding my html site with the vi editor, I was wondering if anyone know how to can access my root directory (and have control, adding...
The PHPMyAdmin login credentials should be these: User: root Password: (leave it blank) Source: Metasploitable 3 Wiki - Vulnerabilities You should not need to install anything (less yet "a database [server]") to access the system. If you have a relative lack of experience using vi, I would recommend you nano, whic...
Metasploitable server
1,533,849,977,000
I'm writing a small perl wrapper to setup environment variables, etc., then invoke a command by the same name. ./foo.pl -a one -b two -c "1 2 3" -d done When I output @ARGV, the "" around 1 2 3 have been stripped. Does someone know how to have perl keep these quotes?
It's not that perl doesn't keep the quotes, perl never gets them. The quotes are just one way to prevent the shell from splitting the text into multiple arguments. The same effect can be achieved with backslash: ./foo.pl -a one -b two -c 1\ 2\ 3 -d done The effect is on both cases a string of 1, space, 2, space, 3. Y...
Keeping quotes passed to a perl wrapper script
1,533,849,977,000
file1.txt (tab delimiter, with the second column containing a string with spaces): A Golden fog B Vibrant rainbow and sunny C Jumping, bold, and bright D Chilly/cold/brisk air file2.txt (tab delimiter): D01 Ti600 A D02 Ti500 B D16 Ti700 C D20 Ti800 B desired output for file3.txt (having a tab delimit...
Although you noted that the files are tab delimited, you did not actually make use of that. Also the common key A, B etc. is in the third field of file2.txt. So: $ awk 'BEGIN{OFS=FS="\t"} NR==FNR{a[$1]=$2;next}{$4=a[$3];}1' file1.txt file2.txt D01 Ti600 A Golden fog D02 Ti500 B Vibrant rainbow and sunny D16 Ti...
Adding a new column in file1 that outputs a string in a reference file file2 that matches the value of another column in file1
1,533,849,977,000
Is it possible to make lines in the info command wider? An example : When running info awk I get the following output, although the terminal size is much wider. 2 Running 'awk' and 'gawk' ************************** This major node covers how to run 'awk', both POSIX-standard and 'gawk'-specific command-line options,...
Unlike man pages, info pages have the line width set when they are created using makeinfo(1) or texi2any(1) (the --fill-column option). The default is 72 characters, which is why you'll usually see line breaks there. As far as I can tell, to reflow an info page you would have to regenerate the file from its original t...
How to change line width in "info" command
1,533,849,977,000
I'm using Debian 8 and want to formating my machine to Debian 9. I pretend to do a minimal install with just the right drivers and the necessary X modules. Everything will be done from the CLI. So, how can I discover the necessary drivers that I'm using and find them on Debian 9 (maybe the names have change?). I have ...
You can get the list of the driver through the command lspci then get the package name that provides this driver. e,g: Get the list of kernel modules driver. lspci -knn A sample output for the wifi driver: 08:00.0 Network controller [0280]: Qualcomm Atheros AR9485 Wireless Network Adapter [168c:0032] (rev 01) Sub...
How discover (and find) all drivers that I'm using for a new minimal SO install?
1,533,849,977,000
This answered question explains how to search and sort a specific filename, but how would you accomplish this for an entire directory? I have 1 million text files I need to to search for the ten most frequently used words. database= /data/000/0000000/s##_date/*.txt - /data/999/0999999/s##_data/*txt Everything I have a...
grep will show the filename of each file that matches the pattern along with the line that contains the match if more than one file is searched, which is what's happening in your case. Instead of using grep (which is an inspired but slow solution to not being able to cat all files on the command line in one go) you ma...
Using a single command-line command, how would I search every text file in a database to find the 10 most used words?
1,533,849,977,000
So, I have a file with insertions hits with some features marks with following aspect (chr, start, end, chr, star, end, number of overlapped base pairs: chr1 69744110 69793325 . -1 -1 0 chr1 82791976 82831348 chr1 82792114 82792615 501 chr1 82791976 82831348 chr1 ...
Question: Concatenate the values in column 5,6 and 7 IF I have a match in the first 3 columns Answer: perl -lane 'if($.==1){@a=@F;next} if($F[0]eq$a[0]&&$F[1]eq$a[1]&&$F[2]eq$a[2]){$a[4].="/$F[4]";$a[5].="/$F[5]";$a[6].="/$F[6]";}else{for($i=0;$i<@a;$i++){printf "\t%s",$a[$i]};print"";@a=@F}END{for($i=0;$i<@a;$i++){...
concatenate columns horizontally, if matches in previous field. Multiple columns to concatenate
1,533,849,977,000
I want to redirect stdin and stdout and stderr at the same time in bash, is this how it's done: someProgram < stdinFile.txt > stdoutFile.txt 2> stderrFile.txt
Yes, your syntax is correct although the following equivalent one is closer to what the shell actually does: < stdinFile.txt > stdoutFile.txt 2> stderrFile.txt command arguments The files used for redirection are open before the command is launched, and if there is a failure in this first step, the command is not lau...
How to redirect stdin and stdout and stderr at the same time in bash? [duplicate]
1,533,849,977,000
I'm running non-GUI ArchLinux on VMWare 14.0. I installed a ssh server on it (by openssh) and connected to my virtual machine by using Kitty 0.70 on Windows 10 [Version 10.0.15063]. My problem is: When I use multiline command, the output of command in Kitty is really weird. For example: On Kitty ssh client: [ddk@myl...
As Stéphane Chazelas remarked, the problem is in your preexec function. When you set the terminal title, you use the command without protecting its special characters. The first newline in the command terminates the escape sequence to set the title, and the other lines get printed. You would also have a problem with b...
Weird output on multiline command in Kitty?
1,533,849,977,000
I have a few thousand subdirectories in a directory, each containing one config.ini file and one JPEG image. The ini file contains (including but not limited to) a section that encodes the time, when the image was taken. [Acquisition] Name=coating_filtered_001 Comment=Image acquisition Year=2017 Month=3 Day=21 Hour=1...
It can be achieved on the command line, but a script that would run on the command line would be an easier solution (I think). Basic steps: Get a list of directories to iterate over: find ${directory} -mindepth 1 -type d Check each directory for the presence of config.ini, and image.jpg. if [ -f ${subdir}/config.ini ...
Copy file to destination based on ini file
1,533,849,977,000
I'm trying to create a dialog menu based on the results of the lsblk command. My goal is to read the first word as the menu item and the remaining words as the menu item description. For example: $ dialog --menu "Choose one:" 0 0 0 $(lsblk -lno name,size | grep sda) This command works, because the dialog --menu op...
You need to do this in 2 parts: # 1. read the output of lsblk, 2 words per line, into an array parts=() while read -r disk data; do parts+=("$disk" "$data") done < <(lsblk -lno name,type,size | grep sda) # 2. send the elements of the array to the dialog command dialog --menu "Choose one:" 0 0 0 "${parts[@]}" Th...
Wordsplitting occurring in quoted variable
1,533,849,977,000
I have following command to clear last entry of bash history(terminal history/command-line history). My Ubuntu 14.04 Trusty Tahr. sed -i '$d' ~/.bash_history But I want to keep last 1,2...n entries and delete the rest, how can I achieve that ? Can be with sed/history/awk or any other command, no problem as far as the...
If you want to keep the last N lines, use tail (for example, the last 20 lines): tail -n 20 "$HISTFILE" > ff && mv ff "$HISTFILE" I'm using the HISTFILE variable since this will always point to your history file, even if you've changed its name.
Clear bash history except last n lines