Tag Info

Hot answers tagged

10

You can mount a tmpfs partititon and write the file there: mount -t tmpfs -o size=500m tmpfs /mountpoint This partition now is limited to 500 MB. If your temporary file grows larger than 500 MB an error will occur: no space left on device. But, it doesn't matter when you specify a larger amount of space than your systems RAM has. tmpfs uses swap space ...


6

I think you want to be very careful about using file in a circumstance where you give it completely untrusted input. For instance, RHEL 5 file will identify this: GIF87a <?php echo "Hello from PHP!\n"; ?> As "GIF image data, version 87a, 15370 x 28735". The PHP interpreter has no trouble executing that input. That lack of trouble is the basis for ...


6

With a large enough value of 'undolevel', Vim should be able to undo the whole day's changes. If you quit Vim in between, you also need to enable persistent undo by setting the 'undofile' option. Vim captures not just a sequential list of commands for undo, but actually a tree of all changes. It also has several commands around undo (cp. :help ...


5

Similar to Archemar's suggestion, you could script this with ed: printf %s\\n ${linenr}m${addr} w q | ed -s infile i.e. linenr # is the line number m # command that moves the line addr=$(( linenr + 1 )) # if you move the line down addr=$(( linenr - 2 )) # if you move the line up w ...


5

As @Celeo shared I think you chances are small. What you should have done before installation are two things :- a. Make a backup of the content on the D drive before doing that. b. Make D partition smaller and then make E which is free, blank and has nothing. Then when you install choose E to install Ubuntu or whichever GNU/Linux distribution you want to ...


4

When you run > /tmp/foo.txt, you are overwriting the contents of /tmp/foo.txt with the output of sed 's/old text/new text/' file1.txt. Since /tmp/foo.txt doesn't exist when you run this command, bash will create that file for you and then write it. Then, when you use the -p flag to cp, you are copying the permissions and attributes of /tmp/foo.txt to ...


4

The feature that you are looking for is handled by the shell. It is called pathname expansion. For example, suppose that you are in a directory that contains the files file1 file2 file3 .. file50. You can specify all the files in the directory that start with file as an argument to to your perl script via: ./perl_script.pl file* To the shell, * means ...


4

If you want to grep recursively in all .eml.gz files, you can use: find -name \*.eml.gz -print0 | xargs -0 zgrep "STRING" You have to escape the first '*' so that the shell does not interpret it. "-print0" tells find to print a null character after each file it finds; "xargs -0" reads from standard input and runs the command after it for each file; ...


4

As one who has worked in a multitude of ?nix environments, I have had to write in a wide variety of shells. Believe it or not, across platforms, the shells are not the same. So if you maintain your personal library in multiple shells (when necessary) it is very helpful to use extensions to ID the shells. That way when you move to another platform and the ...


4

To get the octal permission notation. stat -c "%a" file 644 See the manpage of stat, -c specifies the format and %a prints the permissions in octal. Or for multiple files and folders: stat -c "%a %n" * 755 dir 644 file1 600 file2


4

The command will output the data from device /dev/null to the given file (mailbox of the root account). Since /dev/null responds just with end-of-file when reading from it nothing will be written to the file, but with the redirection > the shell will have cleared the file already. Actually this is equivalent to writing just > /var/spool/mail/root ...


4

There's a command called file that makes (good but not always perfect) guesses about the file type. One way to use that command could be: find your_web_pages_directory -type f -name "*.*" -print0 | xargs -0 file | awk 'BEGIN{FS=": +"}$2~/[Ff]ont/{print $1}' | xargs rm -- The find command looks for ordinary files with extensions (you may ...


4

It's not possible because ctime is changed always if there is a change of mtime. Here is the explanation: Let's see from file perspective: ctime is the inode/file change time, it means that ctime is updated when the file attributes are changed, like changing the owner or the permission. mtime is the file modify time, it's updated when you modify the ...


4

AFAICT, no. The problem is that the gzip process will create a new file and will free the previous (the unzipped) one, including a removal from the directory. If no other hard-link in the filesystem is pointing to the file it will get lost once the last file descriptor refering to it is closed. For the future you'd be advised to synchronize the access to ...


4

If I undersood the question correctly you need files in myfiles which do not have symlinks in images: #!/bin/bash OIFS="$IFS" IFS=$'\n' files="$(find myfiles/ -type f -name '*.jpg' -or -name '*.cr2')" for f in $files; do list="$(find -L images/ -xtype l -samefile "$f")" if [[ "$list" == "" ]]; then echo "$f does not have symlink." fi ...


3

Try this with Ubuntu: ramtmp="$(mktemp -p /dev/shm/)" tac scriptnameYYYYMMDD.txt > "$ramtmp"


3

I'm not sure you will like this answer, but, in my experience too, using PTP has always caused a high WTF/min. Presumably the camera itself restricts writing in the root folder, or something equally sensical. I would suggest getting your hands on a CompactFlash reader, mounting the filesystem directly, and using that type of access to copy your firmware ...


3

I trust that you’re familiar with the basic -rwxrwxrwx notation.  You probably know that set-user-ID gets you -rwsrwxrwx and set-group-ID gets you -rwxrwsrwx.  But, without further clarification, these forms are ambiguous.  If you see -rws------, you might assume that the mode is 04700 (set-user-ID + user read + write + execute), but how do you know that the ...


3

Ok, so you want to run a command in each directory in a directory tree — the current directory, its subdirectories, their subdirectories, etc. The first thing to do is enumerate the directories in question. With the find command, tell it to list only directories: find . -type d The command you want to run in each directory is gmic ./*jpg -gimp_montage ...


3

Using the utility rename from util-linux, which CentOS 6 provides, and assuming bash: rename $'\n' '' wget_* This asks to delete newline characters from the names of listed files. I recommend trying it out on a small subset to ensure it does what you want it to (note that rename on CentOS 7 supports a -v switch to show you what changes it is making). If ...


3

By default, rm does not delete directories. If you want the directories to be removed, use rm -rf. If you want to suppress the message, use rm <dir> 2>/dev/null. Note that all other error message get suppressed, too.


3

You should probably be using the Pheaders, not the Sheaders. There's usually far fewer of them, and they correspond directly to pieces of the file that get mapped into memory by the kernel's ELF loader. I'm forced to use the contents of /usr/include/elf.h in the following, as you example doesn't include Elf64_Phdr definitions. Elf64_Off p_offset; /* ...


3

65534 is some kind of default/nobody UID & GID value. Your VPS provider made some sort of mistake when they copied over your container. For example they used rsync but failed to use its --numeric-ids option. The user IDs inside your container don't exist outside the container and some copy tools, upon seeing UIDs and GIDs that they can't resolve, revert ...


3

ls itself won't show this information. You can pipe the output of the find to file -f -, as follows: $ find /usr/local/bin | file -f - /usr/local/bin: directory /usr/local/bin/apt: Python script, ASCII text executable /usr/local/bin/mint-md5sum: ASCII text /usr/local/bin/search: ...


3

This is about as inelegant as the other answers, but maybe less inefficient: locate --regex --basename "xfce4-keyboard-overlay$" | while IFS= read -r f; do [ -f "$f" ] && printf "%s\n" "$f"; done (broken into two lines for readability).  The above will handle names containing spaces.  The IFS= seems to be necessary to handle names with ...


3

With zsh: print -rl ${(0)^"$(locate -0 ...)"}(N.) (0) is a parameter expansion flag that splits on NUL characters (as we use locate -0), short for (ps:\0:). With ^, instead of adding (N.) at the end of the array, we add it to each element. (N.) is a glob qualifier, . to match only regular files, N to remove the element if it doesn't match (doesn't exist ...


2

Launch your process through strace: strace -fe open skype You will see the list of each open() syscall, that is every file (or connection) the processes opens during its life. Looking at currently opened file descriptors will not provide a log but only a "snapshot" of what the process accesses right now.


2

Just loop over all lines in the file: while read line do echo "function $line() { return stuff; }" > "$line/function.js" done < foo.txt Of course this assumes you have already directories named as lines in the foo.txt. If this is not the case then first create them with mkdir "$line". Another approach, with awk instead of loop would be: awk ...


2

Recursion alone is easy: -r, --recursive Read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -d recurse option. -R, --dereference-recursive Read all files under each directory, recursively. Follow all ...


2

You can do this with perl, using the excellent XML::Twig module. Assuming I've understood you correctly, the basics task is copying the 'verse content' element from one file, and 'everything else' from another file, and making a new file. So: #!/usr/bin/perl use strict; use warnings; use XML::Twig; my %nkjv_content; sub extract_content { my ( ...



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