11

A scriptable editor makes this pretty straight-forward! printf '%s\n' '55m22' 'wq' | ed -s input This sends two commands to ed (editing the file named input): 55m22 -- move line 55 after line 22 wq -- save the file back to disk and quit.


9

char* argv[] = {"/bin/sh","sh","-c","/bin/ls", (char*) NULL}; execve(argv[0], argv, environ); Note that you're using argv[0] (/bin/sh) twice, once as the first argument to execve(), and another time as part of the array passed as the second argument to it. This is not what happens in your execl() invocation, there you only have /bin/sh as the first ...


6

It's the kernel file system cache that makes a second find command so fast. As far as I can tell, there's no way to dump and restore the file system cache. If there would be, I'd expect it to be slower to first write the cache to disk and later reread it, than running the find command afresh.


4

A little shorter: ex input <<<"55m22|wq"


3

On Linux terminals we have to separate the dots from the cd command. I'd like to know how/why is this necessary for the parser to work. Probably the regExp or whatever is parsing the commands is not including the dot as a possible character immediately after the command. Yes, in a sense. Shells (well, at least POSIX ones) treat . as a regular character,...


3

Why doesn’t cd.. work in Unix & Linux? Unix shells treat a lot of non-alphanumeric characters (e.g., @_+-{}:,./~) as if they were letters, so you could have commands called a@, b_, c+, d-, etc.  So when the shell sees cd.., it treats it as a four-letter word, no different from cdef or cd56, and so it looks for a command called cd...1  It doesn’t break ...


3

It's somewhat longer in vi than in ed: vi input 55Gdd23GPZZ 55G ... go to line 55 dd ... delete one line 23G ... go to line 23 P ... paste the deleted line before line 23 ZZ ... write file and exit


2

If your directory tree is relatively static (i.e. files and directories are created or removed infrequently), rather than find, you might try using locate. locate(1) General Commands Manual locate(1) NAME locate - find files by name SYNOPSIS locate [OPTION]... PATTERN... DESCRIPTION locate reads one or more ...


1

To temporarily bypass this issue, I ran swapoff -a Then, I commented out the swap partition's uuid in /etc/fstab Then, I commented out the swap partition's uuid in /etc/initramfs-tools/conf.d/resume and finally update-grub update-initramfs -u This worked like a charm


1

For file to know about it, you need to record the magic number stored at the beginning of the file in /etc/magic. The man page for ‘file’ describes the way that file works, and the man page for ‘magic’ describes the syntax to use in the magic file.


1

On Linux terminals the dots from the cd command have to be separated Short answer: Because POSIX requests it. The POSIX parser is a very-very basic one. The word delimiters in posix are either space, tab, redirection operators (< > >| << >> <& >& <<- <>) or control operators (& && ( ) ; ;; <...


Only top voted, non community-wiki answers of a minimum length are eligible