Tag Info

Hot answers tagged

20

"Everything is a file" is a bit glib. "Everything appears somewhere in the filesystem" is closer to the mark, and even then, it's more an ideal than a law of system design. For example, Unix domain sockets are not files, but they do appear in the filesystem. You can ls -l a domain socket to display its attributes, cat data to/from one, modify its access ...


13

sed creates a temporary file, writes the output into that file, and then renames the temporary file over the top of the original. You can watch what happens using strace: $ strace -e trace=file sed -i -e '' a execve("/usr/bin/sed", ["sed", "-i", "-e", "", "a"], [/* 34 vars */]) = 0 <...trimmed...> open("a", O_RDONLY) = 3 ...


9

mimeopen -a 'picture.jpg' This is what you need It will give you output like this Please choose an application 1) Shotwell Viewer (shotwell-viewer) 2) Firefox Web Browser (firefox) 3) Image Viewer (eog)


8

There are a number of problems with trying to enforce this "after the fact" using a cron job or similar: Race condition. Regardless of which method you use, if you have some program or some code that will be looking through the directory and may pick up and use files you don't want it to interact with, the only way to actually prevent it from doing that is ...


8

When you delete a file you really remove a link to the file (to the inode). If someone already has that file open, they get to keep the file descriptor they have. The file remains on disk, taking up space, and can be written to and read from if you have access to it. The unlink function is defined with this behaviour by POSIX: When the file's link count ...


7

Use recode, e.g.: recode /cr file Note: the fact that you can see the contents in the terminal with cat file is that the Mac end-of-line is CR, which puts the cursor at the beginning of the line without going to the next line, so that everything gets overwritten.


7

From man page of file command, file command actually performs 3 tests on determining the file type. First test The filesystem tests are based on examining the return from a stat(2) system call. Second test The magic number tests are used to check for files with data in particular fixed formats. Third test The language tests ...


7

This output: $ ls -al /usr/lib/*valgrind* drwxr-xr-x 2 root root 4096 Sep 30 00:01 . drwxr-xr-x 24 root root 12288 Sep 30 00:00 .. -rwxr-xr-x 1 root root 1816444 Jun 6 2014 cachegrind-x86-linux indicates that there is a directory named /usr/lib/*valgrind* (most likely just /usr/lib/valgrind) which you're ...


6

I was able reproduce this both on OS X 10.6.8 and OpenBSD 5.5-current. Printing out debug information using file -D tmp, it turns out that your text file fails roughly 2000 tests before file(1) recognizes the Pascal keyword record and decides that it must be a Pascal program text. A minimal working example can be obtained as follows: $ echo record > ...


6

Command Line Tools I use autojump myself and I also depend on many aliases for navigating at the command line, e.g.: alias b='cd -' alias c='cd ~/Dropbox/95_2014/work/code' alias d='~/Dropbox' alias lnk='cd ~/Dropnot/webs/rails_apps/linker' alias n='cd ~/Dropnot' alias play='cd ~/play/' alias q='cd ~/Dropbox/95_2014/work/code/ruby__rails/ruby/ruby_quiz' ...


6

A directory contains a list of filename ⇒ inode mappings. Your directory /home/tim includes an entry with filename tim.pdf, pointing at (say) inode 1234. How do we get at that directory? Well, a directory is really a special kind of file that contains those entries. We can find it the same way we find other files, by looking in its parent: /home will have ...


6

One way to delete files/direcories like this is by their inode-reference. To find the inodes for elements in current dir: ls -i 14813568 mikeaâcnt To delete this: find . -inum 14813568 -delete


5

-t lists the file's modification time, which is the last time the file's content was modified (unless the modification time was explicitly set afterwards). -c lists the file's inode change time, which is the last time the file's metadata was changed (ownership, permissions, etc.) or the file was moved. Most unix systems do not track the creation date of a ...


5

He's saying it's bound by a 64-bit type, which has a maximum value of (2 ^ 64) - 1 unsigned, or (2 ^ 63) - 1 signed (1 bit holds the sign, +/-). The type is not FILE; it's what the implementation uses to track the offset into the file, namely off_t, which is a typedef for a signed 64-bit type.1 (2 ^ 63) - 1 = 9223372036854775807. If a terabyte is 1000 ^ ...


5

ssh host "cd path/to/directory && cp image1.png image2.png" The && is safer than ; in case the cd fails, e.g. because of a typo: in such a case, the cp won't be executed instead of possibly copying a wrong file.


5

Personally, I have never understood the use of fully-fledged file managers. I deeply prefer to use coreutils for file management. As a result, my solution for this would be to suggest a directory management utility. There are a myriad of these, and I have never personally found a use for them so I can make no personal recommendation. But, below are a few ...


5

You should not use non-ASCII characters in the command line since as you could see, for some reason, they won't necessarily correspond to the filename (Unicode has various ways for expressing accented letters). Something like: rm -rf mike* should work since the filename is directly generated by the shell. But make sure there's only one match (do an echo ...


5

Something like this should work: find . \( -iname "*.mp3" -o -iname "*.jpg" \) -printf '%TY%Tm%Td %TT %p\n' | sort -r This should find the files that (case-insensitively) find files ending with mp3 or jpg, print out the modification time, then sort it in reverse order. It seems to show both file-types when you run it effectively as two commands: ( find ...


4

Maybe you can use the --keep-going (-k) option of file. It writes out more matching formats. Related man page description of this option: Don't stop at the first match, keep going. Subsequent matches will be have the string ‘\012- ’ prepended. (If you want a newline, see the -r option.) The magic pattern with the highest strength ...


4

Try: #!/bin/bash id touch script-run-user.file sudo -u appuser 'ksh' <<EOF # add list of cmds to execute id touch appuser.file EOF Edit: Just as an update, check out Here Documents. EOF = "End Of File", the name is arbitrary.


4

I'd suggest a different approach, avoiding the possible word-splitting issues of ls #!/bin/bash shopt -s nullglob for ext in jpg png gif; do files=( *."$ext" ) printf 'number of %s files: %d\n' "$ext" "${#files[@]}" # now we can loop over all the files having the current extension for f in "${files[@]}"; do # anything else you like with ...


4

You can add the file you want to /etc/skel directory. $ sudo touch /etc/skel/test.txt $ sudo useradd -m test $ ls /home/test test.txt From man useradd: -k, --skel SKEL_DIR The skeleton directory, which contains files and directories to be copied in the user's home directory, when the home directory is created by useradd. ...


4

Exactly. Files are tri-partite. The content, that is, a flat array of bytes, written somewhere on a disk or generated on-the-fly. The index node, or inode for short, which is a data structure populated and used by the kernel. It contains all the metadata (size, permission, etc.) about the file, and also pointers to the location of the content of the file. ...


4

Advisory locking is for processes that cooperate "peacefully". The kernel keeps track of the locks but doesn't enforce them - it's up to the applications to obey them. This way the kernel doesn't need to deal with situations like dead-locks. Mandatory locking was introduced in System V Unix, but it turns out that the design was not the brightest thing. ...


4

With zsh: setopt extendedglob zmodload zsh/stat zstat -F %F +mtime -- **/(#i)*.(mp3|jpg)(Om[1]) Note that it's based on last modification time, the creation time (whatever that means) is generally not readily available on Linux. It doesn't consider hidden files. I you want them, add the D globbing qualifier above.


3

You have to quote or escape the filename. In Bash (the default shell in most distros), you can either use quote marks to enclose the entire name, or a backslash to escape the one space. rm "my file" rm my\ file


3

Yes, close can block: If O_NONBLOCK is not set and there have been no signals posted for the STREAM, and if there is data on the module's write queue, close() shall wait for an unspecified time (for each module and driver) for any output to drain before dismantling the STREAM. And: If fildes refers to a socket, close() shall cause the socket to be ...


3

Without the ability to use sudo your options become limited to essentially 2. Method #1 You can either put the users into the same Unix group (/etc/group) so that they're able to access the same files & directories. Example $ more /etc/group somegroup:x:1001:adminuser,nobody You then need to set the parent directory that contains this file like ...


3

Use: mimeopen -a 0001.jpg -a will first Ask you to choose, not run it. Please choose an application 1) Wine Internet Explorer (wine-extension-jfif) 2) Wine Internet Explorer (wine-extension-jpe) 3) Firefox Web Browser (firefox) 4) Luminance HDR (luminance-hdr) 5) ImageMagick (display) (display.im6) 6) Image Viewer (eog) 7) Shutter (shutter) 8) ...


3

There's no foolproof way to tell. However, for log files, the change time (as opposed to the modification time) which you see in the output of stat may be the time at which the compressed file was created, because the filesystem attributes of these compressed files are rarely modified after their creation. For .gz files which were not created by compressing ...



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