I often view files using less and want to remember what i have just seen in the file. However when I quit less by pressing the q key my xterm window removes the page of less showing the file and only shows my command prompt. How do I keep the less output on my terminal when I quit? Answer less
Tag: bash
finding unique values in a data file
I can do this in python but I was wondering if I could do this in Linux I have a file like this I want to find all the different types of values in the 3rd column by a particular username lets say name 1. grep name1 filename gives me all the lines, but there must be some way to
One Line FTP Server
A lot of times I used the command, which opens a temporary HTTP server on current directory: Now I need to receive files, is there any one-line command that opens a ftp server? I am simply looking for a command line ftp server, no configurations files, no daemons. I tried Twisted as in One line ftp server in python ,
Which signal does ctrl-x send when used in a terminal?
On Linux/Unix there are signals. The CtrlC one (SIGINT) is obvious to me. Now, in some other applications there are signals via CtrlX?! Is that even a signal or does it generate an escape sequence? Is there anything else I can use as something similar to CtrlC ( CtrlV, CtrlX …)? If anyone has a clue, im familiar with C
How do I add a line of text to the middle of a file using bash?
I’m trying to add a line of text to the middle of a text file in a bash script. Specifically I’m trying add a nameserver to my /etc/resolv.conf file. As it stands, resolv.conf looks like this: My goal is to add nameserver 127.0.0.1 above all other nameserver lines, but below any text above that. In the end I want to
Combining two files in different folders in Linux
I have two set of folders that have files with the same filenames and structure. The folder structure is something like this: So what I need to do is to combine (append) all the files with the same name in these folders (file1.txt with file1.txt etc.) into another file inside the outputfolder. After getting these combined files I also need
bash scripting: how to find the absolute path of “symlink/..”?
Given two files: Upon calling parent/scripts/hello.sh from any location, I would like (in the script) to find the full path of the parent directory. In this case parent. The main issue is that parent/scripts/.. refers to generic in unix. On the other hand, everything involving regexes is not generic and may be error prone. Solutions that don’t work: All these
linux find regex
I’m having trouble using the regex of the find command. Probably something I don’t understand about escaping on the command line. Why are these not the same? Bash, Ubuntu Answer Regular expressions with character classes (e.g. [[:digit:]]) are not supported in the default regular expression syntax used by find. You need to specify a different regex type such as posix-extended
Bash: How to tokenize a string variable?
If I have a string variable who’s value is “john is 17 years old” how do I tokenize this using spaces as the delimeter? Would I use awk? Answer Use the shell’s automatic tokenization of unquoted variables: If you want to change the delimiter you can set the $IFS variable, which stands for internal field separator. The default value of
Force a shell script to fflush
I was wondering if it was possible to tell bash that all calls to echo or printf should be followed up by a subsequent call to fflush() on stdout/stderr respectively? A quick and dirty solution would be to write my own printf implementation that did this and use it in lieu of either built in, but it occurred to me