date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,346,971,085,000
I have a huge text file ~ 33Gb and due to its size, I wanted to just read the first few lines of the file to understand how the file is organized. I have tried head, but it took like forever to even finish the run. Is it because in UNIX, head needs to run through the WHOLE file first before it can do anything? If so, ...
This doesn't really answer your question; I suspect the reason head is slow is as given in Julie Pelletier's answer: the file doesn't contain any (or many) line feeds, so head needs to read a lot of it to find lines to show. head certainly doesn't need to read the whole file before doing anything, and it stops reading...
why does it take so long to read the top few lines of my file?
1,346,971,085,000
I need to grab the first lines of a long text file for some bugfixing on a smaller file (a Python script does not digest the large text file as intended). However, for the bugfixing to make any sense, I really need the lines to be perfect copies, basically byte-by-byte, and pick up any potential problems with characte...
POSIX says that the input to head is a text file, and defines a text file: 3.397 Text File A file that contains characters organized into zero or more lines. The lines do not contain NUL characters and none can exceed {LINE_MAX} bytes in length, including the <newline> character. Although POSIX.1-2008 does not distin...
does head input > output copy all invisible characters to the new file?
1,346,971,085,000
What command could I create that will list the first 4 lines of all the files in a given directory?
[root@xxx httpd]# head -n 4 /var/log/httpd/* ==> /var/log/httpd/access_log <== xxxx - - [06/Dec/2015:22:22:45 +0100] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36 Vivaldi/1.0.303.52" xxxx - - [06/Dec/2015:22:22:46 +0100] "GET /...
List the first 4 lines of all the files in a given directory
1,346,971,085,000
Given a file, foo.txt: 1 2 3 4 5 Say we want to change it to contain: 1 2 3 Why does head -n3 foo.txt > foo.txt leave foo.txt empty?
This happens because the > redirection occurs before the head program is started. The > redirection truncates the file if it exist, so when the head is reading a file it is already empty.
Why can't I trim a file using `head`? [duplicate]
1,346,971,085,000
I need to find all files that cointains in the first line the strings: "StockID" and "SellPrice". Here is are some exemples of files : 1.csv : StockID Dept Cat2 Cat4 Cat5 Cat6 Cat1 Cat3 Title Notes Active Weight Sizestr Colorstr Quantity Newprice StockCode DateAdded SellPrice ...
find + awk solution: find ./backup -type f -exec \ awk 'NR == 1{ if (/StockID.*SellPrice/) print FILENAME; exit }' {} \; In case if the order of crucial words may be different - replace pattern /StockID.*SellPrice/ with /StockID/ && /SellPrice/. In case of huge number of files a more efficient alternative would be (...
Search recursive for files that contains a specific combination of strings on the first line
1,346,971,085,000
When watching the last few lines of a text files for changes, I can use tail -f to continue updating my display. How can I achieve the same thing with head? Is there some solution which behaves like head -n 10 -f <filename>?
The watch linux command executes a program periodically. Maybe you can use this command with the firsts 10 lines for getting the result of command head. Example: watch head -10 <filename> I hope can help you.
How can I display the first few line of a file with updates?
1,346,971,085,000
I've been looking around and haven't found what I'm trying. I have to say I'm petty poor with grep, sed and awk though. I have an alias: alias upgradable='apt list --upgradable' and it gets me what I need: thunderbird/bionic-updates,bionic-security 1:68.4.1+build1-0ubuntu0.18.04.1 amd64 [upgradable from: 1:68.2.2+bu...
To print everything before the first / you can use cut: alias upgradable='apt list --upgradable | cut -d'/' -f1 or awk: alias upgradable="apt list --upgradable | awk -F'/' '{print \$1}'"
Print first word of the output
1,346,971,085,000
I am using a ffi for nodejs, which for the most part has nothing to do with this question, which is really about understanding pipes better, but does offer some context. function exec(cmd) { var buffer = new Buffer(32); var result = ''; var fp = libc.popen('( ' + cmd + ') 2>&1', 'r'); var code; if (!fp) thr...
Normally, tr shouldn't be able to write that error message because it should have been killed by a SIGPIPE signal when trying to write something after the other end of the pipe has been closed upon termination of head. You get that error message because somehow, the process running tr has been configured to ignore SIG...
broken pipe error with popen and JS ffi
1,346,971,085,000
I'm trying to download a bunch of web pages, and once I've downloaded N lines of html, I want the whole thing to stop. But instead, the previous steps in the pipe just keep going. An example to see the problem: for i in /accessories /aches-pains /allergy-hayfever /baby-child /beauty-skincare; do echo $i; sleep 2; done...
The second part of your pipeline is while read -r line; do curl ...$line; done. When this runs: on first iteration shell reads the first value into line, and runs curl; curl (fetches and) outputs the webpage, of which head -n2 extracts the first two lines and exits, closing the pipe between the second and third parts...
aborting previous steps in curl, xargs pipe when head finishes
1,346,971,085,000
So this shell script: #!/bin/bash head >/dev/null; head; almost always gives the same output when called with sequential numbers (e.g. seq 10000 | ./sscript) OUPUT: //blank line 1861 1862 1863 1864 1865 1866 1867 1868 1869 I straced it with strace seq 10000 | ./sscript but wasn't able to explain to myself, wher...
head prints 10 lines by default, but it reads in as much input as it can while doing so - note that GNU head has options which require it to know how many lines there are in the file in total, so reading in as much as it can is not wrong. head reads in as much as it can to fill its buffer, which seems to be 8192 bytes...
Head Script output explanation
1,457,006,052,000
The less command accepts its defaults with an environment variable LESS, so you can export LESS='-F -g -i -M -R -S -w -X -z-4' at the beginning of your session. Is it possible to change the default lines count returned by head and tail in a similar fashion? An alias is not an option, because it breaks explicit option...
Since the old style options like -5, +5 are only recognised as the first argument, you could do: head() case $1 in ([-+][0-9]*) command head "$@";; (*) command head -n 15 "$@" esac That will affect the heads invoked by your current shell. If you want to affect all head invocations, you'd need to write it ...
Is it possible to change the default COUNT value of tail and head?
1,457,006,052,000
Issue I want to be able to : concatenate all files in a directory (regular and hidden), but I would also like to display the title of each file at the beginning of each concatenation. I found some solutions on the web, where I can do #2 with tail -n +1 * 2>/dev/null super neat trick, but it doesn't include hidden f...
With zsh and GNU tail (not all tail implementations can take more than one filename arguments, and not all that do will display the file names): () { (($# == 0)) || tail -vn +1 -- "$@" < /dev/null; } *(ND) -v is to still print the filenames even if there's only one file, D for dotglob, N for nullglob, using an anonym...
How to properly use tail to concatenate all hidden files [duplicate]
1,457,006,052,000
I'm wondering if it's possible to "extract" the first 5 lines of a textfile to a single variable (not an array) for example: head -5 test.txt >$variable (which of course doesn't work) I'm trying to use zenity to display the first lines so I can confirm / cancel depending on the text displayed zenity --question \ --tex...
It's as simple as variable=`head -5 test.txt` # or variable=$(head -5 test.txt) Looks like you are not well versed in shell scripting basics. Here's are nice guides: https://mywiki.wooledge.org/BashGuide/Parameters https://www.tldp.org/LDP/Bash-Beginners-Guide/html/
extract 5 first lines of a text file to a variable
1,457,006,052,000
I need head -z for a script (off-topic, but the motivation can be found in this question), but in my CoreOS 835.13.0 I get head: invalid option -- 'z'. Full head --help output: Usage: head [OPTION]... [FILE]... Print the first 10 lines of each FILE to standard output. With more than one FILE, precede each with a heade...
Swap NULs and NLs before and after head: <file tr '\0\n' '\n\0' | head | tr '\n\0' '\0\n' With recent versions of GNU sed: sed -z 10q With GNU awk: gawk -v RS='\0' -v ORS='\0' '{print}; NR == 10 {exit}'
How can I execute an equivalent of `head -z` when I don't have the `-z` option available?
1,457,006,052,000
I use the tail, head and grep commands to search log files. Most of the time the combination of these 3 commands, in addition to using pipe, gets the job done. However, I have this one log that many devices report to literally every few seconds. So this log is very large. But the pattern of the reporting is the same: ...
awk '$3 >= "11:58" && $3 <= "23:58" && /Unit ID: 1111/{print l"\n"$0};{l=$0}'
Search and Filter Text on large log files
1,457,006,052,000
I have two environments: Mac and Linux. I wonder about the head command: it can show just 2 lines of text if I invoke it like so: vim --version | head -2 I saw this online and ran to the man page to learn more only to discover that neither the osx nor the linux pages have any information that I could decipher describ...
Essentially, you've found the backwards compatibility flags (which, to be honest, I had never known existed.) From the man page: SEE ALSO The full documentation for head is maintained as a Texinfo manual. If the info and head programs are properly installed at your site, the command in...
head command options and reading man files
1,457,006,052,000
OK, so, I have this non-functional shell script, which I am rewriting piece by piece in python, except I am getting an "unexpected "|" error" from the shell (see below): #/bin/sh LINES=`cat $@ | wc -l` for i in `seq 1 $lines`; do head -n $i $@ | tail -n 1 | text2wave -o temp.wav sox "otherstuff.wav" "temp.wav" "sile...
Your question is long and rambling and I don't know what you expect for an answer. Going by your title, I think your focus is on this fragment of Python code: lineone = linecache.getline(filename, i) os.system("echo " + lineone + "|" + "festival --tts") Your problem is that lineone is the whole line, including the fi...
How to execute this particular shell command from Python?
1,457,006,052,000
For a file containing 20 lines, lines 6-10 can be printed using following command: head -10 filename | tail -5 Can this exactly same thing be done without using 'head' and 'tail' commands ?? Please comment the link if similar question already exists.
sed would work well here seq 20 | sed '6,10!d' 6 7 8 9 10 You could use this as well: sed -n '6,10p' Or awk, awk '6 <= NR && NR <= 10'
Command to print few consecutive lines from middle of a file [duplicate]
1,457,006,052,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,457,006,052,000
I have many CSV files in one directory which have various lengths. I'd like to put the second to last line of each file into one file. I tried something like tail -2 * | head -1 > file.txt, then realized why that doesn't work. I'm using BusyBox v1.19.4. Edit: I do see the similarity with some other questions, b...
for i in *; do tail -2 "$i" | head -1; done >>file.txt That should be sh (and hence Busybox) compatible, but I don't have a non-bash available for testing ATM. Edited in accord with helpful comments.
How can I print the second to last line of many files into one file? [duplicate]
1,457,006,052,000
Ultimately I need to grab lines 3-53 from each CSV in each subdirectory. I grabbed the lines from one file like so ('cat' isn't necessarily required): cat /[path]/[file].csv | head -53 | tail -51 and the files I need like this ('find' is required): find /[path]/ -name "*.csv" The problem is I'm having trouble linkin...
Try this: find /path/to/file/ -maxdepth 1 -type f -name '*.csv' -print0 | while read -d '' -r file; do sed -n '3,53p' $file; done Notice print0 option which take care of any possible whitespace characters in the file names.
Pulling lines n to m from list of files found
1,457,006,052,000
I want to read a big log file with 10000 lines everytime. and I use this command: tail -c +offset somefile | head -n 10000 my question is, with the piping of head, will tail read the whole file? updated: I know that tail will read from the offset pos. what I want to know is that: if the file has 20000 lines left from...
tail will die of a SIGPIPE signal as soon as it tries to write to the pipe when it has no reader. So tail will die soon after head has finished outputting its 10000 lines and exited. Because pipes can hold some data (64kiB on Linux) and because tail buffers its output when not to a terminal (8kiB in my test) and head ...
will tail with piping read whole file?
1,457,006,052,000
I'm making a script to preform "dig ns google.com" and cut off the all of the result except for the answers section. So far I have: #!/bin/bash echo -n "Please enter the domain: " read d echo "You entered: $d" dr="$(dig ns $d)" sr="$(sed -i 1,10d $dr)" tr="$(head -n -6 $sr)" echo "$tr" Theoretically, this should wor...
sed takes its input from stdin, not from the command line, so your script won't work either theoretically or practically. sed -i 1,10d $dr does not do what you think it does...sed will treat the value of "$dr" as a list of filenames to process. Try echo "$dr" | sed -e '1,10d' or sed -e '1,10d' <<<"$dr". BTW, yo...
How can I get my bash script to remove the first n and last n lines from a variable?
1,457,006,052,000
Assume I have a file with about 10000 lines. How can I print 100 lines, starting from line 1200 to line 1300?
With awk this would be awk 'NR >= 1200 && NR <= 1300' with sed: sed -n '1200,1300 p' FILE with head and tail: head -n 1300 FILE | tail -n 100 so many options, so many answers on stackexchange :)
How to echo from specific line of a file to another specific line [duplicate]
1,457,006,052,000
I have txt file that I have to swap the first paragraph with last one. I did it but now I don't know how to paste everything in a new txt file. This is my command tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl.txt I tried to use > like this tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl....
try to grouping the commands within { ...; } and redirect the output at the end to a file: { tail -14 gl.txt ; head -n 74 gl.txt | tail -n 68 ; head -5 gl.txt; } > gl_ok.txt note that the last semi-colon before close bracket is mandatory or group commands can be terminated with a newline like below: { tail -14 gl.txt...
How to paste multiple commands output into single output file
1,457,006,052,000
When I run the command head -n 445 /etc/snort/snort.conf | nl I expect lines 1-445 to be returned. However, only up to line 371 is returned: [snip] 370 preprocessor dcerpc2_server: default, policy WinXP, \ 371 detect [smb [139, 445], tcp 35, udp 135, rpc-over-http-server 593], \ What is happening?
The nl utility does not number blank lines by default (and you have blank lines in the input file).
head not returning n lines
1,457,006,052,000
Is there a unix command I can use to stream the items/contents of a directory? Using Node.js, we can read everything into memory with: fs.readdir(dir, (err, items) => {}); but I am looking to stream items, for a very large directory, say with more than 10 million folders/files in it. The tail command is for reading ...
In Unix you can use the find command to stream files & directories or both. The most basic command is this: $ find . This will stream a list of files & directories which can then be passed through to another command via a pipe, | or you can use find's built in ability to run another command via -exec. $ find . -type...
Stream contents of directory instead of reading all items [closed]
1,457,006,052,000
When i ran head file.txt && nl file.txt it did each command in order of occurance (which makes sense). Is it possible to have the head display with numbered lines, so that this: word word word would become this: 1 word 2 word 3 word
head file.txt | nl The | creates a pipeline that takes the output of head file.txt and gives it to nl as its "standard" input. Bare nl without a file name will read its standard input and number it, so you get the output of head numbered as you wanted. Without a pipe providing input, just nl would read input from th...
Is it possible to run head & use nl to number the lines?
1,457,006,052,000
This is how I did to extract the first 100000 lines from my big xml file (2gb): head source.xml -n 100000 > part.xml How can I keep splitting them to 100000 line (or specific file size chunks) until the whole file is separated?
You could use split -l lines_per_file --additional-suffix=.xml source.xml part This will read the file source.xml and split it into chunks of lines_per_file lines each. The result will be written into a series of files partaa.xml, partab.xml, partac.xml, ... If you want to use another number of suffix characters, you...
Split very big xml file into little pieces with specific line number count
1,457,006,052,000
I have a set of .txt file-pairs. In each pair of files, File1 contains a single integer and File2 contains many lines of text. In the script I'm writing, I'd like to use the integer in File1 to specify how many lines to take off the top of File2 and then write those lines to another file. I'm using gnu-parallel to ru...
Extending Gilles answer: parallel 'head -n "$(cat {1})" {2}' ::: File1s* :::+ Corresponding_File2s* You probably have a lot of File1s that you want linked to File2s. The :::+ does that.
How to pass the contents of a file to an option/parameter of a function
1,457,006,052,000
I am using the below command on a file to extract few lines based on chr# ( different chromosome numbers). This is just a single file am working on. i have 8 such files and for each file I have to do this for chr(1to 22 and then chrX and chrY) , am not using any loop, I did it invidually , but if you see that I want t...
You need something like this: { head -n1 S_313_IPS_S7995.coverage.sample_interval_summary; grep "chr1" S_313_IPS_S7995.coverage.sample_interval_summary; } >S_313_IPS_S7995.chr1.coverage or awk 'NR==1 || /chr1/' S_313_IPS_S7995.coverage.sample_interval_summary >S_313_IPS_S7995.chr1.coverage The problem is that the...
Problem with grep on multiple files and not getting desired output
1,457,006,052,000
It seems that I've removed head manually from my /usr/bin/ a couple of months ago. Now that I chance to need it I don't have it. How do I reinstall it without reinstalling the whole distro? My environment: Ubuntu 20.04 LTS Desktop.
You can re-install head by re-installing the package which contains it; from a terminal window, run sudo apt reinstall coreutils (In older versions of apt, pre-1.8.0~rc1, run sudo apt install --reinstall coreutils instead.) You can determine which package is involved by running dpkg -S bin/head
I have removed 'head' manually - how do I reinstall it? [duplicate]
1,457,006,052,000
I have a file with 1 million lines. I want to extract lines from line 10001 to 500000 How to do this?
sed is your friend: sed -n '10001,500000p;500001q' Note that 500001q is needed to stop further file processing. Otherwise it will still read the file till the very end. Thanks for hint on this to @Freddy.
How to extract lines knowing start and end lines
1,457,006,052,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,457,006,052,000
I would like to print the tail of a file (could be also head or cat in general) to the screen but restrict the number of characters per line. So if a file contains ... abcdefg abcd abcde abcdefgh ... and the maximum number is 5, then the following should be printed: abcde abcd abcde abcde How would I do that?
tail yourfile |cut -c 1-5 ....
echo lines of file - but no more than N characters per line [duplicate]
1,457,006,052,000
Here's a command to move all files whose name begin with 0 into a folder called zero : mv [0]* zero Question: What is a command for moving all files whose contents begin with 0 into a folder called zero? Hopefully, there is a short command doing that also. I know that the first character of the contents of a file is ...
There isn't a command to do this. However, it's a straightforward piece of scripting. Work out how to identify a file by its contents and move it: f=example_file.txt b=$(head -c1 <"$f") [ "$b" = "0" ] && echo mv -- "$f" zero/ Work out how to iterate across all the 100,000 files in the directory: find . -maxdepth 1 ...
How to move all files whose contents begin with 0?
1,457,006,052,000
I want to show the 3th and the 7th lines in a file only using commands head and tail (I don't want to show the lines between the 3th and the 7th).
Using the MULTIOS facility in the zsh shell: $ head -n 7 file | tail -n 5 > >( head -n 1 ) > >( tail -n 1 ) line 3 line 7 That is, extract lines 3 through to 7 with head -n 7 file | tail -n 5 and then get the first and last line of that. In bash, this would be equivalent of $ head -n 7 file | tail -n 5 | tee >( head ...
Show particular lines using only head and tail
1,457,006,052,000
I'm trying to use the following approach to subset the output of a manual: man dig | nl | tail -n +389 | head -n 6 However, the output starts at line 304, not line 389. Doing some research, it seems lines marked as "#####################" are not counted. This is very aggravating, and one of my current books was usin...
By default, nl doesn’t number blank lines. man dig | nl -ba | tail -n +389 | head -n 6 will show that tail is doing the right thing. -ba instructs nl to number all lines.
"tail" Is Returning the Wrong Requested Number Lines
1,457,006,052,000
I want to practice using head, uniq and cut, for this data here. I know this thread but it focuses too much on cat and external programs. I would like a simpler answer. I want to take interval from the data file, e.g. lines 800-1600. I am not sure if cut is intended for this task with the flags -n and -m. At least,...
for i in 799 800 do head -n"$i" >&"$((i&2|1))" done <infile 3>/dev/null The above code will send the first 799 lines of an lseek()able <infile to /dev/null, and the next 800 lines of same to stdout. If you want to prune those 800 lines for sequential uniques, just append |uniq. In that case, you might also do:...
select portion of file by line interval [duplicate]
1,457,006,052,000
when I call ls in ~ i get Documents Downloads Templates Desktop Music Videos Public Pictures If i pipe ls to head (e.g. ls | head -30) i get Desktop Documents Downloads Music Pictures Public Templates Videos I am trying to alias ls to ls | head -30 in order to not spam my terminal when doing ls in a big folde...
As the man page for ls describes: -C list entries by columns So, alias ls='ls -C | head -30' Beware that such an alias will preclude you from being able to pass any parameters to ls. For example: ls /tmp/ will likely not do what you expect. You may find that a shell function is a better choice than an alias.
keep formatting when piping ls to head
1,457,006,052,000
I can't remember how to append a command to a shell script. I searched for append, add, concat, and more without success. Basically I have belly = tail -n +"$HEAD" "$1" | head -n $((TAIL-HEAD+1)) if [ -z "${NUMBER+x}" ]; then # check if NUMBER exists tail -n +"$HEAD" "$1" | head -n $((TAIL-HEAD+1)) else tail...
Actually this may have been answered here: Conditional pipeline That answer takes the shell if/then/else mechanic and uses it to embed logic inside pipeline. You can do that also with the && operator, but it is not so clean to read, so I prefer if. Basically in your case the tail line would be like so (please note als...
How can I append a command
1,457,006,052,000
Warning: I used these commands on a drive that had nothing on it (/dev/sdb). Do not attempt this on a drive with anything important on it. I was experimenting some, and I discovered that the following works: $ printf 'hi\n' | sudo tee /dev/sdb hi $ sudo head -n 1 /dev/sdb hi $ Neat. Here's where I'm confused. I tri...
printf 'hi\n' | sudo tee /dev/sdb copies the standard input (from the pipe) to standard output and to /dev/sdb printf 'hi\n' | sudo cat /dev/sdb copies /dev/sdb to standard output. The output from the pipe is not read by cat. So cat does not hang, it is copying the whole contents of the disk to the terminal, and tha...
When storing text on a USB drive, how do I make cat not hang?
1,457,006,052,000
I have a large text file (>200MB). I want to read [n, n+a] bytes across all rows. Suppose there are 1000 rows in the original text file. The output file would be 1000 rows. What I know head -c349 original.text|tail -c28 > output.txt. However, this only outputs one row. How can I iterate though all rows? Example: n = 2...
The cut command will do it. For example, cut -c 10-12 will print characters 10 to 12 (inclusive) from each line of its input. You can write cut -b 10-12 instead if you really mean bytes rather than characters.
How to get nth to n+ath bytes across all rows form a text file in *nix?
1,457,006,052,000
Possible Duplicate: How can I make iconv replace the input file with the converted output? I'm writing a script to change the content of my hosts file but I got stuck on the head output redirection. If I do head -n -1 hosts >hosts my hosts file will result empty and yes, it has more than 1 line.
That's because your shell truncates the file when you redirect to it. This happens before head gets a chance to read it. You can either use a temporary file: head -n1 hosts > hosts.tmp && mv hosts.tmp hosts Or use sponge from the moreutils packate: head -n1 hosts | sponge hosts
Redirecting head output for update hosts file [duplicate]
1,426,771,187,000
In Bash, how does one do base conversion from decimal to another base, especially hex. It seems easy to go the other way: $ echo $((16#55)) 85 With a web-search, I found a script that does the maths and character manipulation to do the conversion, and I could use that as a function, but I'd have thought that bash wo...
With bash (or any shell, provided the printf command is available (a standard POSIX command often built in the shells)): printf '%x\n' 85 ​​​​​​​​​​​​​​​​​ With zsh, you can also do: dec=85 hex=$(([##16]dec)) That works for bases from 2 to 36 (with 0-9a-z case insensitive as the digits). $(([#16]dev)) (with only one...
BASH base conversion from decimal to hex
1,426,771,187,000
Unfortunately bc and calc don't support xor.
Like this: echo $(( 0xA ^ 0xF )) Or if you want the answer in hex: printf '0x%X\n' $(( 0xA ^ 0xF )) On a side note, calc(1) does support xor as a function: $ calc base(16) 0xa xor(0x22, 0x33) 0x11
How to calculate hexadecimal xor (^) from shell?
1,426,771,187,000
# dd if=2013-Aug-uptime.csv bs=1 count=1 skip=3 2> /dev/null d # dd if=2013-Aug-uptime.csv bs=1 count=1 skip=0x3 2> /dev/null f Why the second command outputs a different value? Is it possible to pass the skip|seek offset to dd as an hexadecimal value?
Why the second command outputs a different value? For historical reasons, dd considers x to be a multiplication operator. So 0x3 is evaluated to be 0. Is it possible to pass the skip|seek offset to dd as an hexadecimal value? Not directly, as far as I know. As well as multiplication using the operator x, you can suffi...
passing dd skip|seek offset as hexadecimal
1,426,771,187,000
I would like to know if there is a way of using bash expansion to view all possibilities of combination for a number of digits in hexadecimal. I can expand in binaries In base 2: echo {0..1}{0..1}{0..1} Which gives back: 000 001 010 011 100 101 110 111 In base 10: echo {0..9}{0..9} Which gives back: 00 01 02...99 ...
You can; you just need to break the range {0..F} into two separate ranges {0..9} and {A..F}: $ printf '%s\n' {{0..9},{A..F}}{{0..9},{A..F}} 00 01 ... FE EF
Bash expansion hexadecimal
1,426,771,187,000
Is there a simple command to reverse an hexadecimal number? For example, given the hexadecimal number: 030201 The output should be: 010203 Using the rev command, I get the following: 102030 Update $ bash --version | head -n1 GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu) $ xxd -version xxd V1.10 27oct98 ...
You can convert it to binary, reverse the bytes, optionally remove trailing newlines rev <2.24, and convert it back: $ xxd -revert -plain <<< 030201 | LC_ALL=C rev | tr -d '\n' | xxd -plain 010203 Using $ bash --version | head -n1 GNU bash, version 4.3.42(1)-release (x86_64-redhat-linux-gnu) $ xxd -version xxd V1.10 ...
Reverse a hexadecimal number in bash
1,426,771,187,000
SHORT VERSION (TL;DR) I have 2 small one-line files, seemingly identical : $ cat f1 f2 ./cconv.sh 100 EUR USD ./cconv.sh 100 EUR USD But they are not, there is a 1 byte difference in size : $ ls -l f1 f2 (...) 24 oct. 30 16:19 f1 (...) 23 oct. 30 16:19 f2 $ diff f1 f2 1c1 < ./cconv.sh 100 EUR USD --- > ./cconv.sh ...
c2 a0 is the UTF-8 encoding of the non-breaking space character. It usually looks like a regular space, but isn't recognized as whitespace by the shell. In a few keymaps, something like AltGr+Space, or Option+Space produces a non-breaking space. Which is amusing if your keymap also has e.g. the pipe character behind A...
Space not taken as an argument separator by shell script (could someone please explain that small file difference ?)
1,426,771,187,000
Say for example I've got this C function: void f(int *x, int *y) { (*x) = (*x) * (*y); } When saved to f.c, compiling with gcc -c f.c produces f.o. objdump -d f.o gives this: f.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <f>: 0: 55 push %rbp 1: ...
You can extract the byte values in the text segment with: $ objcopy -O binary -j .text f.o fo The -O binary option: objcopy can be used to generate a raw binary file by using an output target of binary (e.g., use -O binary). When objcopy generates a raw binary file, it will essentially produce a memory dump of the ...
Get hex-only output from objdump
1,426,771,187,000
I have the bash line: expr substr $SUPERBLOCK 64 8 Which is return to me string line: 00080000 I know that this is, actually, a 0x00080000 in little-endian. Is there a way to create integer-variable from it in bash in big-endian like 0x80000?
Probably a better way to do this but I've come up with this solution which converts the number to decimal and then back to hex (and manually adds the 0x): printf '0x%x\n' "$((16#00080000))" Which you could write as: printf '0x%x\n' "$((16#$(expr substr "$SUPERBLOCK" 64 8)))"
How to read string as hex number in bash?
1,426,771,187,000
I am dealing with an embedded system which has some memory that is accessible by a file descriptor (I have no idea what am I saying, so please correct me if I am wrong). This memory is 32 kB and I want to fill it with 0x00 to 0xFFFFFFFF. I know this for text files: exec {fh} >> ./eeprom; for i in {0..32767}; do echo $...
perl -e 'print pack "L*", 0..0x7fff' > file Would write them in the local system's endianness. Use: perl -e 'print pack "L>*", 0..0x7fff' perl -e 'print pack "L<*", 0..0x7fff' To force big-endian or little-endian respectively regardless of the native endianness of the local system. See perldoc -f pack for details. W...
How to write binary values into a file in Bash instead of ASCII values
1,426,771,187,000
Here is the beginning of a file: # hexdump -n 550 myFile 0000000 f0f2 f5f0 f7f9 f1f1 f1f0 f0f0 e3f1 f3c8 0000010 f3f5 0000 0000 000c 0000 0000 0000 000c 0000020 0000 0c00 0000 0000 0000 0c00 0000 0000 0000030 000c 0000 0000 0000 000c 0000 0c00 0000 0000040 0000 0000 0c00 0000 0000 000c 0000 0000 0000050 0000 000c 0000...
\x0a isn't just any hex value - it's the hex value corresponding to the ASCII linefeed character. Since grep is (by default) line-based, the linefeed characters are stripped out before pattern matching takes place. At least with GNU grep, you can change this behavior with the -z option: -z, --null-data Tr...
grep should find a hex value in a file but doesn't
1,426,771,187,000
I would like to switch between hostnames and hex IP addresses, and vice versa. I have installed syslinux-utils on Debian Stretch, which provides gethostip: gethostip -x google.com D83ACD2E How can I switch D83ACD2E back to hostname? In older version of Debian Wheezy, I can use the commands getaddrinfo' and 'getname...
You may be able to use glibc's getent here: $ getent ahostsv4 0xD83ACD2E | { read ip rest && getent hosts "$ip"; } 216.58.205.46 mil04s24-in-f46.1e100.net Another perl approach: $ perl -MSocket -le '($n)=gethostbyaddr(inet_aton("0xD83ACD2E"), AF_INET); print $n' mil04s24-in-f46.1e100.net
convert hex IP address into hostname
1,426,771,187,000
I see sometimes star symbol (*) in the hex editor, like ... 00001d0 0000 0000 0000 0000 0000 0000 0000 0000 * 00001f0 0000 0000 0000 0000 0008 0000 0000 0000 ... It is probably some sort of separator. However, there are many other separators too. What is the meaning of this star symbol in hex data?
It means that one or more lines were suppressed, because they are identical to the previous line; in this case, it means that the line starting at 00001e0 is all zeroes, same as that starting at 00001d0. To determine the number of deleted lines, you need to look at the addresses involved and the length of each line; i...
What is the meaning of Star symbol * in Hex data?
1,426,771,187,000
allHexChars.txt \x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4...
sed -r 'H;$!d;x;s:\n::g;:l;s:(\\x..)(.*)\1:\2:;tl' allHexChars.txt allowedChars.txt > missingChars.txt The above GNU sed script assumes two things as I understood them from the question: inside the files no hex character is listed more than one time the first file contains all the hex characters from the second file...
How can I list the different hex characters between two files?
1,426,771,187,000
I found a problematic sequence of a supposedly UTF-8 encoded text file. The strange thing is that grep seems unable to match this non-ASCII line. $ iconv -f utf8 -t iso88591 corrupt_part.txt --output corrupt_part.txt.conv iconv: illegal input sequence at position 8 $ cat corrupt_part.txt Oberallg�u $ grep -P -n '[^\x0...
e4 75 is indeed an illegal utf8 sequence. In utf8, a byte with the highest nibble equal to 0xe introduces a three byte sequence. The second byte of such a sequence cannot be 0x75, because the high order nibble of that second byte (0x7) is not between 0x8 and 0xb. This explains why iconv rejects that file as invalid ut...
Grep is not matching non-ascii characters
1,426,771,187,000
I am using the following grep script to output all the unmatched patterns: grep -oFf patterns.txt large_strings.txt | grep -vFf - patterns.txt > unmatched_patterns.txt patterns file contains the following 12-characters long substrings (some instances are shown below): 6b6c665d4f44 8b715a5d5f5f 26364d605243 717c8a919a...
A much more efficient answer that does not use grep: build_k_mers() { k="$1" slot="$2" perl -ne 'for $n (0..(length $_)-'"$k"') { $prefix = substr($_,$n,2); ...
Boosting the grep search using GNU parallel
1,426,771,187,000
I have a script which process some information coming from a web page. I guess that because of the encoding of the page, some special characters are encoded in hexadecimal. For example, I have the the string "%2f" that should be translated to "/". How can I, in bash, translate those special characters in hex to ASCII...
Bash has a printf builtin, which can around the same as we could learn in C. The syntax a little bit differs. printf '\x2f' If you don't need to worry about higher-level data consistency problems, you can simply convert an url by this function: function deUrl() { printf "${1//%/\\x}" } (It converts every % to a \...
How to convert an special hex character from an html page in bash? [duplicate]
1,426,771,187,000
od (octal dump) command is implemented in Unix since Version 1. However, I couldn't find a reverse command in the Version 6 Unix manual (1975). Modern ways of reversing od with either xxd or sed do not apply to Unix V6, since sed and awk appeared only in Version 7 (while uudecode, xxd and base64 are not available neit...
Looks like Version 6 Unix didn't include many common tools yet that appeared only in Version 7 (like sed and awk). At that point, Unix was also not commercialized yet, so "reverse hex dump" could be missing simply because there was no wide demand for that operation or because Ken (or some other programmer) provided su...
Undump od (octal or hex dump) in Version 6 Unix
1,426,771,187,000
The hex string 0068732f6e69622f represents the ASCII string /bin/sh, when it's stored in memory in LE-format. Is there any Linux utiltity that will take the hex string and reverse it bytes (2f62696e2f736800), such that xxd -r -ps will display /bin/sh? $ echo -n 0068732f6e69622f | xxd -r -ps hs/nib/ I've looked into x...
$ echo 0068732f6e69622f | rev | dd conv=swab 2>/dev/null | xxd -r -p /bin/sh rev reverses the input string: 0068732f6e69622f -> f22696e6f2378600 dd conv=swab 2>/dev/null swaps every pair of bytes and discards dd's noisy output on stderr: f2 -> 2f, 26 -> 62, ...
How to modify a hex string to LE-format before passing it to `xxd -r` to view its binary contents?
1,426,771,187,000
I have a Java class which the compiler refuses to compile due to \ufeff at the start of the file. I can view the fact that the BOM is present by vim -b file.java, but neither xxd nor hexdump show the two bytes. Is there some way to make them do so?
The U+FEFF character is encoded in UTF-8 over 3 bytes: ef bb bf. xxd or hexdump shows you the byte content, so those 3 bytes, not the character that those 3 bytes encode like vim -b does. To remove that BOM (which doesn't make sense in UTF-8) and fix other idiosyncrasies of Microsoft text files (which is likely the so...
Why does xxd not show the byte order mark?
1,426,771,187,000
If I have, say: blah;PC=1234abcd PC=4444bbcd;blah PC=0000abcd;;foo PC=1234abff How do I grep for lines with PC values in a given range, say 1234ab00 to 1234b0ff. The - range option seems to only apply to the regular 0-9a-A order which obviously won't work for hexadecimal ranges.
grep -f <(printf "%x\n" $(seq -f "%.f" $(printf "%d %d" 0x1234ab00 0x1234b0ff))) file The inner printf prints decimal values of the two hex values. Then seq prints all between them, in decimal. The outer printf prints hex values for all those decimal values. And finally grep -f searches for all those patterns in the...
How to use grep to return lines with an hexadecimal number in a given range?
1,426,771,187,000
So Im using emacs which has a stupendous hexl-mode to view the byte offset in a file right over the hex values similar to: 87654321 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789abcdeff 00000000: 5765 6c63 6f6d 6520 746f 2047 4e55 2045 Welcome to GNU E As a fan of this capability. Wondering if thi...
My favourite use of hexdump is in this format: hexdump -v -e '"%08_ax "' -e '16/1 "%02X "" "" "' -e '16/1 "%_p""\n"' That gives output similar to % echo hello there everyone | hexdump -v -e '"%08_ax "' -e '16/1 "%02X "" "" "' -e '16/1 "%_p""\n"' 00000000 68 65 6C 6C 6F 20 74 68 65 72 65 20 65 76 65 72 hello th...
Make xxd display the the byte offset at the top column?
1,426,771,187,000
I am using hexedit to show/edit disk MBR (512 Bytes, copied with dd). When I open the file, hexedit displays the file as 9 columns, 4 bytes per column (36 bytes per line). That is very unfortunate. I need to have it aligned in a meaningful way (ie 8 columns, 32 columns per line) I could not find any way to do it in th...
Apparently it keys off of the width of your terminal. If you size the terminal just right you can get hexedit to show you 8 columns instead of 9. Example 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................ 00000020 00 00 ...
hexedit: change number of columns (bytes per line)
1,426,771,187,000
I'm trying to do the following: ch='\x21' line="\x21" len=50 for i in `seq 1 $len` do line+="$ch" done Instead of 50 '!' (hex code \x21) I get a list of 50 '\x21'. How can I do this in bash?
Per the man page, "Words of the form $'string' are treated specially". Thus, adding $'' to the mix may help: % bash bash-3.2$ ch=$'\x21'; echo $ch$ch$ch !!! bash-3.2$
Bash script: hex
1,426,771,187,000
I am creating a password generator however I am not get the passwords to append properly. Here is my script i="0" while [ $i -lt 5 ] do echo -n '#' >> passwords.txt && openssl rand -hex 4 >> passwords.txt && echo -n '/' >> passwords.txt && echo -n 'X' >> passwords.txt i=$[$i+1] done Output #b887e0d0 /X#709328...
This should do: for i in {1..5}; do printf '#%s/Z\n' "$(openssl rand -hex 4)" done >passwords.txt I replaced the multiple calls to echo with a single call to printf. Having the call to openssl wrapped inside a command substitution has the side effect of making the line ending disappear, and that newline character...
Appending Echo [Password Generator]
1,426,771,187,000
Assume the data consists of byte offset which is not fixed i.e. the distance of two subsequent file headers varies. The point of this thread is to go through each size of events separately in arrays. Example data fafafafa 00005e58 da1e5afe 00000000 * fafafafa 00005e58 da1e5afe 00000000 * 00000001 ffffffff 555eea72 0...
Problem So many things wrong here #!/bin/bash myarr = ( has got a space between it meaning nothing is assigned if it even runs at all. cat 25.6.2015_test.txt | awk Awk can open its own files no need for cat -F 'fafafafa' '$1~/^[a-z0-9*]+$/ -F is the field separator not record, so all this is doing is removing the ...
Put big data of heterogenous byte offset into arrays by AWK
1,426,771,187,000
So I am often guilty of running cat on an executable file that's a binary file and my terminal usually makes some weird noises and isn't happy. Is there some accepted naming convention for giving an an extension to binary/executable encoded file? I have an executable file (the output of go build -o /tmp/api.exe . and ...
The standard naming practice for executables is to give them the name of the command they’re supposed to implement: ls, cat... There is no provision for extensions which end up ignored from the command line. To check what a file contains before feeding it to cat, run file on it: $ file /bin/ls /bin/ls: ELF 64-bit LSB ...
Standard naming practice for executables (binary file) and how to tell whether a file has has non-printable characters?
1,426,771,187,000
I can find seemingly every variation of hex manipulation by printf except this one. I am trying to send html hex colour values to a text file, built mostly using printf. I can calculate the separate R, G and B values but they normally print in decimal (range 0-255). How can I print them out, a) in two-digit hexadecima...
You can use printf's %x (lowercase) or %X (uppercase) for this, forcing the width to 2 characters: #!/bin/sh r=254 g=127 b=0 printf '%02X%02X%02X\n' "$r" "$g" "$b" The result looks like so: FE7F00
How to print variable value as a hex number?
1,426,771,187,000
I'm trying to find the offset of a hex pattern in a file. This works for one specific value: $ grep -obUaP -m1 "\x00\x50\x53\x46\x01\x01\x00\x00\x34\x01\x00\x00" file.bin 3088:PSF4 However, this pattern includes a few bytes that will change, so I need to include wildcards in my grep. I can't figure out how to do th...
grep -P '\xAB' doesn't look for a hex character. There is no such thing as a hex character. \xAB is PCRE syntax to match a character whose codepoint value expressed in hexadecimal is 0xAB (171 in decimal). codepoint here would be the Unicode codepoint in locales that use UTF-8 and byte value in locales that use a sing...
How to grep for hex pattern w/ wildcards?
1,426,771,187,000
Debian jess 64 I was wondering if it is possible to view the binary of a file in the 00101000 form and edit it, I am able to view it but in the hex form and I am looking to view and edit it in a the 8 digit form, I have been able to view it in the correct form just not edit it so I believe it is possible, So moral of...
with xxd, you can use the -b flag echo 'hello world' | xxd -b which will output 0000000: 01101000 01100101 01101100 01101100 01101111 00100000 hello 0000006: 01110111 01101111 01110010 01101100 01100100 00001010 world. you can redirect that to a file where you can edit it echo 'hello world' | xxd -b > dumped_bit...
Viewing Binary not Hex
1,426,771,187,000
Is it possible to Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String? It is possible that the string may contain any decimal value, which needs to be modified and replaced with its hexadecimal equivalent. awk example: echo "&#047;Test&#045;Test&#045;Test&#045;Test&#045;Test...
With GNU awk, where the Record Separator can be a regexp, and what it matches is stored in RT: gawk -v RS='&#[0-9]+;' -v ORS= '1;RT{printf("%%%02X", substr(RT,3))}' Personally, I'd use perl instead: perl -pe 's{&#(\d+);}{sprintf "%%%02X", $1}ge' See also: perl -MURI::Escape -MHTML::Entities -lpe '$_ = uri_escape dec...
Modify and Replace $1 (awk) or \1 (sed) Values from Decimal to Hexadecimal Globally in a String?
1,426,771,187,000
I'm trying to match exit codes of a process that is documented to return hexadecimal exit codes (e.g. 0x00 for success, 0x40 - 0x4F on user error, 0x50 - 0x5F on internal error, etc.). I'd like to handle the exit code via a case statement, but the "obvious" solution doesn't match: $ $val = 10 $ case $val in > 0xA)...
Yes, the double-parentheses arithmetic operator will display hex values as decimal, letting case match them. $ echo $((0xA)) 10 $ case $val in > $((0xA))) echo match;; > *) echo no match;; > esac match
Match hexadecimal values in a case statement
1,426,771,187,000
In bash I can call PHP and run the following: testKey='8798(*&98}9%"^8&]8_98{9798**76876' testHex=$(php -r "echo bin2hex('$testKey');") echo $testHex And that will result in 38373938282a2639387d3925225e38265d385f39387b393739382a2a3736383736 I've got a system where PHP isn't available, is there anyway to get the same...
If you have hexdump lying around: $ printf "%s" "$testKey" | hexdump -ve '/1 "%x"' 38373938282a2639387d3925225e38265d385f39387b393739382a2a3736383736 -e sets a format string for hexdump, which 'must be surrounded by double quote ( " ) marks'. /1 uses one byte at a time for the format string %x, which prints it in hex...
BASH binary to Hex to match PHP bin2hex function?
1,513,762,571,000
When inserting a USB stick or device to computer, there is always the risk that the device is malicious, will act as an HID and potentially do some damage on the computer. How can I prevent this problem? Is disabling HID on specific USB port sufficient? How do I do that?
Install USBGuard — it provides a framework for authorising USB devices before activating them. With the help of a tool such as USBGuard Notifier or the USBGuard Qt applet, it can pop up a notification when you connect a new device, asking you what to do; and it can store permanent rules for known devices so you don’t ...
How to safely insert USB stick/device to Linux computer?
1,513,762,571,000
I need a software click debouncer solution for RHEL/CentOS. I'm getting intermittent, but frequent, double-clicks registered on single mouse clicks. The issue doesn't happen on Windows 10 as it seems Logitech (or Microsoft) compensate at the software level. Similar issues can be solved in Windows with a simple scri...
This should be fixed with libinput 1.9. Announce: Pointer devices now have button debouncing automagically enabled. Ghost button release/press events due to worn out or bad-quality switches are transparently discarded and the device should just work.
Single clicks register as double-click - software click debounce in CentOS 7
1,513,762,571,000
I bought a new keyboard similar to an old one. The old one works, the new one not. The new keyboard has an unusual HID Descriptor and sends one extra data byte. Is there a Linux driver which support such keyboard (descriptor)? Communication log via cat /sys/kernel/debug/usb/usbmon/3u, byte sequences only (press A, r...
A proper fix was merged into the Linux kernel: https://lkml.org/lkml/2019/3/27/350 It'll be available whenever version 5.2 comes out, and probably back-ported on some distributions.
Linux HID driver for Primax wireless keyboards
1,513,762,571,000
I've been trying for a while but have not been able to find a way to control the lights on a set of controllers from the game Buzz (wired, from Playstation 2). You can see some of my failed attempts in my questions over on Stack Overflow Ruby libusb: Stall error Sending HID defined messages with usblib So I turned t...
with the sony driver loaded the driver provides standard led kernel interfaces: echo 255 > /sys/class/leds/*buzz1/brightness echo 0 > /sys/class/leds/*buzz1/brightness
How can I write to the Buzz controllers HID device created by hid-sony.c to work the LEDs?
1,513,762,571,000
OS: Ubuntu 18.04.3 Kernel: 5.3.8 Hi guys :) I'm trying to create bunch of HID gadgets by using configfs. It was successful until setting up fourth gadget, but kernel emits error message during creation of fifth gadget. Error message was as below. # 4 successive gadget creation g_mouse1 : /dev/hidg0 g_mouse2 : /dev/...
Yes, you can only create 4 HID gadgets, and it's a hard-coded limit: the only way to bypass it is by modifying the code and recompiling the usb_f_hid.ko module. This limitation has to do with how Linux allocates dynamic major/minor numbers for the /dev/hidg# devices. From drivers/usb/gadget/function/f_hid.c: #define H...
Is there a limit to the number of USB gadget can be created with configfs?
1,513,762,571,000
I have read that some USB devices emulate a keyboard and the information these devices send will be as if the information was typed on a keyboard. For example: a magnetic card reader can use an emulated keyboard to give information about the card. This is a question I had asked about keyboard, BT keyboard and stdin wh...
If you hook up two USB keyboards to your system, or a USB keyboard to a laptop with built-in keyboard, you can alternately type characters¹ on each one (or use the left on one keyboard and the right on the other. The emulating devices have nothing more to do than tell the system they are a keyboard, just like a keyboa...
How does an emulated keyboard work?
1,513,762,571,000
I have a Lenovo Duet 3 Bluetooth keyboard, which works fine when connected physically (it has 5 pins for that) to its laptop, and also works as expected when I connect it to my Android phone. However, I cannot get it to work under (Arch) Linux. Kernel and bluetooth stack (bluez-libs etc.) are up to date, so I connect ...
Try to turn on Caps Lock before you detach the keyboard.
Bluetooth keyboard connects, but does not work
1,513,762,571,000
I have a USB barcode scanner and am running a python script that collects data from /dev/hidraw0 and inputs the data into a database. The issue is that every time the scanner collects a code it additionally send it to the terminal and actually tries to log on to the system via the tty. Is there a way to disable the HI...
Open /dev/input/path-to-your-scanner with the grab option. Use the path with symlinks that are constant across boots, not /dev/input/eventX. See e.g. here for a Python evdev library that makes it easy to do from Python. You cannot grab on the hidraw level, and unless you need the HID reports themselves for some reason...
How to direct /dev/hidraw output to python application and not terminal
1,513,762,571,000
I'm looking for a way to replace my keyboard kernel module to a custom one. I have a Logitech MK710 keyboard + mouse set for this purpose, with a USB receiver with those 2 interfaces. Automatically, this USB receiver is managed by default usb, usbhid or logitech-hidpp-device modules, there is some information (note: 1...
Most likely you are being tripped up by initramfs: a copy of the original HID driver module has been stored in there when your current kernel was installed, and if you haven't regenerated initramfs when adding your module, your customized one won't be in there. At boot time, the USB support modules are among the first...
Replace HID device driver with custom one
1,513,762,571,000
I have a gamma spectrometer that connects as a USB HID. When it is inserted dmesg helpfully informs me that two device files were made for it, hiddev0 and hidraw2 (obviously, the numbering isn't important.) Based on the documentation and a visual inspection of the bytes, I want to be reading from hidraw2. But I am c...
Partial answer: The driver is hid-generic, so the next step is to look at the HID descriptor. As root, do mount -t debugfs none /sys/kernel/debug And then look at the contents of /sys/kernel/debug/hid/<dev>/rdesc, where <dev> identifies your device. The HID descriptor describes the format of what you can read from a...
Format of hiddev bytes?
1,513,762,571,000
I have a USB device which communicates with a wireless handheld remote (Dupad G20S Pro Plus). It works great on my debian box. The problem I am trying to solve is preventing the power button on the remote from shutting down the system (I guess the remote is more intended for smart TVs). I did at least figure out via l...
The clue to the solution (for a systemd based linux host) comes from man logind.conf(8). Only input devices with the "power-switch" udev tag will be watched for key/lid switch events. Indeed this tag is added by the default udev rules: SUBSYSTEM=="input", KERNEL=="event*", ENV{ID_INPUT_KEY}=="1", TAG+="power-switch"...
Is it possible to block capabilities in a USB device?
1,513,762,571,000
I have a Kortek touch screen that is exposed to the system, as shown in /proc/bus/input/devices, via two drivers : hid-generic and hid-multitouch I do not want hid-multitouch driver to expose Kortek touchscreen meaning I want to disable Kortek from hid-multitouch. Is there a way I can do this ? can I use quirks ? and ...
While running your kernel, you could unbind the driver from the device, or you could remove your device from the mt_devices id_table inside drivers/hid/hid-multitouch.c in the linux kernel source.
How to disable a device (hardware) from using hid-multitouch driver?
1,513,762,571,000
When a USB mouse is connected how does the system tell it's a mouse? Does it send some signal? I need to implement (something like) a little mouse using an fpga board. I can output x and y coordinates from the board. How do I take the input x and y coordinates from the board and tell the system to control the mouse us...
When a USB mouse is connected how does the system tell it's a mouse? Does it send some signal? Yes, it sends a USB descriptor, from which the host can tell that it is a mouse and how it expects the host to start reading input from it. How do I take the input x and y coordinates from the board and tell the system to...
How is a mouse identified? Then how do I "implement a mouse"?
1,513,762,571,000
I am trying to understand the touchscreens. And I came across these two kernel modules: usbtouchscreen and usbhid. I am confused as what is exactly the difference ? Lets assume I have a touchscreen connected to my hardware via USB, which among the two should I be using ? I know the obvious answer would be: try insta...
A HID (“human interface device”) is a device that is intended to allow humans to interact with the computer, such as a keyboard, a mouse, a monitor, a microphone, a loudspeaker, etc. USB defines a number of standard device classes: types of devices with some common properties. One of them is HID, which in the context ...
what is the difference between usbtouchscreen and usbhid?
1,513,762,571,000
So, I've recently purchased the named keyboard and have been doing some reverse engineering as to how the Logitech Gaming Software does things with it. In this process I've discovered that a few magic packets are sent to the device to unbind the default f1-6 from g1-6; however after this part things get tricky. None o...
There is now a Linux driver for the Logitech G105 Keyboard, it's called sidewinderd, available on github.
Map non-standard hid reports to scancodes for Logitech G105 Gaming Keyboard
1,513,762,571,000
I'm having a weird problem. I've done some hacking based on another person's work to backport support for the internal keyboard on a MacBook Pro 11,5 into kernel 3.19. My GitHub source can be found here. I've done everything I can to ensure that it's as close to kernel 4.2 as possible while still being able to compil...
There is an excellent answer here. The short answer is the command usb-devices (available for most distros in a package called usbutils or something similar) will should give you the info you want on the current driver each usb device is using.
Determine which module is bound by a HID device?
1,513,762,571,000
My Logitech Wave Cordless keyboard presents itself as two devices to the kernel. One is a regular keyboard which works fine, but all the additional keys appear as an event-mouse, such that cat /dev/input/by-id/usb-Logitech_USB_Receiver-if01-event-mouse produces the expected garbage when the buttons are pressed, but xe...
Partial answer: How to get more information 1) Update question with out of lsusb so we can see the vendor and device id. 2) Update question with dmesg output when the combo is recognized. Unplug and replug the dongle to force re-recognition if you can't find it in the boot messages. 3) Run evtest as root on the mouse ...
My keyboard identifies as a mouse
1,513,762,571,000
Recetly I tried to fix my touchpad lags with firmware update, but it crushed my whole touchpad. Now movement is inverted, and right click doesn’t work. My touchpad is ELAN1200 04F3:304E, one of the worst supported touchpad’s ever. However, I still have a hope. I know that touchpad is being recognized as I2C-HID device...
For everyone seeking for the answer, I reached to ELANTech and they provided me the firmware. If anyone ever needs it, feel free to write me [email protected]
I2C_HID touchpad chip data reading
1,513,762,571,000
I've done some work backporting the kernel modules for hid-apple and bcm5974 (with lots of help from SicVolo) and writing DKMS scripts for them so I can maintain compatibility across kernel upgrades: rfkrocktk/hid-apple-3.19 rfkrocktk/bcm5974-3.19 The patches are pretty straightforward, they just add support for the...
My problem was that I was installing the packages into the wrong directories in DKMS. It's important to set DEST_MODULE_LOCATION to point to the directory within the kernel drivers in which your module is supposed to live. I was installing into /updates, but this was the wrong place. I had to move it to /kernel/drive...
Kernel not recognizing new devices from DKMS module?
1,453,743,545,000
On my Arch install, /etc/bash.bashrc and /etc/skel/.bashrc contain these lines: # If not running interactively, don't do anything [[ $- != *i* ]] && return On Debian, /etc/bash.bashrc has: # If not running interactively, don't do anything [ -z "$PS1" ] && return And /etc/skel/.bashrc: # If not running interactively,...
This is a question that I was going to post here a few weeks ago. Like terdon, I understood that a .bashrc is only sourced for interactive Bash shells so there should be no need for .bashrc to check if it is running in an interactive shell. Confusingly, all the distributions I use (Ubuntu, RHEL and Cygwin) had some ty...
Why does bashrc check whether the current shell is interactive?
1,453,743,545,000
I have a cron job that is running a script. When I run the script via an interactive shell (ssh'ed to bash) it works fine. When the script runs by itself via cron it fails. My guess is that it is using some of the environmental variables set in the interactive shell. I'm going to troubleshoot the script and remove the...
The main differences between running a command from cron and running on the command line are: cron is probably using a different shell (generally /bin/sh); cron is definitely running in a small environment (which ones depends on the cron implementation, so check the cron(8) or crontab(5) man page; generally there's j...
Run script in a non interactive shell?
1,453,743,545,000
Since upgrading to Python 3.4, all interactive commands are logged to ~/.python_history. I don't want Python to create or write to this file. Creating a symlink to /dev/null does not work, Python removes the file and recreates it. The documentation suggests to delete the sys.__interactivehook__, but this also removes ...
To prevent Python from writing ~/.python_history, disable the hook that activates this functionality: import sys # Disable history (...but also auto-completion :/ ) if hasattr(sys, '__interactivehook__'): del sys.__interactivehook__ If you would like to enable tab-completion and disable the history feature, you c...
How can I disable the new history feature in Python 3.4?
1,453,743,545,000
I want to create a script that runs when a Zsh instance starts, but only if the instance is: Non-login. Interactive I think I'm right to say .zshrc runs for all interactive shell instances, .zprofile and .zlogin run for all login shells, and .zshenv runs in all cases. The reason I want to do this is to check if ther...
if [[ -o login ]]; then echo "I'm a login shell" fi if [[ -o interactive ]]; then echo "I'm interactive" fi [[ -o the-option ]] returns true if the-option is set. You can also get the values of options with the $options special associative array, or by running set -o. To check if there's an ssh-agent: if [[ -w $...
How would I detect a non-login shell? (In Zsh)
1,453,743,545,000
I want to search and replace some text in a large set of files excluding some instances. For each line, I want a prompt asking me if I need to replace that line or not. Something similar to vim's :%s/from/to/gc (with the c to prompt for confirmation), but across a set of folders. Is there some good command line tool o...
Why not use vim? Open all files in vim vim $(find . -type f) Or open only relevant files (as suggested by Caleb) vim $(grep 'from' . -Rl) And do then run the replace in all buffers :bufdo %s/from/to/gc | update You can also do it with sed, but my sed knowledge is limited.
How to do a text replacement in a big folder hierarchy?