date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,477,679,498,000
this is my fist question on this forum. I'm currently using Linux Mint 17.2 Cinnamon and trying to run Aircrack-ng to show the password of my own Wi-Fi connection, I got the Handshake too. The problem is when I tried to run aircrack-ng CrackFile.cap -w /pentest/passwords/wordlists/darkc0de an error shows that there's ...
The reason is you probably copied that line from a hacking article that was based on BackTrack which may have had such a path, but since you said you are using Linux Mint, you don't have that. So it is exactly as the error says, you probably don't have that file. But you don't need that particular wordlist to test whe...
Aircrack-ng: No /pentest/passwords/wordlists/darkc0de directories
1,477,679,498,000
I'm trying to set up a lab environment using Virtual box with a stand-alone network. To this end, I've set up 1 VM to communicate with the outside world with 2 NICs - 1 for the Internal Network and 1 in Bridged mode to download packages et all. The aim is to learn installing Linux services like Apache httpd, MySQL, D...
There are a few things you can do. My first recomendation would be to visit the Page for open scap and scan your system using the most recent security guideline configurations available for it. Go through your system and try to get it to at least 90% compliance. Focusing on such things as firewalls and SELinux While o...
Setting up a lab environment in VirtualBox
1,477,679,498,000
When tar-ing up large directories (ie. a home folder for a backup/OS reinstall), it is often okay to exclude certain large files such as multi-GB videos. However, due to the all-encompassing nature of a home folder, it is often unrealistic to remember each and every file that may be useful to exclude (with --exclude) ...
I don't think that is possible, but you might simply just exclude large files automatically from your tar. For example, find mydir ! -type f -o \( -type f -size -1000k \) | tar cv --no-recursion -T - -f /tmp/tar which does not save files bigger than 1000k. Here's a script to ask interactively for a "n" reply to sto...
Remove Specific File From Tar Archival Process After the Process Starts
1,477,679,498,000
When you run yum history (or dnf history) it will give you the list of action starting from the last, most recent action being on top of the list. In case you have a lot of history steps your recent action happens to be on top of the list and you need to do a lot of scrolling to get to it. Is there a way to list yum/d...
Yes, as mentioned in the comments, tac command does what was asked. Simply run: dnf history | tac
List `yum/dnf` history in ascending (reversed) order
1,477,679,498,000
Many times, there are slight inconsistencies between two similar linux machines, where (for example) tmux supports colours on Machine M1, and does not support colours on Machine M2, or vi adds comments and formatting automatically on M1 but not on M2, or bash prompt has line-warping on or off, ssh options may not matc...
Based on a comment by @0xC0000022L , I found http://security.blogoverflow.com/2013/01/a-brief-introduction-to-auditd/ which seems to be useful, so adding it as a community wiki answer, in case other folks search for such questions ; I would not want them to simply move on, thinking that there was no answer here.
How to generate a list of configuration files accessed by a tool (eg bash or vi)?
1,426,697,407,000
There are two messages in /var/mail/test. mail Mail version 8.1.2 01/15/2001. Type ? for help. "/var/mail/test": 2 messages 2 new >N 1 test@test Tue Feb 17 15:07 18/628 *** SECURITY information fo N 2 test@test Tue Feb 17 15:25 18/628 *** SECURITY information fo How to get the whole subject li...
Use Linux command line syntax as Read email if you have only email. echo p|mail |grep -A 1 "^Subject:" Read 1st email, change the number you want to read email. echo 'type 1'|mail |grep -A 1 "^Subject:"
How to display entire subject line in `mail`?
1,426,697,407,000
I recently installed Voyager Linux, an linux distribution based on Xubuntu. The problem is that I cant boot it anymore. I have a dual boot system with Windows 8.1, but that's not the problem. I installed the latest build of WPS Office a16 I think, but when installing things got weird, and apps from the dock started to...
Sounds like your installing the "latest build of WPS Office a16 I think" caused problems. Can you remove (purge?) it and see if anything's fixed? Your screenshot indicates that "LightDM" failed, maybe reinstall / reconfigure that might help too. It's not normally a part of XFCE, maybe Voyager uses it (XFCE uses the ...
Can't boot Voyager Linux based on Xubuntu
1,426,697,407,000
I'm running a terminal application via "su" in this fashion: su -c "/path/to/app --args" username This is done from a root context, and 'username' is a less privileged user in the system. The application has signal handlers for CTRL-C and CTRL-Z (SIGINT and SIGTSTP, respectively). One odd problem I've come across i...
Using 'sudo' instead of 'su' solved the problem, as suggested by mdpc.
How to propagate TSTP while running a program as a different user
1,426,697,407,000
Short story I'm looking for the command to enter first found foo-something directory like: cd foo-* but without using wildcard (or other special shell characters). Long story As part of the remote drush build script, I'm trying to find the way of entering folder which folder name could change, but it has common prefi...
Does drush mung backticks and vertical bars?  If not, you could use cd `ls | grep foo- | head -n 1` If backticks don't work, but |, $, ( and ) do, then you could change the above to cd $(ls | grep foo- | head -n 1) If | doen't work, but $, ( and ) do, then you could do cd $(myprog) where myprog is a script that you...
How to enter foo-* folder without actually using wildcard or shell expansions?
1,426,697,407,000
I have been trying to get adb, fastboot, avd and others to work with the latest version of Linux Mint (16 "Petra") I originally got this error when trying to run ADB: ➜ platform-tools ./adb ./adb: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory After l...
I reinstalled Linux in the end. However, downgrading the packages worked fine.
Error Installing "ia32-libs" to run ADB and Fastboot Linux Mint 16 "Petra"
1,426,697,407,000
I made an alias to search for and display all of the processes associated with a specific user account that seem to auto initiate every time I log in, which are about 15 and through a process of elimination I found the parent process. Basically I want the alias to display, just the parent process and not the whole li...
You can try using the Unix command pstree to get a list of the process names in a tree structure. Example $ pstree init-+-NetworkManager-+-dhclient | `-2*[{NetworkManager}] |-abrtd |-acpid |-atd |-auditd-+-audispd-+-sedispatch | | `-{audispd} | `-...
Make terminal print name of parent process OSX [closed]
1,426,697,407,000
So this works: foo -a -b -c "path/file.ext" And this too if I want to pass all files from directory: foo -a -b -c path/* But if I add the quotes foo -a -b -c "path/*" It doesn't work anymore: it says "no such file..." And I think I need to add the quotes in order to escape arguments (I'm using PHP and escapeshella...
The escapeshellarg docs say it turns it into: "a single safe argument" But you want it to be interpreted as multiple arguments. Try doing the expansion using glob first.
How to pass wildcards in command line [closed]
1,426,697,407,000
I am trying to install Sublime Text 2 on Linux Mint (Mate) from this tutorial and I'm stuck on: Next, to create a menu icon press Alt+F2 and type: gksu gedit /usr/share/applications/sublime.desktop When I press Alt+F2 nothing happens; is there another way I can run this command?
You need to understand that the following command is just one way to create/open a file with an editor - here gedit - using root permissions: gksu gedit /usr/share/applications/sublime.desktop Apparently, the tutorial you're following assumes you have these utilities installed and therefore you're getting troubles wi...
ALT+F2 doesn't work in Linux Mint Mate
1,426,697,407,000
I need to do it for over 600 folders with varying names and the .nfo file inside doesn't necessarily have the same name as the folder, he is just a few of them. m0j0@unity ~/files/TV.TL/TEST $ ls -lr total 28 drwxrwx--- 2 m0j0 m0j0 162 Nov 30 19:57 G.S01E07.720p.AMZN.WEB-DL drwxrwx--- 2 m0j0 m0j0 164 Nov 30 19:57 G....
I was able to do it with the following command: for i in *;do touch -r "$i/"*.nfo
How to change folder's creation date to match the creation date of the .nfo file inside?
1,479,135,807,000
I have a folder with more than 10000 text files. The files can be of two types: Type1: called “DNA” Format: header information starting with “>” Line 2 onwards contains only the following letters: “A”, “T”, “G”, “C”, “N” Example: Filename: “ABC123.tab” >DNA1_example TGTTGTTGTTGTTGCTGCTGTTGTTGCTGCTGTTGTTGTTGTTGTT...
Incase someone is interested in the future: Here is my quick and dirty way of doing it using perl: #!usr/bin/perl use warnings; use strict; open(FILE, "ABC123.fa"); my $line_=<FILE>; $line_=readline(*FILE) if $line_=~/>/; close(FILE); if($line_ =~ /L|M|F|W|K|Q|E|S|P|V|I|Y|H|R|D/){ print "Protein\n"...
What Type Of Data does the Input File Contain?
1,479,135,807,000
We want to add the folwing lines: export KAFKA_HEAP_OPTS="-Xmx8g -Xms8g" and: export KAFKA_JVM_PERFORMANCE_OPTS=" -XX:MetaspaceSize=96m -XX:+UseG1GC-XX:MaxGCPauseMillis=20 - XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M-XX:MinMetaspaceFreeRatio=50 - XX:MaxMetaspaceFreeRatio=80" in "content" line can ...
Not a one-liner, but ... $ new_lines='\\nexport KAFKA_HEAP_OPTS=\\"-Xmx8g -Xms8g\\"\\nexport KAFKA_JVM_PERFORMANCE_OPTS=\\" -XX:MetaspaceSize=96m -XX:+UseG1GC-XX:MaxGCPauseMillis=20 - XX:InitiatingHeapOccupancyPercent=35 -XX:G1HeapRegionSize=16M-XX:MinMetaspaceFreeRatio=50 - XX:MaxMetaspaceFreeRatio=80\\"' $ new_conte...
awk/sed/perl one liner to edit json file
1,479,135,807,000
Is there anyway to compact the follow UNIX command: chmod 755 scriptA.ksh | chmod 755 scriptB.ksh | chmod 755 scriptC.ksh | chmod 755 scriptD.ksh The above command makes every KornShell (ksh) script executable, so the compacted command will be shorter in length and still make every ksh script executable.
You can send as many files as you want to chmod; you don't have to individually chmod each file if they all are being set to the same permission set. You have many options here: chmod 0755 *.ksh # If you want to set these permissions on all *.ksh files chmod 0755 script?.ksh # If you want to set these permissions on...
How to compact a chmod UNIX command
1,479,135,807,000
I have a Music folder, in which I have some music tracks, which aren't organized too well. Thus, if I want to find a particular track, I usually type: ls Music | grep <keyword>, where <keyword> is some keyword I expect the filename to have. Then my command line will return the name of the file for which I am looking, ...
You can use xargs for this. It will take what is piped in on stdin and use it as arguments to a subcommand. So in your case it might look like this: ls Music | grep <keyword> | xargs vlc & Now, this command sequence will probably still have some issues, notably whitespace. By default, xargs will split its input on an...
Using Pipeline to Direct Files to Program that Opens Them
1,479,135,807,000
From bash manual about shebang Most versions of Unix make this a part of the operating system’s command execution mechanism. If the first line of a script begins with the two characters‘ #!’, the remainder of the line specifies an interpreter for the program. Thus, you can specify Bash, awk, Perl, or some oth...
The arguments to the interpreter in this case are the arguments constructed after interpretation of the shebang line, combining the shebang line with the script name and its command-line arguments. Thus, an AWK script starting with #! /usr/bin/awk -f named myscript and called as ./myscript file1 file2 results in the...
What is the actual command executed when running a script with a shebang as its name with same arguments?
1,479,135,807,000
I cannot figure out what this command does. It produces 3 numbers in my terminal but with no explanation of what those numbers are. I understand ls -l lists all files in log list format and wc is word count but those numbers don't seem to match anything. Any help?
Whenever you don't understand a command, read its manual. In this case, man wc would show you that: DESCRIPTION Print newline, word, and byte counts for each FILE, and a total line if more than one FILE is specified. [...] A word is a non-zero-length sequence of characters delimited by white space. So, the...
What does ls -l | wc do?
1,479,135,807,000
This is how I'm extracting all the files in a folder (recursively): find -iname \*.epub -exec unzip -o {} \; But the extracted files end up all in the parent folder: Parent (Extracted Epub files) Child (Epub files) Child (Epub files) How to change that command, so that they are extracted in their own folders? Pa...
If you’re using GNU find, use its -execdir action: find -iname \*.epub -execdir unzip -o {} \; This will run unzip from each directory where files are found, ensuring that the files are extracted in the appropriate subdirectory. If you specify the start directory this will also work on at least some BSDs (OpenBSD in ...
How to extract files recursively but keep them in their own folders?
1,479,135,807,000
I am trying to remove all ruby gems before uninstalling ruby. The command I am using is: sudo gem uninstall --all to achieve this. However, I have to type y continually to remove things. Is there a way I could achieve the same thing without having to type y to remove all of the dependencies?
Use yes: yes | sudo gem uninstall --all
Is there a way to use this command without having to type 'y' all the time?
1,479,135,807,000
i have a file is name -ksh.l.15092015.log to delete this file i do this: rm -rf -ksh.l.15092015.log but i have this error: rm: Not a recognized flag: k Usage: rm [-firRe] [--] File... i have do this: rm -rf *ksh* but i have the same errors, why ? Thx for your help !
Execute this: rm -rf ./-ksh.l.15092015.log
can't delete a file starting with a '-' [duplicate]
1,479,135,807,000
Do any of the common Unix/Linux platforms provide a way to query the system administrator contact information from the command line. Obviously a system admin might not include this information when they set up the server, but is there a way to ask for it when it is there (e.g., name or email)?
Assuming there's no organizational procedure, you can't ask your coworkers, and you don't know the company who runs the server... You could see if there's any contact information when you log in, e.g. in /etc/issue, /etc/motd Or you could try emailing root@<this hostname>. Or you could look at who is in the root or wh...
Get contact information of system administrator from the terminal
1,479,135,807,000
As for now, I use my CLI (Command Line Interface) with either rbash, bash, dash, or sh. Given this fact, one can assume that the CLI is not shell dependent, and that even if we will delete all of these shells, we could use some primal/basic/ultralimited CLI. My question If I delete all the aforementioned shells in my ...
No. Your premise that these different shells are all running on top of some more basic CLUI, because they are all fairly similar, is incorrect. Each shell is separately implementing a CLI interface to the kernel, which all look somewhat similar (because they are all 'Unix' shells, which conform more or less rigidly to...
Using a CLI after deleting all shells (rbash, bash, dash, and sh)
1,479,135,807,000
I have a file like: A B C D E F I can get line 2 to 4 using sed -n 2,4p How can get all the lines except 2 to 4?
Your sample command is indeed the inverse of what you want. Read the man page and note that -n disables sed's default behaviour, which is to print each line that is processed. You disable the printing of lines, and then explicitly print only lines in the range 2,4. One solution would be to enable the default printin...
get all lines except x to y
1,479,135,807,000
When I type echo "${PATH}" | tr -s ':' '\n' | nl from inside a bash script and at the terminal I get the same result: 1 /home/nikhil/Documents/Git/Cs/Architecture/bin 2 /home/nikhil/.local/bin 3 /home/nikhil/opt/.nvm/versions/node/v16.13.0/bin 4 /home/nikhil/opt/bin 5 /usr/local/sbin ...
It looks like you have type aliased to type -a. Aliases are not inherited by any shell scripts you run from your terminal, and scripts are run in non-interactive mode by default. Because scripts are run in a non-interactive shell, ~/.bashrc won't be sourced when bash runs the script, so aliases defined there won't b...
`type` command inside bash script, is not showing all paths
1,479,135,807,000
Let's say I have the following file: A random Title 1 BLOCK 1- a block of text that can contain any character and it also can contain multiple lines BLOCK A random Title 2 BLOCK 2- a block of text that can contain any character and it also can contain multiple lines BLOCK A random Title 3 BLOCK 3- a block of text ...
In the TXR language, we could do it like this: $ txr data.txr data [{"title":"A random Title 1","body":"1- a block of text that can contain any character\nand it also can contain multiple lines"}, {"title":"A random Title 2","body":"2- a block of text that can contain any character\nand it also can contain multiple...
Can I use AWK to distribute parameters inside a JSON file?
1,479,135,807,000
I'm looking for a quick and not-so CPU intensive solution to convert 100,000+ lines of text into decimal format. # random ascii string='QPWOEIRUTYALSKDJFHGZMXNCBV,./;[]75498053$#!@*&^%(*' convert () { for ((b=0; b<${#string}; b++ )) do # convert to dec, append colon character, add to array arr...
Perl to the rescue! perl -nE 'say join ",", map ord, split //' < file -n reads the input line by line and runs the code for each line split on an empty regex // splits the input to individual characters map maps each character to its ord join creates a string back from the characters, inserting commas between them s...
Bash: convert 100,000+ characters to decimal format?
1,479,135,807,000
Call me a dreamer, but imagine a world where "every" CLI tool we use had an option to produce a stable output, say in JSON.  Programmatic use of CLI tools like ls, free, df, fdisk would be a breeze.  The way GNU standardized argument syntax conventions, can it standardize the output along the lines of "--json produce...
You would advocate for this on the mailing lists dedicated to the specific tools you are interested in. The available GNU mailing lists are available here: https://lists.gnu.org/mailman/listinfo/ If one or other of the tools you are interested in is not represented by any GNU mailing list, then you would have to inves...
How to advocate for GNU to add a "--json" parameter for all CLI commands to be compliant? [closed]
1,479,135,807,000
w lists all logged in users. Is there any way to get the working directory for the logged in users?
The current working directory is a property of each process, not of users. On Linux, you can get the current working directory of a process of id $pid by doing a readlink() on /proc/$pid/cwd for instance by using the readlink/realpath command or the :a/:A/:P glob qualifiers in zsh. Unless you're superuser, that only w...
Get working directory of logged in users
1,479,135,807,000
I have a file that looks like this: Heading1,Heading2 value1,value2 And another one that looks like this: Row1 Row2 How can I combine the two to become: Row1,Heading1,Heading2 Row2,value1,value2 Effectively appending a column in the place of the first column?
Job for paste: paste -d, f2.txt f1.txt -d, sets the delimiter as , (instead of tab) With awk: awk 'BEGIN {FS=OFS=","} NR==FNR {a[NR]=$0; next} {print a[FNR], $0}' f2.txt f1.txt BEGIN {FS=OFS=","} sets the input and output field separators as , NR==FNR {a[NR]=$0; next}: for first file (f2.txt), we are saving the...
Append first column to file
1,479,135,807,000
I want to change my root password everyday based on the date. The password will be like a combination of a string and the date. The below code is working fine. echo -e "pass"$(date +"%d%m%Y")"\n""pass"$(date +"%d%m%Y") | passwd root But how to call it each time the system starts and at mid night when the date changes...
I'm not sure why you would want to do that. If you're concerned about security, if someone discovers your password on 1 July, they'll know it on 31 July or 15 September... To answer your question, if you want to ensure that the password update is done either at a scheduled time or when the system restarts, you want to...
Dynamic change of Linux root password everyday
1,479,135,807,000
I have a.txt,b.txt,c.txt. Each has different numbers as below: a.txt: 12 14 111 1 15 2 b.txt 12 18 22 23 1 2 c.txt 12 14 15 16 17 1200 The output should contain all the numbers from each file, but without any duplication. Is there a command to export such a thing into a text file? The actual text files include...
You could do like this if there are more number of files, grep '' *.csv | cut -d: -f2 | sort -u > output.csv
how to export all numbers that are unique in a few text files into another file?
1,479,135,807,000
How can I delete all 'nohup.out' files within a directory recursively from my terminal? I'm using CentOS.
There can't be multiple files named nohup.out in a single directory, so I assume you mean that you want to remove it recursively: find . -name nohup.out -exec rm {} + If you are using GNU find, you can use -delete: find . -name nohup.out -delete In bash4+, you can also use globstar: shopt -s globstar dotglob rm -- *...
Delete all 'nohup.out' within a directory recursively
1,479,135,807,000
is there a mysql command that will show me the tables and how many rows they have in them?
Starting in MySQL 5 you can query the virtual table information_schema which contains metadata about the tables within your MySQL database. To find out the number of rows for every table across every database: $ mysql -u root -p \ -e "select table_schema,table_name,table_rows from information_schema.tables;" +----...
What mysql command can show me the tables in a database and how many rows there are? [closed]
1,479,135,807,000
I using a line like this to search for a bunch of files: find . -name "page.php The results are hundreds of lines and I can't see it all. (I'm trying to just copy/paste it into excel to analyze it). I tried this: find . -name "index1.php | less That did something, but I was in this screen that I couldn't figure out...
You want to get this into Excel? Why copy and paste? find . -name "index1.php" > out.txt Copy out.txt to your Excel machine (SCP is the easiest way), open it up.
Limit find results in SSH
1,479,135,807,000
I found out that to look for file size in bytes, I use 'c'. So I can look for file size with 1000 bytes by using: find . -size 1000c But what about different kind of size such as Mb, Gb or even bits? What character or letters do I need to use?
POSIX only specifies no suffix or a c suffix. With no suffix, values are interpreted as 512-byte blocks; with a c suffix, values are interpreted as byte counts, as you’ve determined. Some implementations support more suffixes; for example GNU find supports b for 512-byte blocks c for bytes w for 2-byte words k for ki...
What are the file size options for "find . -size" command?
1,479,135,807,000
I have a CSV file with only 2 columns (but lots of rows) and the occasional irregular row which always starts with an asterisk (*) character and may span more than two columns. Using just the Linux command line, the intended behavior is: If 3 or more consecutive data rows have the same value for column two, delete th...
Using awk: BEGIN { FS = "," } /^[*]/ { print; next } { if (NR > 1 && $2 == word) { tail = $0 ++count } else { if (count) print tail word = $2; count = 0 print } } END { if (count) print tail } This awk script un...
Process CSV file through command line: Remove only middle rows between consecutive row entries if consecutive entries have the same 2nd column value
1,479,135,807,000
When we run !! in a shell session, it prints and run last executed command I was wonder if it is an alias for another long-written bash built-in command and would like to know where it is defined I also know we can interact with shell history with fc command. So, what exactly is !!?
Bash natively provides a 'history' feature. Commands typed in on the shell are saved to a file, which allows each command to be recalled and executed at a later point. Two built-in commands are used to work with this feature. The fc command is used to select one or more commands from history, modify them if required,...
!! bash command
1,479,135,807,000
Create files touch a1.txt a2.txt a3.txt touch s1.mp3 s2.mp3 s3.mp3 then I do find . -name "*.txt" -or -type f -print And it's showing only s1.mp3 s2.mp3 s3.mp3. Why it's not showing .txt files?
Because of the precedence of the operators: the implicit AND (-a) between -type f and -print has higher precedence than the OR (-o); your command is similar to find . \( -name "*.txt" \) -or \( -type f -print \) while you probably want find . \( -name "*.txt" -or -type f \) -print to print all the files.
Find command output doesn't give desire result
1,479,135,807,000
I am trying to save the list of all files including size in a text file. Using the command find *> yourfilename.csv I can export only the names of the files. how can I also add the file size?
With the bash shell on Linux (or on a system with a compatible stat implementation): shopt -s globstar dotglob nullglob for pathname in ./**/*; do if [[ -f $pathname ]] && [[ ! -h $pathname ]]; then stat -c $'%s\t%n' "$pathname" fi done >outfile.csv For bash on OpenBSD (or on some other BSD systems w...
save in a text file list of files with the size of each file
1,479,135,807,000
Let's say I want to search a file for a string that begins with a dash, say "-something": grep "-something" filename.txt This throws an error, however, because grep and other executables, as well as built-ins, all want to treat this as a command-line switch that they don't recognize. Is there a way to prevent this f...
For grep use -e to mark regex patterns: grep -e "-something" filename.txt For general built-ins use --, in many utilities it marks "end of options" (but not in GNU grep).
Stop executables and built-ins from interpreting a string argument starting with - as a switch? [duplicate]
1,479,135,807,000
I have a list of files named EX5_##.bak. I want to each one in a directory named EX5_##. Example EX5_01.bak EX5_02.bak EX5_03.bak and I want to put them in directories. So when I typy ls -l I get : EX5_01 EX5_02 EX5_03 and so forth where those are directory names and the files of the same name are in the director...
A simple shell loop: #!/bin/sh for file in ./EX5_??.bak; do dir=${file%.bak} mkdir -p "$dir" && mv -i "$file" "$dir" done This would iterate over all your EX5_??.bak files in the current directory (? matches a single character). For each file, it creates a directory name by stripping the .bak suffix off from...
Name a series of directories after file names
1,479,135,807,000
I just got a script who upload image file on to a web hoster; at the end I got a file with all the links (one link per line) and I would like to add [img] at the beginning of each link and [/img] at the end.
One way, with the stream editor, sed: sed -e 's/^/[img]/' -e 's!$![/img]!' < input > output Here I've changed the delimiter for the second search & replacement from / to ! so that the forward-slash in the replacement text doesn't need to be escaped. GNU sed would allow an in-place edit with the -i option: sed -i -e '...
Script to add balise [img][/img] on each line of text linux? [duplicate]
1,479,135,807,000
I have such a problem, I'm trying to output a list of movies without the names of directories in the file, but I have a bug, the argument is not found in the -exeс, below is the code $ find . -name "*.avi" -o -name "*.mkv" -exec basename \{} \ > ~/Bash/test/rm/films.txt
Try this instead : $ find . \( -name "*.avi" -o -name "*.mkv" \) -exec basename {} \; > ~/Bash/test/rm/films.txt
Not found argument in -exec [duplicate]
1,479,135,807,000
I have a file named ~/myScripts/assignments.sh which contains various assignments such as variables and aliases. Here's a taste from that file: drt="/var/www/html" rss="/etc/init.d/php*-fpm restart && systemctl restart nginx.service" alias drt="cd ${drt}" alias rss="${rss}" I use these assignments frequently from th...
If the assignments are necessary for "all" bash-sessions, simply put the file in somewhere like /etc/assignments and source it globally from /etc/bash.bashrc. Append this into /etc/bash.bashrc: source /etc/assignments That way, you have all your definitions available in all bash-sessions, for every user, and can main...
Keep file data always available to Bash, without repeated execution (also after reboot)
1,479,135,807,000
I'm trying to learn linux commands, but the output wasn’t what I expected.
ls -1 (one) and ls -l (ell) both work, but produce different listings. Your textbook shows ls -l; in your terminal you have typed ls -1. man ls on your local system for an explanation of all the available options.
Why doesn't the “ls -1” command work correctly? [closed]
1,479,135,807,000
I need to run same command separately for each file at the same time. I've tried for file in *.txt; do ./script <"$file"; done but It starts the first one and waits until it get finished then goes to the next one. I need to start them all together.
If script doesn't require any input from the user, you could use the shell's job processing features to run it in the background for file in *.txt; do ./script <"$file" & done When you append & to a command it's run in the background. Look up job control in the man page for bash (or your preferred shell) for details....
run same command for multiple file at the same time [duplicate]
1,465,302,621,000
How can I include spaces as part of a variable used in an svn command for RHEL bash scripting? Or if there's something else wrong with the following, please advise. The SVN URL variable has no spaces, and this section is working: svn checkout $svnUrl $checkoutDir --username $username --password $password --non-intera...
Better would be to make a function to do it like updateSubProject() { pushd "$1" svn checkout "$svnUrl" "$checkoutDir" --username "$username" --password "$password" --non-interactive --depth immediates --no-auth-cache popd } updateSubProject project-dir updateSubProject path/to/another-project this way y...
What's the proper way to use a variable with spaces in part of a shell script command? [duplicate]
1,465,302,621,000
With bash, how to count new lines appended to file the last 1 minute? What would be smartest if you want to count new lines for the last 1 minute in multiple files simultanously and get output? I have tried a few things, but i can not find a good solution. I might try to use a programming language instead of Bash
Use wc -l twice and subtract the results. before=$(wc -l < yourfile) sleep 60 after=$(wc -l < yourfile) let dif=after-before echo "$dif" You may also just print the last $dif lines: tail -n$dif yourfile Although more lines could have been appended in the mean time, none of the operations are atomic here. If you want...
Count new lines in file last 1 minute
1,465,302,621,000
What is 1? What is 3? What are the numbers called and is there a full list with explanations? $ whatis nvim nvim (1) - edit text $ whatis printf printf (3) - formatted output conversion printf (1) - format and print data Thanks :)
This is section numbers, according to man man: The table below shows the section numbers of the manual followed by the types of pages they contain. 1 Executable programs or shell commands 2 System calls (functions provided by the kernel) 3 Library calls (functions within program libraries) 4 Special files ...
What is the number inside the parenthesis on a Linux command? [duplicate]
1,465,302,621,000
I want to create a hash of more than one source in Bash. I am aware that I can: echo -n "STRING" | sha256sum or sha256sum [FILE] What I need is: STRING + FILE FILE + FILE STRING + STRING STRING + FILE + STRING For example STRING + FILE Save the hash of STRING in a variable and the hash of the [FILE] in a variable. ...
You could create a script like this to hash multiple files, and then hash the concatenation of their hashes. Hashing in two parts like this instead of concatenating all data first should work to prevent mixups where the concatenation loses information on the borders between the inputs (e.g. ab+c != a+bc). #!/bin/bash ...
How can I create a hash or sha256sum in Bash using multiple sources or inputs? What is the recommended method?
1,465,302,621,000
I have a csv file approximately 16,000 rows long, with two fields. The first field contains a list of numeric values, and the second field contains a list of first and names delimited by semi-colons e.g. 3, Jack Mackie; Hanna Jones; Mike Freeland; Ollie Downs; Farrah Anderson; Judy John 9, Jewel ...
$ awk -F, '{split($2,names,";"); print names[$1]}' file.csv Mike Freeland Ed Aslan Eden Anderson
Find a value in a specific position when the only information you have is the position
1,465,302,621,000
Greetings Stack Exchange, My Goal:Execute ls to search the entire directory structure and grep to search for cats.py. Use cat to read the file cats.py. I know that sounds like Gnu/Linux inception. I currently am new to bash and not really familiar with Stack Exchange so forgive me if this formatted terribly. I execut...
Use the find command. It can find the file, and run a command on it. ls has problems, especially if the -l option is given, as then you have a lot more data than you need (file-mode, date, owner, ... ). i.e. (substitute the bits in the «») find «directory» -name '«file-name-glob-pattern»' -exec «command» {} \; e.g. f...
Question about Gnu/Linux command line interface, with grep, ls, and cat
1,465,302,621,000
(self-migrated from ask-ubuntu because it's linux-related, not ubuntu, and my os isn't ubuntu) I'm trying to make a grep that looks like this: grep -r 2019 | grep -riv FAILED | grep -rl DSL I want to get filenames (-l) of files containing 2019 in them, AND NOT (-v) containing FAILED AND containing DSL. Here, only the...
The last grep in the pipeline would be reading from the previous grep (if it hadn't used the -r option, see later), so it would have no idea from what file the data came from, which in turn means it can't report the pathname of the file. Instead, consider using find like so: find . -type f \ -exec grep -q 2019 {} ...
Piped greps for looking inside files
1,465,302,621,000
if I run nrolland@mactoasty ~ $ type -p skhd skhd is /usr/local/bin/skhd I can't compose it nicely with other command like nrolland@mactoasty ~ $ la `type -p skhd` ls: is: No such file or directory ls: skhd: No such file or directory lrwxr-xr-x 1 nrolland admin 29B Jun 4 09:35 /usr/local/bin/skhd -> .....
Use command -v skhd instead: ls -l "$( command -v skhd )" The command utility is a POSIX standard utility, and by using its -v flag it will output the path to the given utility, if it is found in $PATH, unless it's a function, alias or shell built-in utility.
getting only the path out of `type -p prog` command
1,465,302,621,000
I think the position of parameter of any command is not fixed. For example, cp -r ./abc ./def and cp ./abc ./def -r are the same, grep -rnH hello . and grep hello . -rnH are the same... However, today when I was using ldd, I found that I was wrong. Because ldd -r x.so and ldd x.so -r are not the same. The second comma...
Some GNU utilities silently reorganises the command line parameters so that the options and option-argument comes before the operands. This is not standard behaviour. Standard-compliant utilities expect options and option-arguments to come first, and when the command line parser finds the first non-option argument, th...
the position of parameter of command
1,465,302,621,000
I'm trying to compose myself a bash script with the intent of it being used commonly in a terminal. It should start an application as a background process and discard it's stderr output. Here's what I got: for app in $@; do $app 2>/dev/null done It seemed to work just fine with bare applications started withou...
There are two issues: The use of $@ without quotes. This would make the loop iterate over vlc and video.mp4 as two separate items, even if these were within the same quoted string in the invocation of the script. Using a command in a variable. If the command is anything more complicated than a single simple command,...
Create an abbreviation for "2>/dev/null &"
1,465,302,621,000
We all have (or know someone who has) unintentionally misused the destroy-disk (dd) command. What ways exist (if any) to change the command in the following or a similar way: If /dev/sda is given as the output file (of=/dev/sda) the command doesn't run or prompts for confirmation with something like "are you sure abou...
As Arkadiusz said, you can create a wrapper: dd() { # Limit variables' scope local args command output reply # Basic arguments handling while (( ${#} > 0 )); do case "${1}" in ( of=* ) output="${1#*=}" ;; ( * ) args+=( "${1}" ) ;; esac shift || break done # Bui...
Can you make the `dd` command safe?
1,465,302,621,000
I have two BASE64 encoded strings and I would like to get the BASE64 encoding of the binary concatenation of the two string using just the command line. Example: > $ echo -n "\x01\x02" |base64 AQI= > $ echo -n "\x03\x04" |base64 ...
Probably easiest to decode the inputs and encode again: $ echo "AQI=AwQ=" | base64 -d | base64 AQIDBA== (Or just run the decoder separately for each string if reading the string past the = padding offends your sensibilities.) $ (echo "AQI=" |base64 -d ; echo "AwQ=" |base64 -d) | base64 AQIDBA==
Concatenate 2 binary strings in base64 form
1,465,302,621,000
I have the Ecplise Platform (the programming environment, see https://eclipse.org/) on my system. It can be run by typing "eclipse" into the terminal. Now I installed eclipse prolog (see http://www.eclipseclp.org/ ). I followed the instructions from http://eclipseclp.org/Distribution/Current/6.1_224_x86_64_linux/Readm...
Figure out where the new eclipse is installed, and don't just enter eclipse but the full path: /where/the/new/eclipse/is/installed/bin/eclipse If this new eclipse becomes your first choice, you may want to define an alias in your startup files (e.g. .profile for sh): alias eclipse=/where/the/new/eclipse/is/installed/b...
How to run a program via terminal if it shares its name with another program
1,465,302,621,000
How can we replace the following commands netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n by our special command like this: ab1 my mean is I want to use my command ab1 instead of netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n How can I do this?
You could use an alias, or install an executable script in some directory included in your $PATH Assuming bash, a "global" alias could be defined in /etc/bash.bashrc (or ~/.bashrc if a single user need this alias to be defined). Assuming ksh, it would be in /etc/ksh.kshrc (or ~/.kshrc). The alias definition can be don...
How to replace a sequence of commands by a single command in linux?
1,465,302,621,000
When I run: cat filename | cut -f3 | head -1 I get the following result: apple However when I save this to a file by using: cat filename | cut -f3 | head -1 > newfile I then open this using php with the following: $variable = file_get_contents("newfile"); echo $variable; // PRINTS "apple" But when I do the follow...
Indeed, that's your \n, that is counted by strlen In PHP, you have rtrim (http://php.net/manual/fr/function.rtrim.php) to remove all \n, \t, \r, \0 & \x0B from the right end of your string.
cat filename | cut -f2 | head -1 > newfile contains more characters than expected
1,465,302,621,000
I have a file with data as follows: "google1|yoo|dummy|yes|wow|/" + VARIABLE + "/" "google2|hub|lab|dummy|yes|/" + VARIABLE + "/" "google3|short|lab|yoo|/" + VARIABLE + "/" "google4|hello|good-guy|bad-girl|lol|dummy|/" + VARIABLE + "/" "google5|good-guy|a4-123|yoo|/" + VARIABLE + "/" "google6|bad-girl|b4-124|hub|/" + ...
If you have grep with pcre option: $ grep -oP '\|\K[^|]+(?=\|)' ip.txt | sort -u a4-123 b4-124 bad-girl dummy good-guy hello hub lab lol short wow yes yoo -o print only matching pattern -P use pcre regex \|\K positive lookbehind to see if | is there before our string to be extracted similarly, (?=\|) positive look...
filtering data based on delimiter in shell
1,465,302,621,000
I have a *.sh script that's missing the shebang from the first line. Can I fix it with sed?
Insert (i) the shebang with sed, in place operation: sed -i '1 i #!/bin/bash' file.sh With backing up the original file with a .bak extension: sed -i.bak '1 i #!/bin/bash' file.sh Replace #!/bin/bash with actual shebang you want. Example: % cat foo.sh echo foobar % sed '1 i #!/bin/bash' foo.sh #!/bin/bash echo foo...
Sed Usage: Add shebang missing from first line of script [duplicate]
1,465,302,621,000
I run to run a command using the su -s command to start a process. Since I do not want the root user to own the process. I try to do this by issuing the command su -s "$CATALINA_HOME/bin/catalina.sh run" tomcat which returns su: /opt/apache-tomcat/bin/catalina.sh run: No such file or directory How can I run the su -s ...
If you're running su as root, you can use -s to specify a different shell (running as root is necessary here since your tomcat user doesn't have a valid shell), and -c to specify the command to run: su -s /bin/sh -c "$CATALINA_HOME/bin/catalina.sh run" tomcat You might find start-stop-daemon useful; it has a whole sl...
Run su -s with arguments
1,465,302,621,000
In some circumstances, I need to make an official alias for a set of command, which acts just the same as the original software. Like: alias ipython3="source /Users/zen1/miniconda2/bin/activate py3k; ipython; source /Users/zen1/miniconda2/bin/deactivate;" But as I was lazy, I'd like to use another alias for alias ipy...
Use this: alias ipy3='ipython3'
Can I make alias for alias in bash?
1,465,302,621,000
I'm using Linux Mint 17.2 Cinnamon. Somehow, the exit command isn't working.
Nothing's wrong. You were logged in as a root user. When you exited, your session was closed - but you opened this session as a user, so you get back to your user account. It's kind of like opening full screen game - you open it from your desktop, and it looks like it took over your PC - yet when you close it, you go ...
What's wrong with exit command on my terminal?
1,465,302,621,000
I am pretty green when it comes to bash scripts and completely new to command line functionality in bash. I tried my hand at a script which is supposed to be useable both with command line arguments as well as manual setting of variable values, if the user prefers to edit the code directly. The general idea is this: ...
Generally it's easier to help if there's a "minimum verifiable example" of code - something just sufficient to demonstrate the problem. However, here I think I can see the problem. When parsing options you have code like this: while getopts 't:' opt do case "$opt" in (t) slurm_template_file="$OPTARG" ;; ...
Bash script with command line options gets stuck and doesn't set default values for variables
1,465,302,621,000
I have the following file. //TESTCASES=3 //MARK=9 [runscript] nc dec s10 s11 [/runscript] [checks] [/checks] [testcase] // List: 1, 2, 3, 5, 0xA, -1 .global LIST .data LIST: .word 1, 2, 3, 5, 0xA, -1 [/testcase] I am trying to get the text between [runscript] and [/runscript] using grep and regex. I have verifie...
I wouldn't use grep but rather awk: awk ' $0=="[runscript]" {rs++; next} $0=="[/runscript]" {rs--} rs {print} ' file Output nc dec s10 s11 If you really want to use grep, this will work with PCREs and NUL-delimited data. But I would suggest it's harder for people to understand (and maintain) then the awk...
Grep with regex in CLI returns nothing
1,465,302,621,000
I am completely stupefied by this. I am running a weekly script to move log files into a directory. mkdir 2022-04-30 mv *.* 2022-04-30/ when I do so - only files with extension are moved but not ones without. If I try *. is says no files found If I try * it does what I want but it also tries to move the directory 20...
* means zero or more of any character, . means the single character dot. So *.* means any names with a(t least one) dot in there somewhere. On Unix-likes, the dot is just a regular character in filenames, and also there's no difference between files and directories in a regular glob. (If you wanted to match directorie...
How to use wildcard for files without extension
1,465,302,621,000
I was using the term CLI for describing commands like ls. While updating my list of useful commands, I was wondered about one thing. How do we call a shell-like program like mysql for example? doesn't CLI stands for Command Line Interface or Command Line Interpretor? Isn't it more logical to use this term for shell-l...
Wikipedia has a good definition: A Command-Line Interface (CLI) processes commands to a computer program in the form of lines of text. The program which handles the interface is called a command-line interpreter or command-line processor. The term CLI is used in opposition to GUI (Graphical User Interface) which den...
Is "CLI" describing the shell or the commands? [closed]
1,465,302,621,000
using AWK I am trying to fill down a HTML table (rows/columns) based on the previous value. Similar to excel. eg: table user$ csv2html.awk table.csv rowing | fast | good | fast | good swim | | | | slow | | increase | late |...
You need to add something like this to you awk script: for(i=1;i<=NF;i++){ if($i==""){$i=last[i]} last[i]=$i } As you don't show us your script, you have to do that yourself. Beginning with your resulting table, it could look like this: $ awk -F ' *\| *' ' BEGIN{OFS="|"} { for(i=1;i<=NF;i++){ ...
Fill down multiple columns in HTML file with AWK
1,465,302,621,000
Consider the following file layout: . ├── dir_a │   └── file_1 └── file_2 Invoking find . \( -name dir_a -prune \) -a -print gives ./dir_a but invoking find . \( -name dir_a -prune \) -o -print gives ./file_2 Why logical OR (-o) does not include results from the logical AND (-a)?
From Find's specification (GNU Find manual has a similar wording): expression -o expression Alternation of primaries; the OR operator. The second expression shall not be evaluated if the first expression is true. dir_a Since the -name matches and -prune is always true, \( -name dir_a -prune \) is true, thus Find do...
GNU find logical operators with -print
1,465,302,621,000
I've run into situations where symlinks point to other symlinks causing me to have to run multiple ls commands to try to trace where the base file is stored. For example if I want to know the location of java program I run on centos I usually start with /bin/java and have to go 3-4 symlinks deep before I find the ac...
Use realpath, it will expand all symbolic links until a file target. For example, for me: > ls -al /usr/bin/java lrwxrwxrwx 1 root root 22 Jul 13 2019 /usr/bin/java -> /etc/alternatives/java > realpath /usr/bin/java /usr/lib64/jvm/java-11-openjdk-11/bin/java Also readlink alone would give the direct target, while re...
How to find the original file through multiple symlinks? [duplicate]
1,465,302,621,000
If I issue ln -s source.txt symlink.txt and symlink.txt does not already exist, is a link file automatically created called symlink.txt or is the command a noop? If it is a noop, if I just create a blank symlink.txt (touch symlink.txt) and then run the previous command will the operation works as planned? Thanks for t...
Well, that's easy to test: $ mkdir test; cd test test$ ln -s source.txt symlink.txt test$ ls -l total 0 lrwxrwxrwx 1 ilkkachu ilkkachu 10 Oct 23 18:24 symlink.txt -> source.txt test$ cat symlink.txt cat: symlink.txt: No such file or directory (Representing that output as text doesn't do justice to GNU ls, and the co...
Symbolic Link command behavior ln -s
1,465,302,621,000
I have a directory that contains some subdirectories. I know there are two types of files, such as *A*.txt and *B*.txt, contain an "oldString" under that directory. I want to replace them with a "newString". Can I do this in one command? That is can I add the "*B*.txt" somewhere in this command: find . -type f -name "...
You can try: find . -type f \( -name "*A*.txt" -o -name "*B*.txt" \) \ -exec sed -i 's/oldString/newString/g' {} + (here also using + instead of ; to avoid running one sed invocation per file; also has the benefit of returning a non-zero exit status if any of the sed invocations return with a non-zero exit status)....
can I replace a string in two different files with one command?
1,465,302,621,000
Question: Suppose there is a folder with files log1.txt, log2.txt, log3.txt, etc. I would like to find the smallest integer N such that log<N>.txt does not exist. Is there a simple command/way to achieve this? Example: if the folder is empty, the command should return log1.txt. If the folder has log1.txt, log2.txt, th...
As bash script: #!/bin/bash i=1 while [ -f "log${i}.txt" ]; do ((i++)) done echo "log${i}.txt" The while-loop increments variable $i as long as file log${i}.txt exists. The echo outputs the non-existing filename with the next number.
Finding the smallest index such that the indexed log file does not exist in a particular directory
1,465,302,621,000
I want to rename files with zero padded numbers while keeping extension. Example a.abc b.cde c.xyz to be renamed as 001.abc 002.cde 003.xyz :~/x$ rename -n -v 's/.+/our $i; sprintf("%03d.jpg", 1+$i++)/e' * #output> rename(a.abc, 001.jpg) rename(b.cde, 002.jpg) rename(c.xyz, 003.jpg) #then :~/x$ echo "a.abc" a.abc...
rename -n -v 'our $n; my $zn=sprintf("%03d", ++$n); s/[^.]*/$zn/' * This would probably do what you intended. Instead of putting the Perl code inside the substitution, we run it before the substitution. The regular expression [^.]* would match any length string up to (but not including) the first dot in the filename....
Rename files with zero padded numbers while keeping extension using "rename" command
1,465,302,621,000
$ cat test15.sh #!/bin/bash # extracting command line options as parameters # echo while [ -n "$1" ] do case "$1" in -a) echo "Found the -a option" ;; -b) echo "Found the -b option" ;; -c) echo "Found the -c option" ;; *) echo "$1 is not an option" ;; esac shift done $ ...
-d represents whatever it is programmed to represent, which will not necessarily be delete or debug. In curl for example -d is the option for data. In your script -d is not a valid option. Your options are -a, -b, and -c. All of which essentially do nothing. while [ -n "$1" ] do case "$1" in -a) e...
Command Line Options for a script
1,465,302,621,000
I know I can use & at the end of a command to make it run in background and && to connect multiple commands at the same line. However, when I use them together it seems not work. Below is an example. json-server --watch db.json & && python -m http.server 7777 The error message is: bash: syntax error near unexpected t...
It seems you want this json-server --watch db.json & python -m http.server 7777 The && is not to connect multiple commands at the same line, that is ;. The && is a logical AND. You can't use an AND if you don't wait for the command to exit.
How to run multiple command in one line and some commands in background at the same time?
1,465,302,621,000
I am trying to take a directory and create an archive of it in my home directory from another location. I know that the -C option can be used for this, but tar seems to be ignoring it. I've tried $(basename $DEST)_$(date +%F_%H%M%S).tar.gz -C $HOME $(basename $DEST) where $DEST is the path to the directory I want to a...
-C doesn't affect where the archive is created. It only affects which files are added to the archive. So, for example, given tar cvf foo.tar a -C /b c -C /d e, tar will add a from the current directory, switch to /b and add c, switch to /d and add e. foo.tar itself will be created in the current directory (where a was...
Tar ignores --directory option
1,465,302,621,000
My question is basically a follow up question on this topic. I have a file like this: 1000 | line1 100 | line2 10 | line3 I want to do something on $2 if $1 is greater than 20. I wrote something to mimic the 2nd answer but it doesn't work: for a, b in $(cat file.text|cut -d"|" -f 1,2); do if ($1>20) echo $2 done; ...
awk -F'|' '$1 > 20 { system("/path/to/another/script.sh "$2 }' < file.text This tells awk to split the input up into fields based on the pipe symbol. Any first field whose value is greater than 20 triggers the system call to ... anything you want. Keep in mind that the argument (here $2, but it could be $0 or any oth...
looping through a file of two columns
1,516,282,436,000
When I save a command output which contains several lines to a variable directly into my terminal, I have the following results : $ dirs=$(ls -1d /mnt/*/) $ echo $dirs /mnt/ext4/ /mnt/local/ /mnt/remote/ /mnt/test/ $ echo "$dirs" /mnt/ext4/ /mnt/local/ /mnt/remote/ /mnt/test/ However when using it from a posix shell ...
$ ./test.sh /mnt/*/ The glob here expands to the directory names as separate arguments, same as if you wrote them out manually on the command line: $ ./test.sh /mnt/ext4/ /mnt/local/ /mnt/remote/ /mnt/test/ However, in the script itself, you refer to only the first argument, $1: dirs=$(ls -1d $1) If you want to ref...
Posix shell script - Save multi line command output to variable
1,516,282,436,000
I have a very large text list and need a way to extract lines beginning with the same 2 characters, then save those lines to separate files named after those 2 characters. Example List: abWEye7kgw7 abff34ZSrZf abke8mzMyma b2R5mPZGbCb b2zhhCeLZzZ b2q2T5rkACp k9ekzbc8nUh k9QzXBUrNT7 k92RtdXntZ3 vrTtR9G...
$ awk '{ f = substr($0,1,2) ".txt"; print >f }' file.in $ ls ab.txt b2.txt file.in k9.txt vr.txt $ cat ab.txt abWEye7kgw7 abff34ZSrZf abke8mzMyma This can obviously be solved in the shell too, but awk is better suited for parsing text files. The substr() picks out the first two characters of each line in the in...
How to extract lines starting with the same first 2 characters, then output to separate files?
1,516,282,436,000
I want to search for bash commands in the bash itself. When I forget the name of a command I want a fast way to find it. For example "search for file" should suggest "find".
The closest thing you can get is via one of these commands: man -k search apropos search These will return all manpages whose description contains the word "search". You can restrict the search to pages in section 1 (user commands) and 8 (admin commands) with the (non-standard) -s option: man -ks1,8 search That woul...
Search for bash command
1,516,282,436,000
I'd like to write a script that reads a file and passes every line as options (or "option arguments") to a command, like this: command -o "1st line" -o "2nd line" ... -o "last line" args What's the simplest way of doing this?
Here is one possibility: $ cat tmp 1st line 2nd line 3rd line 4th line $ command $(sed 's|.*|-o "&"|' tmp | tr '\n' ' ') As glennjackman points out in the comments, word splitting can be circumvented by wrapping in eval, though the security implications of doing so should be appreciated: $ eval "command $(sed 's|.*|-...
How to pass every line of a file as options to a command?
1,516,282,436,000
I have a file similar to the following: random,test123,MyCompany, Inc. hello,12345,TestCompany, LLC I want to remove the commas from the third column so I'd have something like this: random,test123,MyCompany Inc. hello,12345,TestCompany LLC How would I do this?
This is easy with sed: sed 's/,//3' file Try it online! If you want to directly apply the modifications in your input file, then run: sed -i 's/,//3' file
Remove character from column of CSV
1,516,282,436,000
I am running the below directly in bash command line prompt: $ PIDS= ;while read name; do (cd $name; npm install) & echo started install; PIDS+=($!); done < <(\ls); for pid in ${PIDS[@]}; do wait $pid; done; And I get this: -bash: !: event not found I assume the ! symbol is being used to do command history substitut...
I haven't been able to reproduce your problem with bash 4.3 and 4.4, so here is a generic answer. Your problem is triggered by the ! in PIDS+=($!), ! being the start of history substitution (which is enabled by default with an interactive shell). Either disable history substitution with set +H, or quote the ! (not des...
$! doesn't work on command line
1,516,282,436,000
I have a list of files that are space separated and I want to use the touch command to update their timestamps in that order. But when I supply the filenames as arguments, the timestamps get updated in a different order. touch 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt 11.txt 12.txt After running t...
With no time specified, touch changes the timestamps of all its arguments to the current time at the time each file is touched, which should produce a different timestamp for each file, but in many cases this ends up applying the same timestamp to all its arguments; you can verify this by running stat on all the touch...
Execution order of touch command arguments
1,516,282,436,000
I'm aware that this is a really simple question, but I'm struggling to find a solution to this . I need to automatically find and replace in the /etc/aliases file the following section: # Person who should get root's mail #root: marc And it needs to look something like: # Person who should get root's mail root: ...
On a GNU system, you can use this: sed -i '/^#[[:blank:]]Person/{n;s/#root:[[:blank:]]\+marc/root:\[email protected]/;}' file It searches for a line beginning with # Person. Then switches to the next line and replaces #root:<blanks>marc with root:<tab> .... The -i flag edits the file inplace. -i, \+ and \t are GNU ex...
SED - Find and replace with special characters (#, , % )
1,516,282,436,000
I have a script that updates some remote systems with my laptop's IP and CIDR on the WAN, how the Internet sees me, in other words. I use the following to get my IP on the WAN in bash: dig +short myip.opendns.com @resolver1.opendns.com How can I get the CIDR for my IP on the WAN in bash as well?
In general the short answer is this is not practically feasible. In the very specific case you have access to your firewall your firewall has a public IP address on its outside interface and you can access a shall prompt on the firewall. You can do something like this: ssh [email protected] 'eval $(ipcalc -np `ifconfi...
Get CIDR of my IP on the WAN
1,516,282,436,000
Can you please describe and explain each part of the command prompt pi@raspberrypi ~ $ This is what I saw when I first logged in to my Linux computer.
You can set this with the PS1 environment variable. pi is the username. raspberrypi is the name of the server. ~ is the current directory (and means 'home dir') $ is the prompt - $ denotes a non privileged user. (# denotes root). PS1 is probably set to: PS1='\u@\h \w \$'
Describe the prompt I see when I first logged into the Linux computer
1,516,282,436,000
Marias-MacBook-Air:~ mariasharapova$ ls -a /home . .. Marias-MacBook-Air:~ mariasharapova$ ls -a-1 /home ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...] Marias-MacBook-Air:~ mariasharapova$ ls -a-l /home ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1...
You don't have a space between -a and -1, so ls is trying to interpret the - as an option, not as signifying an option. Add a space, or just use ls -a1 and it should work properly. Although I have to admit, -1 seems a rather unusual option - I usually ls -al as opposed to ls -a1.
Why does my "ls -a-l /home" not work?
1,516,282,436,000
I come from the windows world trying to switch to Linux. Sorry for the naïve question but is there something like "common Linux commands"? For example in Windows, the command line is pretty limited, but it is common between all windows. So if you know what the dir or mkdir command does and what switches it takes, you...
The beautiful thing about *nix, and open source in general, is that you have no shortage of resources. Most *nix CLIs will behave similarly, though there are outliers. Don't worry about them for now. Get BASH figured out. It'll be your interpreter 99% of the time. Learn vim, and know right now that most distro's only ...
Is there something like "common Linux commands"? [duplicate]
1,516,282,436,000
After I have learned that the $$ special variable holds the process number of the shell, I tried too kill the shell by simply: kill <pid obtained by echo $$>, however this did not work, I also tried some variations, but them also had no effect.
You can, but the shell tries hard not to die unless it's absolutely sure that's what is required. SIGHUP works (as does SIGKILL), and you can try this - kill -HUP $$ (If you prefer numeric signal identifiers the HUP can be replaced with 1.) The reason that SIGHUP works is that this is the signal that would have been ...
Why can't I kill the shell using the PID obtained from the $$ special variable? [duplicate]
1,516,282,436,000
Here is the sample input: AbbigailAbieAbbyAbbi Using sed, I have separated them into 4 characters but seems like I got a problem because I have to separate the first 8 characters first then add spaces after every 4 characters sed 's/.\{4\}/& /g That is the code I used for sed. Any help? The output should be Abbigai...
With GNU sed: $ echo AbbigailAbieAbbyAbbi | sed -e 's/.\{4\}/& /2g' Abbigail Abie Abby Abbi
Add space after 8 characters then add space after every 4 characters
1,516,282,436,000
I'm trying pass a URL to mpv for it to play it as a network stream. This can be done in bash with the following syntax: $ mpv http://myvideosite.com However, zsh wants to evaluate the URL as (presumably) a file path. Running % mpv http://myvideosite.com gets the following response: zsh: no matches found: http://myvi...
I assume you've inadvertently trimmed the important part of your command lines out here: the URLs in question contain a ? character (or a *). ? and * are special glob matching characters to the shell. ? matches a single character in a filename, and * matches many. When zsh says: zsh: no matches found: http://myvideosi...
Must pass urls in quotes
1,516,282,436,000
Say I'd like to use the file -f - command inside a script, and send some input using the stdin, when I'm finished I'd like to terminate it gracefully, but unfortunately I haven't found any way to do this (and yes I did read the man page :) ).
You only need to send EOF signal when you finished. To do that, you need to press CTRL + D: $ file -f - test.py test.py: a /usr/bin/python script, ASCII text executable test.pl test.pl: a /usr/bin/perl script, UTF-8 Unicode text executable <CTRL + D here> or you can send to file inside shell script via ...
file(1) command termination when using the -f - option